mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-22 07:34:16 +00:00
feature(util) add getType
This commit is contained in:
parent
70e96d0ab5
commit
b23f04be7c
1 changed files with 25 additions and 6 deletions
31
lib/util.js
31
lib/util.js
|
|
@ -339,12 +339,12 @@
|
|||
|
||||
this.isContainStr = function(str1, str2) {
|
||||
var i, n, str, is, index,
|
||||
isStr1 = Util.isString(str1),
|
||||
isStr2 = Util.isString(str2),
|
||||
isArray = Util.isArray(str2);
|
||||
isStr = Util.isString(str1),
|
||||
type = Util.getType(str2);
|
||||
|
||||
if (isStr1)
|
||||
if (isArray) {
|
||||
if (isStr)
|
||||
switch (type) {
|
||||
case 'array':
|
||||
n = str2.length;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
|
|
@ -354,9 +354,12 @@
|
|||
if (is)
|
||||
break;
|
||||
}
|
||||
} else if (isStr2) {
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
index = str1.indexOf(str2);
|
||||
is = index >= 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return is;
|
||||
|
|
@ -686,6 +689,22 @@
|
|||
return typeof variable === pType;
|
||||
};
|
||||
|
||||
/**
|
||||
* get type of variable
|
||||
*
|
||||
* @param variable
|
||||
*/
|
||||
this.getType = function(variable) {
|
||||
var regExp = new RegExp('\\s([a-zA-Z]+)'),
|
||||
obj = {},
|
||||
toStr = obj.toString,
|
||||
str = toStr.call(variable),
|
||||
typeBig = str.match(regExp)[1],
|
||||
type = typeBig.toLowerCase();
|
||||
|
||||
return type;
|
||||
};
|
||||
|
||||
/**
|
||||
* return save exec function
|
||||
* @param callback
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue