mirror of https://github.com/186526/net186-bot
19 lines
541 B
TypeScript
19 lines
541 B
TypeScript
|
if (!String.prototype.replaceAll) {
|
||
|
String.prototype.replaceAll = function (
|
||
|
searchValue: string | RegExp,
|
||
|
replaceValue: string | ((substring: string, ...args: any[]) => string)
|
||
|
): string {
|
||
|
if (typeof replaceValue == "function") throw new Error("Not Supported.");
|
||
|
// If a regex pattern
|
||
|
if (
|
||
|
Object.prototype.toString.call(searchValue).toLowerCase() ===
|
||
|
"[object regexp]"
|
||
|
) {
|
||
|
return this.replace(searchValue, replaceValue);
|
||
|
}
|
||
|
|
||
|
// If a string
|
||
|
return this.replace(new RegExp(searchValue, "g"), replaceValue);
|
||
|
};
|
||
|
}
|