Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

dottpath

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dottpath

Use dot path notation to find diffs, map paths, and set or extract values in JSON-serializable inputs.

latest
Source
npmnpm
Version
0.2.3
Version published
Weekly downloads
94
840%
Maintainers
1
Weekly downloads
 
Created
Source

dottpath

Use dot path notation to find diffs, map paths, and set or extract values in JSON-serializable inputs.

Installation

npm install dottpath
# or
yarn add dottpath

Usage

const dottpath = require("dottpath"); // commonjs
// or
import dottpath from "dottpath"; // esm

Map

Generate a flat array of all dot paths in an input.

dottpath.map({ a: 1, b: { c: 2 } }); // ["a", "b.c"]
dottpath.map({ a: [1, 2] }); // ["a.0", "a.1"]
dottpath.map([1, [2, 3]]); // ["0", "1.0", "1.1"]
dottpath.map({}); // []

Extract

Extract values from an input using dot path notation.

dottpath.extract({ a: { b: 1 } }, "a.b"); // 1
dottpath.extract({ a: 1, b: 2 }, ["a", "b"]); // [1, 2]
dottpath.extract({ a: 1, b: 2 }, { x: "a", y: "b" }); // { x: 1, y: 2 }
dottpath.extract({ a: { b: 1 } }, "a.c"); // undefined

Set

Set values at specified dot paths in an input.

dottpath.set({ a: 1, b: { c: 2 } }, { "b.c": 99 }); // { a: 1, b: { c: 99 } }
dottpath.set({ a: 1, b: { c: 2 } }, { a: 0 }); // { a: 0, b: { c: 2 } }
dottpath.set([1, [2, 3]], { "1.0": 99 }); // [1, [99, 3]]
dottpath.set({ a: 1 }, {}); // { a: 1 }

Diffs

Find differences between two JSON-serializable inputs.

dottpath.diffs({ a: 1 }, { a: 2 });
// [{ path: "a", valueA: 1, valueB: 2, state: "value changed", change: 1, timestamp: ... }]

dottpath.diffs({ a: 1, b: 2 }, { a: 1 });
// [{ path: "b", valueA: 2, valueB: undefined, state: "property removed", timestamp: ... }]

dottpath.diffs({ a: 1 }, { a: 1, b: 2 });
// [{ path: "b", valueA: undefined, valueB: 2, state: "property added", timestamp: ... }]

dottpath.diffs({ a: 1 }, { a: 2 }, ["a"]); // excludes path "a"
// []

Diff object

PropertyTypeDescription
pathstringDot path of the changed value
valueAunknownValue from the first input
valueBunknownValue from the second input
state"value changed" | "property added" | "property removed"Type of change
changenumberNumeric or timestamp delta (only for numeric or date values)
timestampnumberUnix timestamp of when the diff was computed

License

MIT

Keywords

typescript

FAQs

Package last updated on 20 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts