File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 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+ / ^ \/ .* \/ [ d g i m s u y ] * $ / . test ( maybeRegexp ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments