tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
16 lines • 833 B
text/typescript
/**
* Asynchronously replaces matches in a string using a regex and an async function.
*
* @param {string} str - The input string to perform replacements on.
* @param {RegExp} regex - The regular expression to match substrings for replacement.
* @param {Function} asyncFn - An asynchronous function that returns a replacement for each match.
* It receives the same arguments as a standard `replace` callback.
* @returns {Promise<string>} The resulting string with all async replacements applied.
*
* @example
* await asyncReplace("Hello @user1 and @user2!", /@\w+/g, async (mention) => {
* return await getUserNameFromMention(mention);
* });
*/
export default function asyncReplace(str: string, regex: RegExp, asyncFn: Function): Promise<string>;
//# sourceMappingURL=replaceAsync.d.mts.map