Skip to content

Conversation

Jason3S
Copy link
Contributor

@Jason3S Jason3S commented Jun 21, 2025

When this library was created functions like String.matchAll were not widely available.

This API change is to have the worker methods match String.match, String.matchAll, RegExp.exec.

The new API

/**
 * Run text.matchAll against a RegExp in a worker.
 * @param text - The text to search within.
 * @param regExp - The regular expression to match against the text.
 * @param timeLimitMs - Optional time limit in milliseconds for the operation.
 */
export async function workerMatchAll(text: string, regExp: RegExp, timeLimitMs?: number): Promise<MatchAllRegExpResult> {
    const worker = new RegExpWorker();
    return await worker.matchAll(text, regExp, timeLimitMs);
}

/**
 * Runs text.matchAll against an array of RegExps in a worker.
 * @param text - The text to search within.
 * @param regExps - An array of regular expressions to match against the text.
 * @param timeLimitMs - Optional time limit in milliseconds for the operation.
 */
export async function workerMatchAllArray(text: string, regExps: RegExp[], timeLimitMs?: number): Promise<MatchAllRegExpArrayResult> {
    const worker = new RegExpWorker();
    return await worker.matchAllArray(text, regExps, timeLimitMs);
}

/**
 * Run RegExp.exec in a worker.
 * @param regExp - The regular expression to execute.
 * @param text - The text to search within.
 * @param timeLimitMs - Optional time limit in milliseconds for the operation.
 */
export async function workerExec(regExp: RegExp, text: string, timeLimitMs?: number): Promise<ExecRegExpResult> {
    const worker = new RegExpWorker();
    return await worker.exec(regExp, text, timeLimitMs);
}

/**
 * Run text.match with a RegExp in a worker.
 * @param text - The text to search within.
 * @param regExp - The regular expression to match against the text.
 * @param timeLimitMs - Optional time limit in milliseconds for the operation.
 */
export async function workerMatch(text: string, regExp: RegExp, timeLimitMs?: number): Promise<MatchRegExpResult> {
    const worker = new RegExpWorker();
    return await worker.match(text, regExp, timeLimitMs);
}

Migration from 3.x to 4.x

The order of the parameters have changed to closer match JavaScript.
match methods have the text first followed by the RegExp.

  • execRegExpOnWorker -> workerMatchAll
  • execRegExpMatrixOnWorker -> Deleted - Use workerMatchAllArray
  • RegExpWorker.execRegExpMatrix -> Deleted - Use RegExpWorker.matchAllArray
  • RegExpWorker.matchRegExp -> Deleted -- it returned number ranges instead of matches.
  • RegExpWorker.matchRegExpArray -> Deleted -- it returned number ranges instead of matches.
  • RegExpWorker.execRegExp -> RegExpWorker.matchAll

@Jason3S Jason3S merged commit f00328b into main Jun 21, 2025
16 checks passed
@Jason3S Jason3S deleted the dev-api branch June 21, 2025 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant