11import uniq = require( "lodash.uniq" ) ;
22import uniqWith = require( "lodash.uniqwith" ) ;
33import sortBy = require( "lodash.sortby" ) ;
4+ import escapeStringRegexp = require( "escape-string-regexp" ) ;
5+ import { isRegExpString , parseRegExpString } from "./regexp-parse" ;
46
57const execall = require ( "execall" ) ;
68const 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+
2110const DEFAULT_FLAGS = "g" ;
2211
2312const defaultFlags = ( flagsString : string ) => {
@@ -35,7 +24,7 @@ export interface matchPatternResult {
3524
3625const createRegExp = ( patternString : string ) : RegExp => {
3726 if ( patternString . length === 0 ) {
38- throw new Error ( "Emtpy string can not includes" ) ;
27+ throw new Error ( "Empty string can not includes" ) ;
3928 }
4029 if ( isRegExpString ( patternString ) ) {
4130 const regExpStructure = parseRegExpString ( patternString ) ;
@@ -47,10 +36,7 @@ const createRegExp = (patternString: string): RegExp => {
4736 }
4837 throw new Error ( `"${ patternString } " can not parse as RegExp.` ) ;
4938 } else {
50- return toRegex ( patternString , {
51- flags : DEFAULT_FLAGS ,
52- contains : true
53- } ) ;
39+ return new RegExp ( escapeStringRegexp ( patternString ) , DEFAULT_FLAGS ) ;
5440 }
5541} ;
5642
0 commit comments