underarm
Version:
Transducers for JavaScript with Underscore API and Async extensions
60 lines (51 loc) • 1.18 kB
JavaScript
var toString = Object.prototype.toString,
isArray = (Array.isArray || predicateToString('Array')),
has = {}.hasOwnProperty
module.exports = {
isArray: isArray,
isFunction: isFunction,
isNumber: predicateToString('Number'),
isRegExp: predicateToString('RegExp'),
isString: predicateToString('String'),
isUndefined: isUndefined,
identity: identity,
arrayPush: arrayPush,
stringAppend: stringAppend,
objectMerge: objectMerge
}
function isFunction(value){
return typeof value === 'function'
}
function isUndefined(value){
return value === void 0
}
function predicateToString(type){
var str = '[object '+type+']'
return function(value){
return toString.call(value) === str
}
}
function identity(result){
return result
}
function arrayPush(result, input){
result.push(input)
return result
}
function stringAppend(result, input){
return result + input
}
function objectMerge(result, input){
if(isArray(input) && input.length === 2){
result[input[0]] = input[1]
} else {
var prop
for(prop in input){
if(has.call(input, prop)){
result[prop] = input[prop]
}
}
}
return result
}