Added polyfill

This commit is contained in:
Mattia Mascarello 2021-11-02 11:17:13 +01:00 committed by GitHub
parent dcb6e08f76
commit dd1a147835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

13
main.js
View File

@ -1,3 +1,16 @@
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);
};
}
function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}