Skip to content

Latest commit

 

History

History
43 lines (29 loc) · 924 Bytes

README.md

File metadata and controls

43 lines (29 loc) · 924 Bytes

Propathy

version downloads license

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: [{}] } }