mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
refactor(util) type
This commit is contained in:
parent
77d9330151
commit
61e213ec22
1 changed files with 16 additions and 83 deletions
99
lib/util.js
99
lib/util.js
|
|
@ -526,97 +526,30 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* functions check is variable is array
|
||||
* functions check is variable is type of name
|
||||
*
|
||||
* @param variable
|
||||
*/
|
||||
type.array = function(variable) {
|
||||
var result;
|
||||
|
||||
if (Array.isArray)
|
||||
result = Array.isArray(variable) ;
|
||||
else
|
||||
result = type(variable) === 'array';
|
||||
|
||||
return result;
|
||||
};
|
||||
function typeOf(name, variable) {
|
||||
return type(variable) === name;
|
||||
}
|
||||
|
||||
/**
|
||||
* functions check is variable is arrayBuffer
|
||||
* @param variable
|
||||
*/
|
||||
type.arrayBuffer = function(variable) {
|
||||
return type(variable) === 'arraybuffer';
|
||||
};
|
||||
function typeOfSimple(name, variable) {
|
||||
return typeof variable === name;
|
||||
}
|
||||
|
||||
/**
|
||||
* functions check is variable is boolean
|
||||
* @param variable
|
||||
*/
|
||||
type.boolean = function(variable) {
|
||||
return typeof variable === 'boolean';
|
||||
};
|
||||
['arrayBuffer', 'object', 'file', 'array']
|
||||
.forEach(function(name) {
|
||||
type[name] = typeOf.bind(null, name);
|
||||
});
|
||||
|
||||
/**
|
||||
* functions check is variable is function
|
||||
* @param variable
|
||||
*/
|
||||
type.function = function(variable) {
|
||||
return typeof variable === 'function';
|
||||
};
|
||||
|
||||
/**
|
||||
* functions check is variable is number
|
||||
* @param variable
|
||||
*/
|
||||
type.number = function(variable) {
|
||||
return typeof variable === 'number';
|
||||
};
|
||||
|
||||
/**
|
||||
* functions check is variable is object
|
||||
* @param variable
|
||||
*/
|
||||
type.object = function(variable) {
|
||||
var type = Util.type(variable),
|
||||
is = type === 'object';
|
||||
|
||||
return is;
|
||||
};
|
||||
|
||||
/**
|
||||
* functions check is variable is string
|
||||
* @param variable
|
||||
*/
|
||||
type.string = function(variable) {
|
||||
return typeof variable === 'string';
|
||||
};
|
||||
|
||||
/**
|
||||
* functions check is variable is string
|
||||
* @param variable
|
||||
*/
|
||||
type.undefined = function(variable) {
|
||||
return typeof variable === 'undefined';
|
||||
};
|
||||
|
||||
/**
|
||||
* functions check is variable is File
|
||||
* @param variable
|
||||
*/
|
||||
type.file = function(variable) {
|
||||
var FILE = '[object File]',
|
||||
name, is;
|
||||
|
||||
name = Util.exec.ifExist(variable, 'toString');
|
||||
|
||||
is = name === FILE;
|
||||
|
||||
return is;
|
||||
};
|
||||
['string', 'undefined', 'boolean', 'number', 'function']
|
||||
.forEach(function(name) {
|
||||
type[name] = typeOfSimple.bind(null, name);
|
||||
});
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* function return false
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue