Get, set, or delete a property from a nested object using a dot path 🔥
- Lightweight 🪶
- Minimalist ⚪ (but powerful)
- TypeScript 🔷
- Super-Fast ⚡
- Suitable for large data 📃
- Safe 🔒
- Easy to use 🍞
- ... and much more 🚀
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
- `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.
<npm|pnpm|yarn> install inidot