Created
April 12, 2016 03:27
-
-
Save luxiaojian/45934fd5d4339b87d3b32331199f68c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 判断类型 | |
* @module filters/is | |
* @param {Any} value - 待检测类型的对象 | |
* @param {sting} type - 类型:`array`, `object`, `boolean`, `string`, `number`, `undefined` | |
* 多个用逗号分隔 | |
* @return {Boolean} | |
*/ | |
export function is(value, types) { | |
let correct = false; | |
let methods = { | |
array: _Lang.isArray, | |
object: _Lang.isPlainObject, | |
boolean: _Lang.isBoolean, | |
number: _Lang.isNumber, | |
string: _Lang.isString, | |
undefined: _Lang.isUndefined | |
}; | |
types = types.toLowerCase().split(','); | |
types.forEach(type => { | |
type = type.trim(); | |
if (correct) { | |
return; | |
} | |
correct = methods[type](value); | |
}); | |
return correct; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment