File tree 1 file changed +6
-10
lines changed
1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -561,24 +561,20 @@ function escape(str: string) {
561
561
}
562
562
563
563
/**
564
- * Escape and repeat a string for regular expressions.
564
+ * Escape and repeat loose characters for regular expressions.
565
565
*/
566
- function repeat ( str : string ) {
567
- return `${ escape ( str ) } +` ;
566
+ function looseReplacer ( value : string , loose : string ) {
567
+ return loose ? `${ escape ( value ) } +` : escape ( value ) ;
568
568
}
569
569
570
570
/**
571
571
* Encode all non-delimiter characters using the encode function.
572
572
*/
573
573
function toStringify ( loose : string ) {
574
- if ( loose ) {
575
- const re = new RegExp ( `[^${ escape ( loose ) } ]+|(.)` , "g" ) ;
576
- const replacer = ( value : string , loose : string ) =>
577
- loose ? repeat ( value ) : escape ( value ) ;
578
- return ( value : string ) => value . replace ( re , replacer ) ;
579
- }
574
+ if ( ! loose ) return escape ;
580
575
581
- return escape ;
576
+ const re = new RegExp ( `[^${ escape ( loose ) } ]+|(.)` , "g" ) ;
577
+ return ( value : string ) => value . replace ( re , looseReplacer ) ;
582
578
}
583
579
584
580
/**
You can’t perform that action at this time.
0 commit comments