mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 01:17:18 +00:00
refactor(util) rmStr, rmStrOnce
This commit is contained in:
parent
4d2ed0542f
commit
85eb6a8027
1 changed files with 11 additions and 16 deletions
27
lib/util.js
27
lib/util.js
|
|
@ -473,8 +473,9 @@
|
|||
* @param str
|
||||
* @param substr
|
||||
*/
|
||||
this.rmStr = function(str, substr) {
|
||||
var strArray = [],
|
||||
this.rmStr = function(str, substr, isOnce) {
|
||||
var replace,
|
||||
strArray = [],
|
||||
isString = Util.isString(str),
|
||||
isArray = Util.isArray(substr);
|
||||
|
||||
|
|
@ -484,8 +485,13 @@
|
|||
else
|
||||
strArray.push(substr);
|
||||
|
||||
if (isOnce)
|
||||
replace = str.replace.bind(str);
|
||||
else
|
||||
replace = Util.replaceStr.bind(null, str);
|
||||
|
||||
strArray.forEach(function(strItem) {
|
||||
str = Util.replace(str, strItem, '');
|
||||
str = replace(strItem, '');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -498,20 +504,9 @@
|
|||
* @param substr
|
||||
*/
|
||||
this.rmStrOnce = function(str, substr) {
|
||||
var n, isArray,
|
||||
isString = Util.isString(str);
|
||||
var ONCE = true;
|
||||
|
||||
if (isString && substr) {
|
||||
n = substr.length;
|
||||
isArray = Util.isArray(substr);
|
||||
|
||||
if (!isArray)
|
||||
str = str.replace(substr, '');
|
||||
else
|
||||
Util.fori(n, function(i) {
|
||||
str = str.replace(substr[i], '');
|
||||
});
|
||||
}
|
||||
str = Util.rmStr(str, substr, ONCE);
|
||||
|
||||
return str;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue