@ptolemy2002/rgx 7.3.0 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/internal/taggedTemplateToArray.js +16 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1113,7 +1113,9 @@ function rgx(flags?: string, multiline?: boolean): (strings: TemplateStringsArra
|
|
|
1113
1113
|
|
|
1114
1114
|
Creates and returns a template tag function that constructs an `ExtRegExp` object from the provided template literal with the provided flags. The template literal can contain RGX tokens, which will be resolved and concatenated with the literal parts to form the final regex pattern. Before constructing the pattern, any convertible token that defines `rgxAcceptInsertion` is checked; if it returns `false` or a string, an `RGXInsertionRejectedError` is thrown with details about the reason and exactly where the rejection occurred.
|
|
1115
1115
|
|
|
1116
|
-
When `multiline` is `true` (the default), the literal string parts of the template are processed to strip newlines, trim leading whitespace from each line, and remove empty lines, then joined together. This allows you to write regex patterns across multiple lines in the source code for readability without the newlines and indentation becoming part of the pattern. Only the literal string parts between tokens are affected — interpolated values (tokens) are preserved as-is, including string tokens passed via `${"..."}`.
|
|
1116
|
+
When `multiline` is `true` (the default), the literal string parts of the template are processed to strip newlines, trim leading whitespace from each line, and remove empty lines, then joined together. This allows you to write regex patterns across multiple lines in the source code for readability without the newlines and indentation becoming part of the pattern. Only the literal string parts between tokens are affected — interpolated values (tokens) are preserved as-is, including string tokens passed via `${"..."}`. Also, comments (denoted with `//`) ending a line or on a line by themselves are stripped. If a command ends a line, that line is also stripped of whitespace on the right side.
|
|
1117
|
+
|
|
1118
|
+
When `multiline` is `false`, all literal string parts are preserved exactly as written, including newlines and whitespace.
|
|
1117
1119
|
|
|
1118
1120
|
The provided `flags` are passed as `currentFlags` to the resolver, enabling inline modifier groups for any `RegExp` literal tokens whose localizable flags (`i`, `m`, `s`) differ from the parent flags. For example, embedding `/foo/i` in a no-flag context produces `(?i:foo)`, while embedding `/bar/` in an `i`-flag context produces `(?-i:bar)`.
|
|
1119
1121
|
|
|
@@ -1150,7 +1152,7 @@ const pattern6 = rgx()`
|
|
|
1150
1152
|
#### Parameters
|
|
1151
1153
|
**Direct**
|
|
1152
1154
|
- `flags` (`string`, optional): The regex flags to apply to the resulting `ExtRegExp` object (e.g., 'g', 'i', 'm', or custom registered flags). If not provided, no flags will be applied. If provided and not valid regex flags (vanilla or registered custom), an `RGXInvalidRegexFlagsError` will be thrown.
|
|
1153
|
-
- `multiline` (`boolean`, optional): Whether to strip newlines and trim leading whitespace from the literal string parts of the template. Defaults to `true`. When `true`, each literal string part is split by newlines, each line has its leading whitespace trimmed, empty lines are removed, and the remaining lines are joined together. Interpolated tokens (including string tokens via `${"..."}`) are not affected. When `false`, literal string parts are preserved exactly as written.
|
|
1155
|
+
- `multiline` (`boolean`, optional): Whether to strip newlines and trim leading whitespace from the literal string parts of the template. Defaults to `true`. When `true`, each literal string part is split by newlines, each line has its leading whitespace trimmed, empty lines are removed, comments (denoted with `//`) ending a line or on a line by themselves are stripped, and the remaining lines are joined together. Interpolated tokens (including string tokens via `${"..."}`) are not affected. When `false`, literal string parts are preserved exactly as written.
|
|
1154
1156
|
|
|
1155
1157
|
**Template Tag**
|
|
1156
1158
|
- `strings` (`TemplateStringsArray`): The literal parts of the template string.
|
|
@@ -1182,7 +1184,7 @@ A helper function that creates an `RGXWalker` instance from an interpolation of
|
|
|
1182
1184
|
#### Parameters
|
|
1183
1185
|
- `source` (`string`): An arbitrary string value that will be included in the `source` property of the walker object.
|
|
1184
1186
|
- `options` (`RGXWOptions<R>`, optional): Additional options for configuring the behavior of the resulting `RGXWalker`. This includes:
|
|
1185
|
-
- `multiline` (`boolean`, optional): Whether to strip newlines and trim leading whitespace from the literal string parts of the template. Defaults to `true`. When `true`, each literal string part is split by newlines, each line has its leading whitespace trimmed, empty lines are removed, and the remaining lines are joined together. Interpolated tokens (including string tokens via `${"..."}`) are not affected. When `false`, literal string parts are preserved exactly as written.
|
|
1187
|
+
- `multiline` (`boolean`, optional): Whether to strip newlines and trim leading whitespace from the literal string parts of the template. Defaults to `true`. When `true`, each literal string part is split by newlines, each line has its leading whitespace trimmed, empty lines are removed, comments (denoted with `//`) ending a line or on a line by themselves are stripped, and the remaining lines are joined together. Interpolated tokens (including string tokens via `${"..."}`) are not affected. When `false`, literal string parts are preserved exactly as written.
|
|
1186
1188
|
- `reduced` (`R`, optional): An optional initial value for the walker's `reduced` property, which can be used to accumulate results across matches.
|
|
1187
1189
|
|
|
1188
1190
|
#### Returns
|
|
@@ -1643,7 +1645,9 @@ Since these are defined as native tokens (strings), they are automatically wrapp
|
|
|
1643
1645
|
| --- | --- | --- |
|
|
1644
1646
|
| `"any"` | `.` | Matches any single character (except newline by default) |
|
|
1645
1647
|
| `"start"` | `^` | Start of string anchor |
|
|
1648
|
+
| `"line-start"` | `^` (with `m` flag) | Start of line anchor |
|
|
1646
1649
|
| `"end"` | `$` | End of string anchor |
|
|
1650
|
+
| `"line-end"` | `$` (with `m` flag) | End of line anchor |
|
|
1647
1651
|
| `"word-bound"` | `\b` | Word boundary |
|
|
1648
1652
|
| `"non-word-bound"` | `\B` | Non-word boundary |
|
|
1649
1653
|
| `"word-bound-start"` | `(?<=\W)(?=\w)` | Start of a word |
|
|
@@ -15,8 +15,22 @@ function taggedTemplateToArray(strings, tokens, multiline) {
|
|
|
15
15
|
array.push(string);
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
// Remove all empty lines and trim whitespace from the start of each line.
|
|
19
|
-
let lines = string
|
|
18
|
+
// Remove all empty lines, remove comments, and trim whitespace from the start of each line.
|
|
19
|
+
let lines = string
|
|
20
|
+
.split("\n")
|
|
21
|
+
.map(line => line.trimStart())
|
|
22
|
+
// Remove comments both for the start of the line.
|
|
23
|
+
.filter(line => !line.startsWith("//"))
|
|
24
|
+
.filter(line => line.length > 0)
|
|
25
|
+
// Remove comments at the end of the line.
|
|
26
|
+
.map(line => {
|
|
27
|
+
const commentIndex = line.indexOf("//");
|
|
28
|
+
if (commentIndex !== -1) {
|
|
29
|
+
return line.substring(0, commentIndex).trimEnd();
|
|
30
|
+
}
|
|
31
|
+
return line;
|
|
32
|
+
})
|
|
33
|
+
.join("");
|
|
20
34
|
array.push(lines);
|
|
21
35
|
}
|
|
22
36
|
}
|