Remove replaceAsync() dependency on String.prototype.matchAll().

This commit is contained in:
hackademix 2023-10-08 21:48:09 +02:00
parent 28972ba44f
commit fae6b04131
No known key found for this signature in database
GPG Key ID: 231A83AFDA9C2434
1 changed files with 7 additions and 3 deletions

View File

@ -145,9 +145,13 @@
async getContentCSS() {
contentCSS = contentCSS || (async () => {
const replaceAsync = async (string, regexp, replacerFunction) => {
const replacements = await Promise.all(
Array.from(string.matchAll(regexp),
match => replacerFunction(...match)));
regexp.lastIndex = 0;
const promises = [];
for (let match; match = regexp.exec(string);) {
promises.push(replacerFunction(...match));
}
const replacements = await Promise.all(promises);
regexp.lastIndex = 0;
let i = 0;
return string.replace(regexp, () => replacements[i++]);
}