Skip to content

Commit fb771c1

Browse files
committed
Add bun engine
1 parent 1fd7786 commit fb771c1

File tree

2 files changed

+76
-8
lines changed

2 files changed

+76
-8
lines changed

src/engines/bun.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import type { RegexEngine } from "./RegexEngine";
2+
3+
export const bun: RegexEngine = {
4+
description: "RegExp Object",
5+
enabled: true,
6+
help_label: "MDN",
7+
help_url:
8+
"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp",
9+
handle: "bun",
10+
level: "beta",
11+
links: {
12+
"MDN RegExp Object":
13+
"https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp",
14+
"MDN flags":
15+
"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#advanced_searching_with_flags",
16+
},
17+
logo_icon: "https://www.vectorlogo.zone/logos/bunsh/bunsh-icon.svg",
18+
logo_ar21: "https://www.vectorlogo.zone/logos/bunsh/bunsh-ar21.svg",
19+
nodeping_url: "https://nodeping.com/reports/checks/LATER",
20+
notfound: ["javascript", "typescript"],
21+
options: [
22+
{
23+
code: "d",
24+
description: "Generate indices for substring matches. (hasIndices)",
25+
},
26+
{ code: "g", legacyCode: "global", description: "Global search. (global)" },
27+
{
28+
code: "i",
29+
legacyCode: "ignorecase",
30+
description: "Case-insensitive search. (ignoreCase)",
31+
},
32+
{
33+
code: "m",
34+
legacyCode: "multiline",
35+
description:
36+
"Allows ^ and $ to match next to newline characters. (multiline)",
37+
},
38+
{
39+
code: "s",
40+
description: "Allows . to match newline characters. (dotAll)",
41+
},
42+
{
43+
code: "u",
44+
description: `"Unicode"; treat a pattern as a sequence of Unicode code points. (unicode)`,
45+
},
46+
{
47+
code: "v",
48+
description:
49+
"An upgrade to the u mode with more Unicode features. (unicodeSets)",
50+
},
51+
{
52+
code: "y",
53+
description: `Perform a "sticky" search that matches starting at the current position in the target string. (sticky)`,
54+
},
55+
],
56+
short_name: "Bun",
57+
source_url: "https://github.com/regexplanet/regexplanet-bun",
58+
status_url: "https://bun.gcr.regexplanet.com/status.json",
59+
test_url: "https://bun.gcr.regexplanet.com/test.json",
60+
};

src/engines/index.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TestOutput } from "@/types/TestOutput";
22
import type { RegexEngine } from "./RegexEngine";
33

4+
import { bun } from "./bun";
45
import { dotnet } from "./dotnet";
56
import { erlang } from "./erlang";
67
import { go } from "./go";
@@ -16,8 +17,10 @@ import { ruby } from "./ruby";
1617
import { rust } from "./rust";
1718
import { tcl } from "./tcl";
1819
import { xregexp } from "./xregexp";
20+
import { TestInput } from "@/types/TestInput";
1921

2022
const engineMap = new Map<string, RegexEngine>([
23+
[bun.handle, bun],
2124
[erlang.handle, erlang],
2225
[go.handle, go],
2326
[haskell.handle, haskell],
@@ -91,19 +94,24 @@ function getWorkingEngines(): Array<RegexEngine> {
9194
}
9295

9396
async function runTest(
94-
engine: RegexEngine,
95-
testInput: FormData
97+
testInput: TestInput
9698
): Promise<TestOutput> {
97-
if (!engine.test_url) {
98-
throw new EngineNotImplementedError(engine.handle);
99+
100+
const theEngine = getEngineOrThrow(testInput.engine);
101+
102+
if (!theEngine.test_url) {
103+
throw new EngineNotImplementedError(theEngine.handle);
99104
}
100105

101106
// this is a bogus 'as', but next build insists on it
102-
const postData = new URLSearchParams(
103-
testInput as unknown as Record<string, string>
104-
);
107+
const postData =
108+
`regex=${encodeURIComponent(testInput.regex)}`
109+
+ `&replacement=${encodeURIComponent(testInput.replacement)}`
110+
+ `&${testInput.option.map((option) => `option=${option}`).join("&")}`
111+
+ `&${testInput.inputs.map((input) => `input=${input}`).join("&")}`
112+
;
105113

106-
const response = await fetch(engine.test_url, {
114+
const response = await fetch(theEngine.test_url, {
107115
method: "POST",
108116
body: postData,
109117
headers: {

0 commit comments

Comments
 (0)