From 8536fe4610dd70c9d58616a116e0b2c791d92592 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Sat, 15 Oct 2022 00:27:25 -0400 Subject: [PATCH] Remove string replaceAll implementations --- src/components/alert.js | 7 +------ src/components/apphost.js | 12 +----------- src/components/confirm/confirm.js | 6 +----- src/components/prompt/prompt.js | 6 +----- src/components/viewContainer.js | 9 +++------ src/scripts/globalize.js | 6 +----- 6 files changed, 8 insertions(+), 38 deletions(-) diff --git a/src/components/alert.js b/src/components/alert.js index a4689c79ac..f8c4209f6d 100644 --- a/src/components/alert.js +++ b/src/components/alert.js @@ -5,11 +5,6 @@ import globalize from '../scripts/globalize'; /* eslint-disable indent */ - function replaceAll(originalString, strReplace, strWith) { - const reg = new RegExp(strReplace, 'ig'); - return originalString.replace(reg, strWith); - } - function useNativeAlert() { // webOS seems to block modals // Tizen 2.x seems to block modals @@ -33,7 +28,7 @@ import globalize from '../scripts/globalize'; await appRouter.ready(); if (useNativeAlert()) { - alert(replaceAll(options.text || '', '
', '\n')); + alert((options.text || '').replaceAll('
', '\n')); return Promise.resolve(); } else { const items = []; diff --git a/src/components/apphost.js b/src/components/apphost.js index d4ae5a79d4..4a12a78d0e 100644 --- a/src/components/apphost.js +++ b/src/components/apphost.js @@ -63,23 +63,13 @@ function getDeviceProfile(item) { }); } -function escapeRegExp(str) { - return str.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1'); -} - -function replaceAll(originalString, strReplace, strWith) { - const strReplace2 = escapeRegExp(strReplace); - const reg = new RegExp(strReplace2, 'ig'); - return originalString.replace(reg, strWith); -} - function generateDeviceId() { const keys = []; keys.push(navigator.userAgent); keys.push(new Date().getTime()); if (window.btoa) { - return replaceAll(btoa(keys.join('|')), '=', '1'); + return btoa(keys.join('|')).replaceAll('=', '1'); } return new Date().getTime(); diff --git a/src/components/confirm/confirm.js b/src/components/confirm/confirm.js index 0624fb3ffb..a96910e16a 100644 --- a/src/components/confirm/confirm.js +++ b/src/components/confirm/confirm.js @@ -3,10 +3,6 @@ import browser from '../../scripts/browser'; import dialog from '../dialog/dialog'; import globalize from '../../scripts/globalize'; -function replaceAll(str, find, replace) { - return str.split(find).join(replace); -} - function useNativeConfirm() { // webOS seems to block modals // Tizen 2.x seems to block modals @@ -24,7 +20,7 @@ async function nativeConfirm(options) { }; } - const text = replaceAll(options.text || '', '
', '\n'); + const text = (options.text || '').replaceAll('
', '\n'); await appRouter.ready(); const result = window.confirm(text); diff --git a/src/components/prompt/prompt.js b/src/components/prompt/prompt.js index df93cfbbf2..54b6e338fe 100644 --- a/src/components/prompt/prompt.js +++ b/src/components/prompt/prompt.js @@ -12,10 +12,6 @@ import '../formdialog.scss'; import template from './prompt.template.html'; export default (() => { - function replaceAll(str, find, replace) { - return str.split(find).join(replace); - } - function setInputProperties(dlg, options) { const txtInput = dlg.querySelector('#txtInput'); @@ -105,7 +101,7 @@ export default (() => { }; } - const label = replaceAll(options.label || '', '
', '\n'); + const label = (options.label || '').replaceAll('
', '\n'); const result = prompt(label, options.text || ''); if (result) { diff --git a/src/components/viewContainer.js b/src/components/viewContainer.js index 48660290c5..82e7ef40c7 100644 --- a/src/components/viewContainer.js +++ b/src/components/viewContainer.js @@ -112,14 +112,11 @@ import Dashboard from '../utils/dashboard'; } } - function replaceAll(str, find, replace) { - return str.split(find).join(replace); - } - function parseHtml(html, hasScript) { if (hasScript) { - html = replaceAll(html, '\x3c!----\x3e', ''); + html = html + .replaceAll('\x3c!----\x3e', ''); } const wrapper = document.createElement('div'); diff --git a/src/scripts/globalize.js b/src/scripts/globalize.js index 7a98dd2a4c..81c727c4ff 100644 --- a/src/scripts/globalize.js +++ b/src/scripts/globalize.js @@ -232,14 +232,10 @@ const Direction = { return key; } - function replaceAll(str, find, replace) { - return str.split(find).join(replace); - } - export function translate(key) { let val = translateKey(key); for (let i = 1; i < arguments.length; i++) { - val = replaceAll(val, '{' + (i - 1) + '}', arguments[i].toLocaleString(currentCulture)); + val = val.replaceAll('{' + (i - 1) + '}', arguments[i].toLocaleString(currentCulture)); } return val; }