UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

26 lines (22 loc) 501 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); /** * polyfill for replaceAll * * @export * * @example * * replaceAllPolyfill() */ function replaceAllPolyfill() { // @ts-ignore String.prototype.replaceAll = function (s1, s2) { var newStr = s1; if (typeof s1 === 'string') { newStr = s1.replace(/([|+*?[\](){}^$|])/g, '\\$1'); } return this.replace(new RegExp(newStr, 'gm'), s2); }; } exports.replaceAllPolyfill = replaceAllPolyfill;