baiji-meld
v1.0.2
Published
Baiji meld(Utils tools)
Downloads
1
Readme
Meld
Lead Maintainer: Oliver Wang
Node utilities shared amongst the extended baiji universe
Usage
Installation
npm install baiji-meld
Usage
var meld = require('baiji-meld');
meld.isArray([1,2,3]);
// => true
Method
All the functions used in Meld is based on lodash(v4.0.0-pre), some of them have been customized(italic) in the following list.
Language Functions
- clone
Creates a shallow clone structured clone algorithm ofvalue
.meld.clone(value)
- isArray
Checks ifvalue
is classified as anArray
object.meld.isArrayLike(value)
- isBoolean
Checks ifvalue
is classified as a boolean primitive or object.meld.isBoolean(value)
- isDate
Checks ifvalue
is classified as aDate
object.meld.isDate(value)
- isEmpty
Checks ifvalue
is empty. A value is considered empty unless it's anarguments
object, array, string, or jQuery-like collection with a length greater than0
, an object with own enumerable properties or a number.meld.isEmpty(value)
- isFunction
Checks ifvalue
is classified as aFunction
object.meld.isFunction(value)
- isLength
Checks ifvalue
is a valid array-like length.meld.isLength(value)
- isNil
Checks ifvalue
isnull
orundefined
.meld.isNil(value)
- isNull
Checks ifvalue
isnull
.meld.isNull(value)
- isNumber
Checks ifvalue
is classified as aNumber
primitive or object.meld.isNumber(value)
- isObject
Checks ifvalue
is the language type ofObject
.meld.isObject(value)
- isPlainObject
Checks ifvalue
is a plain object, that is, an object created by theObject
constructor or one with a[[Prototype]]
ofnull
.meld.isPlainObject(value)
- isPresent
Check ifvalue
is notEmpty
meld.isPresent(value)
- isRegExp
Checks ifvalue
is classified as aRegExp
object.meld.isRegExp(value)
- isString
Checks ifvalue
is classified as aString
primitive or object.meld.isString(value)
- isUndefined
Checks ifvalue
isundefined
.meld.isUndefined(value)
Array Functions
- compact
Creates an array with all falsey values removed. The valuesfalse
,null
,0
,""
,undefined
, andNaN
are falsey.meld.compact(array)
- flatten
Flattensarray
a single level.meld.flatten(array)
- first
Gets the first element ofarray
.meld.first(array)
- last
Gets the last element ofarray
.meld.last(array)
Object Functions
- extend
Assigns own enumerable properties of source objects to the destination object. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources but it iterates over own and inherited source properties.meld.entend(object, [sources])
- get
Gets the value atpath
ofobject
. If the resolved value isundefined
thedefaultValue
is used in its place.meld.get(object, path, [defaultValue])
- hasIn
Checks ifpath
is a direct or inherited property ofobject
.meld.hasIn(object, path)
- keys
Creates an array of the own enumerable property names ofobject
.meld.keys(object)
- keysIn
Creates an array of the own and inherited enumerable property names ofobject
.meld.keysIn(object)
- values
Creates an array of the own enumerable property values ofobject
.meld.values(object)
String Functions
- pad
Padsstring
on the left and right sides if it's shorter thanlength
. Padding characters are truncated if they can't be evenly divided bylength
.meld.pad([string=''], [length=0], [chars=' '])
- padLeft
Padsstring
on the left side if it's shorter thanlength
. Padding characters are truncated if they exceedlength
.meld.padLeft([string=''], [length=0], [chars=' '])
- padRight
Padsstring
on the right side if it's shorter thanlength
. Padding characters are truncated if they exceedlength
.meld.padRight([string=''], [length=0], [chars=' '])
- escapeRegExp
Escape RegExp special characters.
meld.escapeRegExp([string=''])
Collection Functions
meld.iteratee
: a function that a invokesfunc
with the arguments of the created function.
- each
Iterates over elements ofcollection
invokingiteratee
for each element. The iteratee is invoked with three arguments: (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returningfalse
.meld.each(collection, [iteratee = meld.identity])
- eachRight
This method is likemeld.each
except that it iterates over elements ofcollection
from right to left.meld.eachRight(collection, [iteratee = meld.identity])
- map
Creates an array of values by running each element incollection
throughiteratee
. The iteratee is invoked with three arguments: (value, index|key, collection).meld.map(collection, [iteratee = meld.identity])
Math Functions
- max
Computes the maximum value ofarray
. Ifarray
is empty or falseyundefined
is returned.meld.max(array)
- min
Computes the minimum value ofarray
. Ifarray
is empty or falseyundefined
is returned.meld.min(array)
License
MIT