Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@luxiaojian
Created April 12, 2016 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luxiaojian/45934fd5d4339b87d3b32331199f68c3 to your computer and use it in GitHub Desktop.
Save luxiaojian/45934fd5d4339b87d3b32331199f68c3 to your computer and use it in GitHub Desktop.
/**
* 判断类型
* @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