6.0.0 • Published 9 years ago

obus v6.0.0

Weekly downloads
76
License
MIT
Repository
github
Last release
9 years ago

obus Build Status

obus is deep object accessor

Usage

var Obus = require('obus');
var obus = new Obus();
obus.set('a.b.c', 42);

API

Obus new Obus()

Creates new Obus object

var obus = new Obus();

* obus.set(String path, * data)

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}}}

* obus.get(String path[, * defaultValue])

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

Boolean obus.del(String path)

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

Boolean obus.has(String path)

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

* obus.add(String path, * data)

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}}

Also

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

6.0.0

9 years ago

5.0.1

10 years ago

5.0.0

10 years ago

4.0.0

10 years ago

3.0.0

10 years ago

2.1.4

10 years ago

2.1.3

10 years ago

2.1.2

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

11 years ago

1.0.0-1

11 years ago

1.0.0-0

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago