objectio
v0.2.0
Published
A JavaScript object getter and setter with string literals ⚡
Downloads
3
Maintainers
Readme
objectio (object + io)
A JavaScript object getter and setter with string literals ⚡
Usage
import { get, set } from 'objectio';
const obj = {
a: 1,
b: {
c: [
'd',
{
e: 'e',
},
],
},
};
// getter examples
console.log(get(obj, 'a')); // 1
console.log(get(obj, 'b.c[0]')); // 'd'
console.log(get(obj, 'b.c[1].e')); // 'e'
// setter examples
set(obj, 'a', 100);
console.log(get(obj, 'a')); // 100
set(obj, 'b.c[1]', 'E')
console.log(get(obj, 'b.c[1]')); // 'E'
console.log(obj);
// {
// "a": 100,
// "b": {
// "c": [
// "d",
// "E"
// ]
// }
// }