You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
782 B
JavaScript
40 lines
782 B
JavaScript
'use strict'
|
|
|
|
var toString = ({}).toString
|
|
var hasOwnProp = ({}).hasOwnProperty
|
|
|
|
var utils = {
|
|
noop: function noop() {},
|
|
|
|
isString: function isString(str) {
|
|
return typeof str === 'string'
|
|
},
|
|
|
|
forEach: function forEach(obj, fn) {
|
|
for (var key in obj) {
|
|
if (hasOwnProp.call(obj, key)) {
|
|
fn(key, obj[key])
|
|
}
|
|
}
|
|
},
|
|
|
|
assign: function assign (dest, methods) {
|
|
utils.forEach(methods, function (key, val) {
|
|
dest[key] = val
|
|
})
|
|
}
|
|
}
|
|
|
|
function checkType(type) {
|
|
return function _checkType(val) {
|
|
return toString.call(val) === '[object ' + type + ']'
|
|
}
|
|
}
|
|
|
|
// add isRegExp, isArray, isFunction
|
|
['RegExp', 'Array', 'Function'].forEach(function addIsChecks(type) {
|
|
utils['is' + type] = checkType(type)
|
|
})
|
|
|
|
module.exports = utils
|