object-tools
Useful functions for working with objects
Example
var o =
- object-tools
- .extend(...object) ⇒
object
- .clone(input) ⇒
object
|array
- .every(object, iterator) ⇒
boolean
- .each(object, callback)
- .exists(object, query) ⇒
boolean
- .without(object, toRemove) ⇒
object
- .where(object, query) ⇒
object
- .extract(object, query) ⇒
object
- .select(object, fields) ⇒
object
- .get(object, expression) ⇒
*
- .extend(...object) ⇒
object
o.extend(...object) ⇒ Merge a list of objects, left to right, into one - to a maximum depth of 10.
Kind: static method of object-tools
Param | Type | Description |
---|---|---|
...object | object |
a sequence of object instances to be extended |
Example
> o one: 'one' three: 3 two: 2 four: 4
object
| array
o.clone(input) ⇒ Clones an object or array
Kind: static method of object-tools
Param | Type | Description |
---|---|---|
input | object | array |
the input to clone |
Example
> date = Fri May 09 2014 13:54:34 GMT+> o{} // a Date instance doesn't own any properties> dateclive = 'hater''hater'> o clive: 'hater' > array = 123 1 2 3 > newArray = o 1 2 3 > array === newArrayfalse
boolean
o.every(object, iterator) ⇒ Returns true if the supplied iterator function returns true for every property in the object
Kind: static method of object-tools
Param | Type | Description |
---|---|---|
object | object |
the object to inspect |
iterator | function |
the iterator function to run against each key/value pair, the args are (value, key) . |
Example
> { return input > 10; }> otrue> ofalse
o.each(object, callback)
Runs the iterator function against every key/value pair in the input object
Kind: static method of object-tools
Param | Type | Description |
---|---|---|
object | object |
the object to iterate |
callback | function |
the iterator function to run against each key/value pair, the args are (value, key) . |
Example
> var total = 0> { total += n; }> o> total6
boolean
o.exists(object, query) ⇒ returns true if the key/value pairs in query
also exist identically in object
.
Also supports RegExp values in query
. If the query
property begins with !
then test is negated.
Kind: static method of object-tools
Param | Type | Description |
---|---|---|
object | object |
the object to examine |
query | object |
the key/value pairs to look for |
Example
> ofalse> otrue> ofalse> otrue> otrue> otrue> ofalse
object
o.without(object, toRemove) ⇒ Returns a clone of the object minus the specified properties. See also select.
Kind: static method of object-tools
Param | Type | Description |
---|---|---|
object | object |
the input object |
toRemove | string | Array.<string> |
a single property, or array of properties to omit |
Example
> o a: 1 c: 3 > o c: 3
object
o.where(object, query) ⇒ Returns a new object containing the key/value pairs which satisfy the query
Kind: static method of object-tools
Since: 1.2.0
Param | Type | Description |
---|---|---|
object | object |
The input object |
query | Array.<string> | function |
Either an array of property names, or a function. The function is called with (value, key) and must return true to be included in the output. |
Example
> object = a: 1 b: 0 c: 2 a: 1 b: 0 c: 2 > o a: 1 c: 2 > o b: 0 > object a: 1 b: 0 c: 2
object
o.extract(object, query) ⇒ identical to o.where(object, query)
with one exception - the found properties are removed from the input object
Kind: static method of object-tools
Since: 1.2.0
Param | Type | Description |
---|---|---|
object | object |
The input object |
query | Array.<string> | function |
Either an array of property names, or a function. The function is called with (value, key) and must return true to be included in the output. |
Example
> object = a: 1 b: 0 c: 2 a: 1 b: 0 c: 2 > o a: 1 c: 2 > object b: 0
object
o.select(object, fields) ⇒ Returns a new object containing only the selected fields. See also without.
Kind: static method of object-tools
Param | Type | Description |
---|---|---|
object | object |
the input object |
fields | string | array |
a list of fields to return |
*
o.get(object, expression) ⇒ Returns the value at the given property.
Kind: static method of object-tools
Since: 1.4.0
Param | Type | Description |
---|---|---|
object | object |
the input object |
expression | string |
the property accessor expression |
© 2014-16 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.