Add String#replace & String#replaceAll (#653)

This commit is contained in:
Max Graey
2019-06-12 18:39:49 +03:00
committed by Daniel Wirtz
parent d4313f1ed8
commit 3af2603daa
15 changed files with 5206 additions and 3013 deletions

View File

@ -461,6 +461,7 @@ declare class String {
padStart(targetLength: i32, padString?: string): string;
padEnd(targetLength: i32, padString?: string): string;
replace(search: string, replacement: string): string;
replaceAll(search: string, replacement: string): string;
repeat(count?: i32): string;
slice(beginIndex: i32, endIndex?: i32): string;
split(separator?: string, limit?: i32): string[];

View File

@ -196,6 +196,16 @@ String["fromCodePoints"] = function fromCodePoints(arr) {
return String.fromCodePoint.apply(String, arr);
};
if (!String.prototype.replaceAll) {
Object.defineProperty(String.prototype, "replaceAll", {
value: function replaceAll(search, replacment) {
var res = this.split(search).join(replacment);
if (!search.length) res = replacment + res + replacment;
return res;
}
});
}
globalScope["isInteger"] = Number.isInteger;
globalScope["isFloat"] = function isFloat(arg) {