1
1
import uniq = require( "lodash.uniq" ) ;
2
2
import uniqWith = require( "lodash.uniqwith" ) ;
3
3
import sortBy = require( "lodash.sortby" ) ;
4
+ import escapeStringRegexp = require( "escape-string-regexp" ) ;
5
+ import { isRegExpString , parseRegExpString } from "./regexp-parse" ;
4
6
5
7
const execall = require ( "execall" ) ;
6
8
const toRegex = require ( "to-regex" ) ;
7
- const REGEXP_LITERAL_PATTERN = / ^ \/ ( .* ) \/ ( [ g u i m y ] * ) $ / ;
8
- const parseRegExpString = ( str : string ) : { source : string ; flagString : string } | null => {
9
- const result = str . match ( REGEXP_LITERAL_PATTERN ) ;
10
- if ( ! result ) {
11
- return null ;
12
- }
13
- return {
14
- source : result [ 1 ] ,
15
- flagString : result [ 2 ]
16
- } ;
17
- } ;
18
- const isRegExpString = ( str : string ) : boolean => {
19
- return REGEXP_LITERAL_PATTERN . test ( str ) ;
20
- } ;
9
+
21
10
const DEFAULT_FLAGS = "g" ;
22
11
23
12
const defaultFlags = ( flagsString : string ) => {
@@ -35,7 +24,7 @@ export interface matchPatternResult {
35
24
36
25
const createRegExp = ( patternString : string ) : RegExp => {
37
26
if ( patternString . length === 0 ) {
38
- throw new Error ( "Emtpy string can not includes" ) ;
27
+ throw new Error ( "Empty string can not includes" ) ;
39
28
}
40
29
if ( isRegExpString ( patternString ) ) {
41
30
const regExpStructure = parseRegExpString ( patternString ) ;
@@ -47,10 +36,7 @@ const createRegExp = (patternString: string): RegExp => {
47
36
}
48
37
throw new Error ( `"${ patternString } " can not parse as RegExp.` ) ;
49
38
} else {
50
- return toRegex ( patternString , {
51
- flags : DEFAULT_FLAGS ,
52
- contains : true
53
- } ) ;
39
+ return new RegExp ( escapeStringRegexp ( patternString ) , DEFAULT_FLAGS ) ;
54
40
}
55
41
} ;
56
42
0 commit comments