mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
refactor(util) strCmp
This commit is contained in:
parent
59f7ef4c7d
commit
4a2cec4625
1 changed files with 20 additions and 16 deletions
36
lib/util.js
36
lib/util.js
|
|
@ -266,25 +266,29 @@
|
|||
|
||||
/**
|
||||
* function check is strings are equal
|
||||
* @param pStr1
|
||||
* @param pStr2
|
||||
* @param {String} str1
|
||||
* @param {String, Array} str2
|
||||
*/
|
||||
this.strCmp = function(pStr1, pStr2) {
|
||||
var i, n,
|
||||
ret = Util.isString(pStr1);
|
||||
this.strCmp = function(str1, str2) {
|
||||
var ret,
|
||||
isStr = Util.isString(str1),
|
||||
type = Util.getType(str2);
|
||||
|
||||
if (ret)
|
||||
if (Util.isArray(pStr2))
|
||||
for (i = 0, n = pStr2.length; i < n; i++) {
|
||||
ret = Util.strCmp(pStr1, pStr2[i]);
|
||||
if (isStr)
|
||||
switch(type) {
|
||||
case 'array':
|
||||
str2.some(function(str) {
|
||||
ret = Util.strCmp(str1, str);
|
||||
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
else if (Util.isString(pStr2))
|
||||
ret = Util.isContainStr(pStr1, pStr2) &&
|
||||
pStr1.length === pStr2.length;
|
||||
|
||||
return ret;
|
||||
});
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
ret = !str1.indexOf(str2);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue