Skip to content

Commit

Permalink
jsr docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
tugrul committed May 2, 2024
1 parent 1089b53 commit a890a5d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -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"
}
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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<string>;

/**
* 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;
Expand Down

0 comments on commit a890a5d

Please sign in to comment.