mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 01:17:18 +00:00
refactor(util) replaceStr
This commit is contained in:
parent
f5174234f4
commit
0c84ddc50c
1 changed files with 12 additions and 11 deletions
23
lib/util.js
23
lib/util.js
|
|
@ -488,22 +488,23 @@
|
|||
|
||||
/**
|
||||
* function replase pFrom to pTo in pStr
|
||||
* @pStr
|
||||
* @pFrom
|
||||
* @pTo
|
||||
* @pNotEscape
|
||||
* @param str
|
||||
* @param from
|
||||
* @param to
|
||||
* @param notEscape
|
||||
*/
|
||||
this.replaceStr = function(pStr, pFrom, pTo, pNotEscape) {
|
||||
var ret = pStr;
|
||||
this.replaceStr = function(str, from, to, notEscape) {
|
||||
var isStr = Util.isStr(str),
|
||||
regExp = new RegExp(from, 'g');
|
||||
|
||||
if (pStr && pFrom) {
|
||||
if (!pNotEscape)
|
||||
pFrom = Util.escapeRegExp(pFrom);
|
||||
if (isStr && from) {
|
||||
if (!notEscape)
|
||||
from = Util.escapeRegExp(from);
|
||||
|
||||
ret = pStr.replace(new RegExp(pFrom, 'g'), pTo);
|
||||
str = str.replace(regExp, to);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue