Skip to content

KazariEX/propathy

Repository files navigation

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

About

Operate objects via dot path.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published