xtnd
Extra methods for underscore and lodash
Installation
npm install xtnd
bower install xtnd
Usage
var xtnd = ;
Api
- xtnd
- xtnd.keys
- xtnd.values
- xtnd.array
- xtnd.hash
- xtnd.each
- xtnd.map
- xtnd.filter
- xtnd.clone
- xtnd.find
- xtnd.param
- xtnd.is<Type>
xtnd(dest, src, ...)
Extends any object with src
var a = ; // {a: 1}
xtnd.keys(any)
Returns all object's keys
{}fa = 1; fb = 2;xtnd; // ['a', 'b']xtnd; // ['a', 'b']xtnd; // []
xtnd.values(any)
Returns all object's values
xtnd; // [1, 2]xtnd; // [1, 2]
xtnd.array(any)
Makes array from any
value.
xtnd; // [1]xtnd; // [{a: 1}]xtnd; // converts to arrayxtnd; // []xtnd; // [null]xtnd; // [123]xtnd; // ['a']
xtnd.hash(array, key)
Creates object from array
of objects. Skips objects withou key
.
xtndhasha: 1 b: 2 a: 3 b: 4 'a'; // {1: {a: 1, b: 2}, 3: {a: 3, b: 4}}
xtnd.each(list, function(val, i, orig) {})
Like any other each
can iterate through arrays and objects. You can return false
from callback and it will stop iteration.
xtnd;
xtnd.map(list, function(val, i, orig) {})
Can map not only arrays but also objects. You can return undefined
from callback to skip val
.
var src = a: 1 b: 2 c: 3;var res = xtnd;// res === {a: 5, c: 7}
xtnd.filter(list, function(val, i, orig) {})
Like a map, looks through each value in the list, returning a list of all the values that pass a callback truth test.
xtnd.clone(src)
Creates a deep copy of the src
.
xtnd.find(list, function(val, i, orig) {})
For array or object returns first matched (truthy-value returned) by callback val
or undefined
. It stops iterating after val
returned.
var res = xtnd;// res === 3
xtnd.param(str, eq, sp)
Converts URL params into object
xtnd // {a: '1', b: '1'}xtnd // {a: '1', b: '2'}
xtnd.is<Type>
Strong type checkers.
xtnd; // truextnd; // false xtnd; // truextnd; // false xtnd; // truextnd; // truextnd; // true