dot-prop nested property paths: working versions (tested 2026-10-16)
Read, write, check and delete nested object properties with dot-prop using dotted paths, escaped dots and defaults, fully offline.
passed8 passed · 0 failed2026-10-16 19:54 UTC- Status
- passed
- Last passed
- 2026-10-16 19:54 UTC
- Tests
- 8 / 8
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
dot-prop@10.2.0@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38958328921
The code
Exactly the files that passed. Your agent can pull them with get_recipe("dot-prop-nested-paths") (install), or see them on GitHub.
package.json
{
"name": "dot-prop-nested-paths",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"dot-prop": "10.2.0"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/paths.ts
import {
getProperty,
setProperty,
hasProperty,
deleteProperty,
} from "dot-prop";
export function readPath<T = unknown>(object: unknown, path: string, fallback: T): T {
const value = getProperty(object, path);
return value === undefined ? fallback : (value as T);
}
export { getProperty, setProperty, hasProperty, deleteProperty };
test/paths.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import {
getProperty,
setProperty,
hasProperty,
deleteProperty,
readPath,
} from "../src/paths.ts";
test("getProperty reads nested values", () => {
const config = { a: { b: { c: 42 } } };
assert.equal(getProperty(config, "a.b.c"), 42);
assert.equal(getProperty(config, "a.b.missing"), undefined);
});
test("getProperty reads array index paths", () => {
const data = { users: [{ name: "ada" }, { name: "grace" }] };
assert.equal(getProperty(data, "users.1.name"), "grace");
});
test("getProperty reads keys with escaped dots", () => {
const flat = { "a.b": { c: 7 } };
assert.equal(getProperty(flat, "a\\.b.c"), 7);
assert.equal(getProperty(flat, "a.b.c"), undefined);
});
test("setProperty creates nested objects", () => {
const target: Record<string, unknown> = {};
setProperty(target, "a.b.c", 1);
assert.deepEqual(target, { a: { b: { c: 1 } } });
});
test("setProperty honours escaped dots", () => {
const target: Record<string, unknown> = {};
setProperty(target, "a\\.b.c", 2);
assert.deepEqual(target, { "a.b": { c: 2 } });
});
test("hasProperty detects nested and escaped paths", () => {
const obj = { a: { b: 1 }, "a.b": 2 };
assert.equal(hasProperty(obj, "a.b"), true);
assert.equal(hasProperty(obj, "a\\.b"), true);
assert.equal(hasProperty(obj, "a.c"), false);
});
test("deleteProperty removes nested and escaped keys", () => {
const obj: Record<string, unknown> = { a: { b: 1, c: 2 }, "a.b": 3 };
assert.equal(deleteProperty(obj, "a.b"), true);
assert.deepEqual(obj, { a: { c: 2 }, "a.b": 3 });
assert.equal(deleteProperty(obj, "a\\.b"), true);
assert.deepEqual(obj, { a: { c: 2 } });
});
test("readPath returns a fallback for missing paths", () => {
const obj = { a: { b: 5 } };
assert.equal(readPath(obj, "a.b", 0), 5);
assert.equal(readPath(obj, "a.z", 99), 99);
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.