Skip to content

Commit

Permalink
ui: patch up replaceAll; closes #4654
Browse files Browse the repository at this point in the history
  • Loading branch information
fichtner committed Feb 1, 2021
1 parent 3782c38 commit 87c00de
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/opnsense/www/js/polyfills.js
Expand Up @@ -150,3 +150,21 @@ if (!Array.prototype.includes) {
}
});
}

/**
* 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, newStr) {
// If a regex pattern
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
return this.replace(str, newStr);
}

// If a string
return this.replace(new RegExp(str, 'g'), newStr);
};
}

0 comments on commit 87c00de

Please sign in to comment.