obus
is deep object accessor
var Obus = require('obus');
var obus = new Obus();
obus.set('a.b.c', 42);
Creates new Obus
object
var obus = new Obus();
Puts the given object deep into object according to given path
var obus = new Obus();
obus.set('a.b.c', 42);
obus.valueOf(); // -> {a: {b: {c: 42}}}
Returns the value placed deep in object according to given path. Returns the second argument if returning value is undefined
var obus = new Obus();
obus.set('a.b.c', 42);
obus.get('a.b'); // -> {c: 42}
obus.get('a.b.c'); // -> 42
obus.get('a.b.c.d'); // -> undefined
obus.get('a.b.c.d', 146); // -> 146
Deletes data from given path. Returns true if the data was deleted else false
var obus = new Obus();
obus.set('a', 42);
obus.del('a'); // -> true
obus.del('a'); // -> false
Checks if any truey (not undefined
) data placed by the given path
var obus = new Obus();
obus.set('a.b', 42);
obus.has('a.b'); // -> true
obus.has('a'); // -> true
obus.has('a.b.c'); // -> false
Extends existing data with the given value
var obus = new Obus();
obus.set('a.b', 42);
obus.add('a', {c: 42});
obus.valueOf(); // -> {a: {b: 42, c: 42}}
You can use brace accessors if the properties you want is not identifiers.
var obus = new Obus();
obus.set('foo.bar-baz', 42); // error
// Obus supports string literals
obus.set('foo["bar-baz"]', 42); // done
obus.set("foo['bar-baz']", 42); // done
LICENSE MIT