feature(util) add getType

This commit is contained in:
coderaiser 2014-05-10 04:42:17 -04:00
parent 70e96d0ab5
commit b23f04be7c

View file

@ -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