mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-09 00:24:20 +01:00
createStatusController: parse mentions in text
This commit is contained in:
16
src/utils/text.ts
Normal file
16
src/utils/text.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export async function asyncReplaceAll(
|
||||
input: string,
|
||||
regex: RegExp,
|
||||
replacer: (match: string, ...args: string[]) => Promise<string>,
|
||||
): Promise<string> {
|
||||
const promises: Promise<string>[] = [];
|
||||
|
||||
input.replaceAll(new RegExp(regex), (match, ...args) => {
|
||||
promises.push(replacer(match, ...args));
|
||||
return '';
|
||||
});
|
||||
|
||||
let i = 0;
|
||||
const replacements = await Promise.all(promises);
|
||||
return input.replaceAll(new RegExp(regex), () => replacements[i++]);
|
||||
}
|
||||
Reference in New Issue
Block a user