propathy
v0.1.0
Published
Operate objects via dot path
Downloads
169
Readme
Propathy
Operate objects via dot path.
Install
pnpm i propathy
Usage
import { getProperty, setProperty, hasProperty, deleteProperty } from "propathy";
const target = { foo: { bar: [{ baz: "qux" }] } };
getProperty(target, "foo.bar[0].baz");
// "qux"
getProperty(target, "foo.bar[1]");
// undefined
setProperty(target, "foo.bar[0].baz", "kzr");
console.log(target);
// { foo: { bar: [{ baz: "kzr" }] } }
hasProperty(target, "foo.bar[0].baz");
// true
hasProperty(target, "foo.bar[1]");
// false
deleteProperty(target, "foo.bar[0].baz");
// true
console.log(target);
// { foo: { bar: [{}] } }