Skip to content

Commit 7840255

Browse files
committed
added regexp file
1 parent 69e0439 commit 7840255

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/regexp.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags
2+
export const isConvertableRegexp = (maybeRegexp: string): boolean =>
3+
/^\/.*\/[dgimsuy]*$/.test(maybeRegexp);

tests/regexp.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { isConvertableRegexp } from "../src/regexp";
2+
3+
describe("isConvertableRegexp", () => {
4+
describe("match", () => {
5+
test.each([
6+
"//",
7+
"/hello/",
8+
"/hello/d",
9+
"/hello/g",
10+
"/hello/i",
11+
"/hello/m",
12+
"/hello/s",
13+
"/hello/u",
14+
"/hello/y",
15+
"/hello/dgimsuy",
16+
`/\\w+\\s/g`,
17+
`/^[a-z]+:[\\\/]$/i`,
18+
`/^(?:\d{3}|\(\d{3}\))([-\/\.])\d{3}\\1\d{4}$/`,
19+
])("%s", (maybeRegexp) => {
20+
expect(isConvertableRegexp(maybeRegexp)).toBeTruthy();
21+
});
22+
});
23+
describe("does not match", () => {
24+
test.each([
25+
"hello",
26+
"/world",
27+
"world/",
28+
"https://example.com/",
29+
" /hello/",
30+
"/hello/d ",
31+
"/hello/dgimsuy ",
32+
])("%s", (maybeRegexp) => {
33+
expect(isConvertableRegexp(maybeRegexp)).toBeFalsy();
34+
});
35+
});
36+
});

0 commit comments

Comments
 (0)