diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..41583e3 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@jsr:registry=https://npm.jsr.io diff --git a/bun.lockb b/bun.lockb index 08f1f16..ba735b8 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 338b7c6..16f7cfd 100644 --- a/package.json +++ b/package.json @@ -11,5 +11,8 @@ "start": "bun run --logLevel=debug dist/server.js", "build": "bun build src/server.ts --outdir ./dist" }, - "type": "module" + "type": "module", + "dependencies": { + "@regexplanet/common": "npm:@jsr/regexplanet__common" + } } \ No newline at end of file diff --git a/src/runTest.ts b/src/runTest.ts deleted file mode 100644 index ec0522d..0000000 --- a/src/runTest.ts +++ /dev/null @@ -1,209 +0,0 @@ -import { type TestInput, type TestOutput } from "./types"; - -function h(unsafe: string): string { - if (unsafe == null) { - return ""; - } - - return unsafe - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/"/g, """) - .replace(/'/g, "'"); -} - -export function runTest(input: TestInput): TestOutput { - if (input.regex == null || input.regex.length == 0) { - return { success: false, message: "No regex to test!" }; - } - - const options = input.option ? input.option.join("") : undefined; - - const html = []; - html.push( - '
Regular Expression | \n"); - html.push("\t\t"); - html.push(h(input.regex)); - html.push(" | \n"); - html.push("\t
Replacement | \n"); - html.push("\t\t"); - html.push(h(input.replacement)); - html.push(" | \n"); - - html.push("\t
Options | \n"); - html.push("\t\t"); - html.push(options ? h(options) : "(none)"); - html.push(" | \n"); - html.push("\t
Test | \n'); - html.push("\t\t\tInput | "); - html.push("\t\t\tregex.test() | "); - html.push("\t\t\tinput.replace() | "); - html.push("\t\t\tinput.replaceAll() | "); - html.push("\t\t\tinput.split()[] | "); - html.push("\t\t\tregex.exec().index | "); - html.push("\t\t\tregex.exec()[] | "); - html.push("\t\t\tregex.lastIndex | "); - html.push("\t\t|||
---|---|---|---|---|---|---|---|---|---|---|---|
'); - html.push(loop + 1); - html.push(" | \n"); - - html.push("\t\t\t"); - html.push(h(target)); - html.push(" | \n"); - - html.push("\t\t\t"); - html.push( - new RegExp(input.regex, options).test(target) ? "true" : "false" - ); - html.push(" | \n"); - - html.push("\t\t\t"); - html.push( - h(target.replace(new RegExp(input.regex, options), input.replacement)) - ); - html.push(" | \n"); - - html.push("\t\t\t"); - try { - html.push( - h( - target.replaceAll( - new RegExp(input.regex, options), - input.replacement - ) - ) - ); - } catch (replaceAllErr) { - const message = - replaceAllErr instanceof Error - ? replaceAllErr.message - : `unknown error ${replaceAllErr}`; - html.push(`${message}`); - } - html.push(" | \n"); - - html.push("\t\t\t");
- var splits = target.split(new RegExp(input.regex, options));
- for (var split = 0; split < splits.length; split++) {
- html.push("[");
- html.push(split);
- html.push("]: ");
- html.push(splits[split] == null ? "(null)" : h(splits[split]));
- html.push(" "); - } - html.push(" | \n");
-
- var regex = new RegExp(input.regex, options);
- var result = regex.exec(target);
- if (result == null) {
- html.push('\t\t\t(null) | \n'); - } else { - var first = true; - - while (result != null) { - if (first == true) { - first = false; - } else { - html.push("'); - html.push("regex.exec()"); - html.push(" | \n"); - } - - html.push("\t\t\t"); - html.push(result.index); - html.push(" | \n"); - - html.push("\t\t\t");
- for (var capture = 0; capture < result.length; capture++) {
- html.push("[");
- html.push(capture);
- html.push("]: ");
- html.push(
- result[capture] == null ? "(null)" : h(result[capture])
- );
- html.push(" "); - } - html.push(" | \n");
-
- html.push("\t\t\t"); - html.push(regex.lastIndex); - html.push(" | \n"); - - result = global ? regex.exec(target) : null; - } - } - html.push("\t\t\n"); - count++; - } - } - - if (count == 0) { - html.push("\t\t|
'); - html.push("(no input to test)"); - html.push(" | \n"); - html.push("\t\t