String.replaceAll Polyfill
This commit is contained in:
parent
76d7ccae53
commit
84ba78d067
2 changed files with 21 additions and 1 deletions
|
@ -18,7 +18,7 @@ Android port of OMORI RPG game
|
||||||
|
|
||||||
- [ ] Options menu fix
|
- [ ] Options menu fix
|
||||||
- [x] Physical gamepad support
|
- [x] Physical gamepad support
|
||||||
- [ ] replaceAll polyfill
|
- [x] replaceAll polyfill
|
||||||
- [ ] External saves (Android/data)
|
- [ ] External saves (Android/data)
|
||||||
- [ ] Cordova localhost bug
|
- [ ] Cordova localhost bug
|
||||||
- [x] WakeLock
|
- [x] WakeLock
|
||||||
|
|
|
@ -2,6 +2,26 @@
|
||||||
|
|
||||||
window._MEMO_PATHS = {}
|
window._MEMO_PATHS = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function replaceSpecialSymbols(s) {
|
function replaceSpecialSymbols(s) {
|
||||||
const memoized = _MEMO_PATHS[s];
|
const memoized = _MEMO_PATHS[s];
|
||||||
if (memoized != undefined) {
|
if (memoized != undefined) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue