notate
v2.1.1
Published
Resolve dot notation strings
Downloads
12,807
Maintainers
Readme
notate
Resolve dot notation strings
import { notate } from "notate";
const obj = {
top_level: {
nested: {
value: "My Value",
},
},
};
notate(obj, "top_level.nested.value"); // 'My Value'
notate(obj, "top_level.missing.value"); // undefined
Resolve list notation as well
const obj = {
list: [{ name: "Alice" }, { name: "Bob" }],
};
notate(obj, "list[1].name"); // 'Bob'
Supports Map and Set
const map = new Map([["key", { chain: "value" }]]);
notate(map, "key.chain"); // 'value'
const set = new Set([{ chain: "value" }]);
notate(set, "[0].chain"); // 'value'