From a890a5d4c10b46942364199d4b2b28ff70050a39 Mon Sep 17 00:00:00 2001 From: Tugrul Topuz Date: Thu, 2 May 2024 05:44:50 +0300 Subject: [PATCH] jsr docs update --- jsr.json | 3 ++- src/index.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/jsr.json b/jsr.json index fe4aee3..ee5586e 100644 --- a/jsr.json +++ b/jsr.json @@ -1,5 +1,6 @@ { "name": "@tugrul/async-replace", - "version": "1.0.3", + "description": "A lightweight TypeScript module for asynchronous string replacement with concurrency limiting.", + "version": "1.0.4", "exports": "./mod.ts" } diff --git a/src/index.ts b/src/index.ts index f7d4668..a21a27c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,23 @@ +/** + * Represents a callback function used for string replacement. + * @param match - The matched substring. + * @param groups - An array of captured groups in the regex match. + * @param index - The starting index of the match in the input string. + * @param input - The original input string. + * @returns A Promise resolving to the replacement string. + */ export type ReplaceCallback = (match: string, groups: string[], index: number, input: string) => Promise; +/** + * Asynchronously replaces substrings in a string that match a specified regular expression + * with the results of a specified callback function. + * @param str - The input string to perform replacements on. + * @param regex - The regular expression pattern to match substrings against. + * @param callback - The callback function that produces the replacement substring. + * @param limit - Optional. The maximum number of replacements to make concurrently. Default is 0 (no limit). + * @returns A Promise resolving to the modified string after replacements. + */ export async function replace(str: string, regex: RegExp, callback: ReplaceCallback, limit: number = 0): string { let last = 0;