Add formatting and comments from util.ts to util.js

This commit is contained in:
Adam Stachowicz
2021-09-19 23:09:52 +02:00
parent 795d5f586f
commit bcc02c1680
2 changed files with 49 additions and 8 deletions

View File

@@ -50,16 +50,15 @@ export function debug(msg: any) {
declare global { interface String { replaceAll(str: string, newStr: string): string; } }
/**
* String.prototype.replaceAll() polyfill
* https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/
* @author Chris Ferdinandi
* @license MIT
*/
export function polyfill() {
/**
* String.prototype.replaceAll() polyfill
* https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/
* @author Chris Ferdinandi
* @license MIT
*/
if (!String.prototype.replaceAll) {
String.prototype.replaceAll = function (str: string, newStr: string) {
// If a regex pattern
if (Object.prototype.toString.call(str).toLowerCase() === "[object regexp]") {
return this.replace(str, newStr);
@@ -67,7 +66,6 @@ export function polyfill() {
// If a string
return this.replace(new RegExp(str, "g"), newStr);
};
}
}