Browse Source

无JIRA任务 refactor: replaceAll兼容null

master
windy 5 years ago
parent
commit
fcca3f4e1d
  1. 19
      src/core/func/__test__/string.test.js
  2. 2
      src/core/func/string.js

19
src/core/func/__test__/string.test.js

@ -0,0 +1,19 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2020/6/5
*/
describe("dateFunctionTest", function () {
before(function () {
});
/**
* test_author_windy
*/
it("getWeekNumber", function () {
expect(BI.replaceAll(null, "A", "b")).to.equal(null);
expect(BI.replaceAll("A", "A", "b")).to.equal("b");
});
});

2
src/core/func/string.js

@ -81,7 +81,7 @@ _.extend(BI, {
* @returns {String} 替换后的字符串 * @returns {String} 替换后的字符串
*/ */
replaceAll: function (str, s1, s2) { replaceAll: function (str, s1, s2) {
return str.replace(new RegExp(s1, "gm"), s2); return BI.isNull(str) ? str : str.replace(new RegExp(s1, "gm"), s2);
}, },
/** /**
* 总是让字符串以指定的字符开头 * 总是让字符串以指定的字符开头

Loading…
Cancel
Save