ettr
v1.0.2
Published
a lib that use string to access attribute
Downloads
5
Readme
install
npm install ettr
usage
Assume obj
is
{
a: {
b: {
c: 1,
d: 2,
}
}
}
.get(obj, attr)
ettr.get(obj, 'a.b.c')
.should.equal(1);
ettr.get(obj, 'a[b]["c"]')
.should.equal(1);
.set(obj, attr, value)
ettr.set(obj, 'a.b.c', 5);
obj.a.b.c.should.equal(5);
.incr(obj, attr, value, defaultValue)
ettr.incr(obj, 'a.b.z', 1, 100);
ettr.incr(obj, 'a.b.z', 1, 100);
obj.a.b.z.should.equal(102);
license
MIT