npm.io
1.0.0-rc.2 • Published 2 years ago

inidot

Licence
MIT
Version
1.0.0-rc.2
Deps
0
Size
11 kB
Vulns
0
Weekly
0

Inidot banner

Inidot

npmjs License Activity GitHub stars

Get, set, or delete a property from a nested object using a dot path

Features

  • Lightweight
  • Minimalist (but powerful)
  • TypeScript
  • Super-Fast
  • Suitable for large data
  • Safe
  • Easy to use
  • ... and much more

Usage

import Inidot from "inidot";
// or
import {
  toDotNotation,
  getProperty,
  setProperty,
  deleteProperty,
  hasProperty
} from "inidot";

const myObj = {
  name: "Jo,hn",
  age: 21,
  address: {
    city: "New York",
    zip: 65221,
  },
  hobbies: ["Reading", "Tra[veling", ["test", "test2", { test: true }]],
};

// Get Property by path
Inidot.getProperty(myObj, "address.city");
// New York

// Get Unexisted Property by path
Inidot.getProperty(myObj, "address.country");
// undefined

// Define a default value
Inidot.getProperty(myObj, "address.city", "Morocco");
// Morocco
Selector Examples
- `obj.value` => `['obj', 'value']`
- `obj.ary.0.value` => `['obj', 'ary', '0', 'value']`
- `obj.ary.0.va\\.lue` => `['obj', 'ary', '0', 'va.lue']`
- `obj.ary.*.value` => `['obj', 'ary', '*', 'value']`

If you like Inidot, please sponsor: GitHub Sponsors || Paypal.

Install

<npm|pnpm|yarn> install inidot

License

MIT

Keywords