aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/extension.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-08 22:08:11 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-08 22:25:03 -0500
commit4d7940e8e4ceb0b90439fc9726339f796ee23940 (patch)
tree9aac5f220a0095feeb04d06e27309967483b791b /ext/mixed/js/extension.js
parentfa963722a79c26c1642bbf81a2e153bd0c1a3fe8 (diff)
Optimize dictFieldFormat
Diffstat (limited to 'ext/mixed/js/extension.js')
-rw-r--r--ext/mixed/js/extension.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/mixed/js/extension.js b/ext/mixed/js/extension.js
index 54862e19..12ed9c1f 100644
--- a/ext/mixed/js/extension.js
+++ b/ext/mixed/js/extension.js
@@ -133,3 +133,18 @@ function promiseTimeout(delay, resolveValue) {
return promise;
}
+
+function stringReplaceAsync(str, regex, replacer) {
+ let match;
+ let index = 0;
+ const parts = [];
+ while ((match = regex.exec(str)) !== null) {
+ parts.push(str.substring(index, match.index), replacer(...match, match.index, str));
+ index = regex.lastIndex;
+ }
+ if (parts.length === 0) {
+ return Promise.resolve(str);
+ }
+ parts.push(str.substring(index));
+ return Promise.all(parts).then(v => v.join(''));
+}