File tree Expand file tree Collapse file tree 4 files changed +47
-5
lines changed Expand file tree Collapse file tree 4 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -16,11 +16,19 @@ test('`regexBuilder` flags', () => {
16
16
expect ( buildRegExp ( 'a' , { hasIndices : true } ) . flags ) . toBe ( 'd' ) ;
17
17
expect ( buildRegExp ( 'a' , { hasIndices : false } ) . flags ) . toBe ( '' ) ;
18
18
19
+ expect ( buildRegExp ( 'a' , { dotAll : true } ) . flags ) . toBe ( 's' ) ;
20
+ expect ( buildRegExp ( 'a' , { dotAll : false } ) . flags ) . toBe ( '' ) ;
21
+
22
+ expect ( buildRegExp ( 'a' , { sticky : true } ) . flags ) . toBe ( 'y' ) ;
23
+ expect ( buildRegExp ( 'a' , { sticky : false } ) . flags ) . toBe ( '' ) ;
24
+
19
25
expect (
20
26
buildRegExp ( 'a' , {
21
27
global : true , //
22
28
ignoreCase : true ,
23
29
multiline : false ,
30
+ dotAll : true ,
31
+ sticky : true ,
24
32
} ) . flags ,
25
- ) . toBe ( 'gi ' ) ;
33
+ ) . toBe ( 'gisy ' ) ;
26
34
} ) ;
Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ function encodeFlags(flags: RegexFlags): string {
31
31
if ( flags . ignoreCase ) result += 'i' ;
32
32
if ( flags . multiline ) result += 'm' ;
33
33
if ( flags . hasIndices ) result += 'd' ;
34
+ if ( flags . dotAll ) result += 's' ;
35
+ if ( flags . sticky ) result += 'y' ;
34
36
35
37
return result ;
36
38
}
Original file line number Diff line number Diff line change @@ -22,16 +22,44 @@ export interface RegexConstruct {
22
22
encode ( ) : EncodeResult ;
23
23
}
24
24
25
+ /**
26
+ * Flags to be passed to RegExp constructor.
27
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp#flags
28
+ */
25
29
export interface RegexFlags {
26
- /** Find all matches in a string, instead of just the first one. */
30
+ /**
31
+ * Find all matches in a string, instead of just the first one.
32
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global
33
+ */
27
34
global ?: boolean ;
28
35
29
- /** Perform case-insensitive matching. */
36
+ /**
37
+ * Perform case-insensitive matching.
38
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase
39
+ */
30
40
ignoreCase ?: boolean ;
31
41
32
- /** Treat the start and end of each line in a string as the beginning and end of the string. */
42
+ /**
43
+ * Treat the start and end of each line in a string as the beginning and end of the string.
44
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline
45
+ */
33
46
multiline ?: boolean ;
34
47
35
- /** Penerate the start and end indices of each captured group in a match. */
48
+ /**
49
+ * Generate the start and end indices of each captured group in a match.
50
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices
51
+ */
36
52
hasIndices ?: boolean ;
53
+
54
+ /**
55
+ * MDN: _Allows . to match newlines._
56
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll
57
+ */
58
+ dotAll ?: boolean ;
59
+
60
+ /**
61
+ * MDN: _Matches only from the index indicated by the lastIndex property of this regular expression in the target string. Does not attempt to match from any later indexes._
62
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky
63
+ */
64
+ sticky ?: boolean ;
37
65
}
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ function buildRegExp(
13
13
ignoreCase? : boolean ;
14
14
multiline? : boolean ;
15
15
hasIndices? : boolean ;
16
+ dotAll? : boolean ;
17
+ sticky? : boolean ;
16
18
},
17
19
): RegExp ;
18
20
```
@@ -25,3 +27,5 @@ It optionally accepts a list of regex flags:
25
27
- ` ignoreCase ` - perform case-insensitive matching.
26
28
- ` multiline ` - treat the start and end of each line in a string as the beginning and end of the string.
27
29
- ` hasIndices ` - provide each captured group's start and end indices in a match.
30
+ - ` dotAll ` - allows ` . ` to match newlines.
31
+ - ` sticky ` - matches only from the index indicated by the ` lastIndex ` property, does not attempt to match from any later indexes.
You can’t perform that action at this time.
0 commit comments