@ptolemy2002/rgx 5.2.0 → 5.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 CHANGED
@@ -54,7 +54,7 @@ type RGXTokenFromType<T extends RGXTokenTypeGuardInput> =
54
54
  // ... see source for full definition
55
55
  ;
56
56
 
57
- type RGXErrorCode = 'UNKNOWN' | 'INVALID_RGX_TOKEN' | 'INVALID_REGEX_STRING' | 'INVALID_REGEX_FLAGS' | 'INVALID_VANILLA_REGEX_FLAGS' | 'NOT_IMPLEMENTED' | 'NOT_SUPPORTED' | 'INVALID_IDENTIFIER' | 'OUT_OF_BOUNDS' | 'INVALID_FLAG_TRANSFORMER_KEY' | 'FLAG_TRANSFORMER_CONFLICT' | 'INSERTION_REJECTED';
57
+ type RGXErrorCode = 'UNKNOWN' | 'INVALID_RGX_TOKEN' | 'INVALID_REGEX_STRING' | 'INVALID_REGEX_FLAGS' | 'INVALID_VANILLA_REGEX_FLAGS' | 'NOT_IMPLEMENTED' | 'NOT_SUPPORTED' | 'INVALID_IDENTIFIER' | 'OUT_OF_BOUNDS' | 'INVALID_FLAG_TRANSFORMER_KEY' | 'FLAG_TRANSFORMER_CONFLICT' | 'CONSTANT_CONFLICT' | 'INVALID_CONSTANT_KEY' | 'INSERTION_REJECTED';
58
58
 
59
59
  type RangeObject = {
60
60
  min?: number | null;
@@ -218,6 +218,32 @@ constructor(message: string, got: string)
218
218
  #### Properties
219
219
  - `got` (`string`): The conflicting key string.
220
220
 
221
+ ### RGXInvalidConstantKeyError extends RGXError
222
+ A specific error class for invalid constant keys. This error is thrown when attempting to access or assert an RGX constant with a name that does not exist. The error code is set to `INVALID_CONSTANT_KEY` on instantiation.
223
+
224
+ #### Constructor
225
+ ```typescript
226
+ constructor(message: string, got: string)
227
+ ```
228
+ - `message` (`string`): The error message.
229
+ - `got` (`string`): The constant name that was not found.
230
+
231
+ #### Properties
232
+ - `got` (`string`): The constant name that was not found.
233
+
234
+ ### RGXConstantConflictError extends RGXError
235
+ A specific error class for constant name conflicts. This error is thrown when attempting to define an RGX constant with a name that is already in use. The error code is set to `CONSTANT_CONFLICT` on instantiation.
236
+
237
+ #### Constructor
238
+ ```typescript
239
+ constructor(message: string, got: string)
240
+ ```
241
+ - `message` (`string`): The error message.
242
+ - `got` (`string`): The conflicting constant name.
243
+
244
+ #### Properties
245
+ - `got` (`string`): The conflicting constant name.
246
+
221
247
  ### RGXInsertionRejectedError extends RGXError
222
248
  A specific error class for token insertion rejection. This error is thrown when a convertible token's `rgxAcceptInsertion` method returns `false` or a string (rejection reason) during pattern construction via `rgx`, `rgxa`, or `rgxConcat`. The error code is set to `INSERTION_REJECTED` on instantiation.
223
249
 
@@ -305,7 +331,7 @@ An abstract base class for creating custom RGX token classes. Subclasses must im
305
331
  #### Methods
306
332
  - `rgxAcceptInsertion(tokens: RGXToken[], flags: ValidRegexFlags) => string | boolean`: Called during pattern construction (via `rgx`, `rgxa`, or `rgxConcat`) to allow the token to reject its own insertion based on the surrounding tokens and the pattern's flags. Returns `true` to accept insertion (the default), `false` to reject with no reason, or a string to reject with a reason message. When a token rejects insertion, an `RGXInsertionRejectedError` is thrown. Subclasses can override this to enforce constraints such as requiring certain flags to be present.
307
333
  - `or(...others: RGXTokenCollectionInput[]) => RGXClassUnionToken`: Creates an `RGXClassUnionToken` that represents a union (alternation) of this token with the provided others. If any of the `others` are `RGXClassUnionToken` instances, their tokens are flattened into the union rather than nested. If `this` is already an `RGXClassUnionToken`, its existing tokens are preserved and the others are appended.
308
- - `group(args?: RGXGroupTokenArgs) => RGXGroupToken`: Wraps this token in an `RGXGroupToken` with the provided arguments. The `args` parameter defaults to `{}`, which creates a capturing group with no name. This is a convenience method that creates a new `RGXGroupToken` with `this` as the sole token.
334
+ - `group(args?: RGXGroupTokenArgs, ...others: RGXTokenCollectionInput[]) => RGXGroupToken`: Wraps this token in an `RGXGroupToken` with the provided arguments. The `args` parameter defaults to `{}`, which creates a capturing group with no name. Any additional `others` are included in the group alongside `this`. This is a convenience method that creates a new `RGXGroupToken` with `this` and the `others` as the tokens.
309
335
  - `repeat(min?: number, max?: number | null, lazy?: boolean) => RGXRepeatToken`: Wraps this token in an `RGXRepeatToken` with the given repetition bounds. `min` defaults to `1`, `max` defaults to `min`, `lazy` defaults to `false`. Pass `null` for `max` to allow unlimited repetitions. When `lazy` is `true`, the resulting quantifier will be non-greedy. This is a convenience method that creates a new `RGXRepeatToken` with `this` as the token. Throws `RGXNotSupportedError` if called on a token with `rgxIsRepeatable` set to `false` (e.g., `RGXLookaroundToken`).
310
336
  - `optional(lazy?: boolean) => RGXRepeatToken`: Shorthand for `repeat(0, 1, lazy)`. Wraps this token in an `RGXRepeatToken` that matches the token zero or one times. `lazy` defaults to `false`. Throws `RGXNotSupportedError` if called on a token with `rgxIsRepeatable` set to `false` (e.g., `RGXLookaroundToken`).
311
337
  - `asLookahead(positive?: boolean) => RGXLookaheadToken`: Wraps this token in an `RGXLookaheadToken`. `positive` defaults to `true`. If this token is already an `RGXLookaheadToken`, it is returned as-is without re-wrapping.
@@ -912,7 +938,7 @@ For convertible tokens, if the token has an `rgxGroupWrap` property, that value
912
938
  function rgxConcat(tokens: RGXToken[], groupWrap?: boolean, currentFlags?: string): ValidRegexString
913
939
  ```
914
940
 
915
- A helper function that resolves an array of RGX tokens and concatenates their resolved string representations together. This is useful for cases where you want to concatenate multiple tokens without creating a union between them. Before returning, any convertible token in the array that defines `rgxAcceptInsertion` is checked; if it returns `false` or a string, an `RGXInsertionRejectedError` is thrown.
941
+ A helper function that resolves an array of RGX tokens and concatenates their resolved string representations together. This is useful for cases where you want to concatenate multiple tokens without creating a union between them. Before returning, any convertible token in the array 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.
916
942
 
917
943
  #### Parameters
918
944
  - `tokens` (`RGXToken[]`): The array of RGX tokens to resolve and concatenate.
@@ -927,7 +953,7 @@ A helper function that resolves an array of RGX tokens and concatenates their re
927
953
  function rgx(flags?: string): (strings: TemplateStringsArray, ...tokens: RGXToken[]) => ExtRegExp
928
954
  ```
929
955
 
930
- 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.
956
+ 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.
931
957
 
932
958
  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)`.
933
959
 
@@ -962,7 +988,7 @@ const pattern4 = rgx()`${beginning}${caseInsensitiveWord} world${end}`; // /^(?i
962
988
  ```typescript
963
989
  function rgxa(tokens: RGXToken[], flags?: string): ExtRegExp
964
990
  ```
965
- As an alternative to using the `rgx` template tag, you can directly call `rgxa` with an array of RGX tokens and optional flags to get an `ExtRegExp` object. This is useful in cases where you don't want to use a template literal. Like `rgx`, the provided `flags` are passed as `currentFlags` to the resolver, enabling inline modifier groups for `RegExp` literal tokens whose localizable flags differ. Before constructing the pattern, any convertible token in the array that defines `rgxAcceptInsertion` is checked; if it returns `false` or a string, an `RGXInsertionRejectedError` is thrown.
991
+ As an alternative to using the `rgx` template tag, you can directly call `rgxa` with an array of RGX tokens and optional flags to get an `ExtRegExp` object. This is useful in cases where you don't want to use a template literal. Like `rgx`, the provided `flags` are passed as `currentFlags` to the resolver, enabling inline modifier groups for `RegExp` literal tokens whose localizable flags differ. Before constructing the pattern, any convertible token in the array 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.
966
992
 
967
993
  #### Parameters
968
994
  - `tokens` (`RGXToken[]`): The RGX tokens to be resolved and concatenated to form the regex pattern.
@@ -1270,6 +1296,140 @@ Creates a clone of the given RGX token to the given depth, provided that the tok
1270
1296
  #### Returns
1271
1297
  - `T`: The cloned token.
1272
1298
 
1299
+ ### listRGXConstants
1300
+ ```typescript
1301
+ function listRGXConstants(): string[]
1302
+ ```
1303
+
1304
+ Returns the names of all currently defined RGX constants.
1305
+
1306
+ #### Returns
1307
+ - `string[]`: An array of constant names.
1308
+
1309
+ ### hasRGXConstant
1310
+ ```typescript
1311
+ function hasRGXConstant(name: string): boolean
1312
+ ```
1313
+
1314
+ Checks if an RGX constant with the given name exists.
1315
+
1316
+ #### Parameters
1317
+ - `name` (`string`): The constant name to check.
1318
+
1319
+ #### Returns
1320
+ - `boolean`: `true` if the constant exists, otherwise `false`.
1321
+
1322
+ ### assertHasRGXConstant
1323
+ ```typescript
1324
+ function assertHasRGXConstant(name: string): void
1325
+ ```
1326
+
1327
+ Asserts that an RGX constant with the given name exists. If the assertion fails, an `RGXInvalidConstantKeyError` will be thrown.
1328
+
1329
+ #### Parameters
1330
+ - `name` (`string`): The constant name to assert.
1331
+
1332
+ #### Returns
1333
+ - `void`: This function does not return a value, but will throw an error if the assertion fails.
1334
+
1335
+ ### assertNotHasRGXConstant
1336
+ ```typescript
1337
+ function assertNotHasRGXConstant(name: string): void
1338
+ ```
1339
+
1340
+ Asserts that an RGX constant with the given name does not exist. If the assertion fails, an `RGXConstantConflictError` will be thrown.
1341
+
1342
+ #### Parameters
1343
+ - `name` (`string`): The constant name to assert.
1344
+
1345
+ #### Returns
1346
+ - `void`: This function does not return a value, but will throw an error if the assertion fails.
1347
+
1348
+ ### defineRGXConstant
1349
+ ```typescript
1350
+ function defineRGXConstant(name: string, value: RGXToken): RGXToken
1351
+ ```
1352
+
1353
+ Defines a new RGX constant with the given name and value. Throws an `RGXConstantConflictError` if a constant with the same name already exists.
1354
+
1355
+ #### Parameters
1356
+ - `name` (`string`): The name for the constant.
1357
+ - `value` (`RGXToken`): The token value to associate with the name.
1358
+
1359
+ #### Returns
1360
+ - `RGXToken`: The value that was defined.
1361
+
1362
+ ### rgxConstant
1363
+ ```typescript
1364
+ function rgxConstant(name: string): RGXToken
1365
+ ```
1366
+
1367
+ Retrieves the value of an RGX constant by name. Throws an `RGXInvalidConstantKeyError` if no constant with the given name exists.
1368
+
1369
+ #### Parameters
1370
+ - `name` (`string`): The constant name to retrieve.
1371
+
1372
+ #### Returns
1373
+ - `RGXToken`: The token value associated with the constant name.
1374
+
1375
+ ### deleteRGXConstant
1376
+ ```typescript
1377
+ function deleteRGXConstant(name: string): void
1378
+ ```
1379
+
1380
+ Deletes an existing RGX constant by name. Throws an `RGXInvalidConstantKeyError` if no constant with the given name exists.
1381
+
1382
+ #### Parameters
1383
+ - `name` (`string`): The constant name to delete.
1384
+
1385
+ #### Returns
1386
+ - `void`: This function does not return a value, but will throw an error if the constant does not exist.
1387
+
1388
+ ## Built-in Constants
1389
+ The library defines the following built-in constants, which are available immediately after import. Each can be retrieved via `rgxConstant(name)`.
1390
+
1391
+ ### Control Characters
1392
+ | Name | Resolves To | Description |
1393
+ | --- | --- | --- |
1394
+ | `"newline"` | `\n` | Newline character |
1395
+ | `"carriage-return"` | `\r` | Carriage return character |
1396
+ | `"tab"` | `\t` | Tab character |
1397
+ | `"null"` | `\0` | Null character |
1398
+ | `"form-feed"` | `\f` | Form feed character |
1399
+
1400
+ ### Special Characters
1401
+ | Name | Resolves To | Description |
1402
+ | --- | --- | --- |
1403
+ | `"any"` | `.` | Matches any single character (except newline by default) |
1404
+ | `"start"` | `^` | Start of string anchor |
1405
+ | `"end"` | `$` | End of string anchor |
1406
+ | `"word-bound"` | `\b` | Word boundary |
1407
+ | `"non-word-bound"` | `\B` | Non-word boundary |
1408
+ | `"word-bound-start"` | `(?<=\W)(?=\w)` | Start of a word |
1409
+ | `"word-bound-end"` | `(?<=\w)(?=\W)` | End of a word |
1410
+
1411
+ ### Character Sets
1412
+ | Name | Resolves To | Description |
1413
+ | --- | --- | --- |
1414
+ | `"letter"` | `[a-zA-Z]` | Any letter (uppercase or lowercase) |
1415
+ | `"lowercase-letter"` | `[a-z]` | Any lowercase letter |
1416
+ | `"uppercase-letter"` | `[A-Z]` | Any uppercase letter |
1417
+ | `"non-letter"` | `[^a-zA-Z]` | Any character that is not a letter |
1418
+ | `"alphanumeric"` | `[a-zA-Z0-9]` | Any letter or digit |
1419
+ | `"non-alphanumeric"` | `[^a-zA-Z0-9]` | Any character that is not a letter or digit |
1420
+
1421
+ ### Predefined Character Sets
1422
+ | Name | Resolves To | Description |
1423
+ | --- | --- | --- |
1424
+ | `"digit"` | `\d` | Any digit |
1425
+ | `"non-digit"` | `\D` | Any non-digit |
1426
+ | `"whitespace"` | `\s` | Any whitespace character |
1427
+ | `"non-whitespace"` | `\S` | Any non-whitespace character |
1428
+ | `"vertical-whitespace"` | `\v` | Vertical whitespace character |
1429
+ | `"word-char"` | `\w` | Any word character (letter, digit, or underscore) |
1430
+ | `"non-word-char"` | `\W` | Any non-word character |
1431
+ | `"backspace"` | `[\b]` | Backspace character |
1432
+
1273
1433
  ## Peer Dependencies
1274
1434
  - `@ptolemy2002/immutability-utils` ^2.0.0
1275
1435
  - `@ptolemy2002/js-utils` ^3.2.2
@@ -16,7 +16,7 @@ export declare abstract class RGXClassToken implements RGXConvertibleToken {
16
16
  get rgxIsRepeatable(): boolean;
17
17
  get rgxGroupWrap(): boolean;
18
18
  or(...others: RGXTokenCollectionInput[]): RGXClassUnionToken;
19
- group(args?: RGXGroupTokenArgs): RGXGroupToken;
19
+ group(args?: RGXGroupTokenArgs, ...others: RGXTokenCollectionInput[]): RGXGroupToken;
20
20
  repeat(min?: number, max?: number | null, lazy?: boolean): RGXRepeatToken;
21
21
  optional(lazy?: boolean): RGXRepeatToken;
22
22
  asLookahead(positive?: boolean): RGXLookaheadToken;
@@ -19,7 +19,7 @@ class RGXClassToken {
19
19
  or(...others) {
20
20
  throw new errors_1.RGXNotImplementedError('RGXClassToken.or(...others)', 'call rgxClassInit() first.');
21
21
  }
22
- group(args = {}) {
22
+ group(args = {}, ...others) {
23
23
  throw new errors_1.RGXNotImplementedError('RGXClassToken.group(args)', 'call rgxClassInit() first.');
24
24
  }
25
25
  repeat(min = 1, max = min, lazy = false) {
@@ -25,8 +25,8 @@ function rgxClassInit() {
25
25
  return new union_1.RGXClassUnionToken([this, ...filteredOthers]);
26
26
  }
27
27
  };
28
- base_1.RGXClassToken.prototype.group = function (args = {}) {
29
- return new group_1.RGXGroupToken(args, [this]);
28
+ base_1.RGXClassToken.prototype.group = function (args = {}, ...others) {
29
+ return new group_1.RGXGroupToken(args, [this, ...others]);
30
30
  };
31
31
  base_1.RGXClassToken.prototype.repeat = function (min = 1, max = min, lazy = false) {
32
32
  if (lookaround_1.RGXLookaroundToken.check(this))
@@ -0,0 +1,8 @@
1
+ import { RGXToken } from "./types";
2
+ export declare function listRGXConstants(): string[];
3
+ export declare function hasRGXConstant(name: string): boolean;
4
+ export declare function assertHasRGXConstant(name: string): void;
5
+ export declare function assertNotHasRGXConstant(name: string): void;
6
+ export declare function defineRGXConstant(name: string, value: RGXToken): RGXToken;
7
+ export declare function rgxConstant(name: string): RGXToken;
8
+ export declare function deleteRGXConstant(name: string): void;
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listRGXConstants = listRGXConstants;
4
+ exports.hasRGXConstant = hasRGXConstant;
5
+ exports.assertHasRGXConstant = assertHasRGXConstant;
6
+ exports.assertNotHasRGXConstant = assertNotHasRGXConstant;
7
+ exports.defineRGXConstant = defineRGXConstant;
8
+ exports.rgxConstant = rgxConstant;
9
+ exports.deleteRGXConstant = deleteRGXConstant;
10
+ const errors_1 = require("./errors");
11
+ const rgxConstants = {};
12
+ function listRGXConstants() {
13
+ return Object.keys(rgxConstants);
14
+ }
15
+ function hasRGXConstant(name) {
16
+ return name in rgxConstants;
17
+ }
18
+ function assertHasRGXConstant(name) {
19
+ if (!hasRGXConstant(name)) {
20
+ throw new errors_1.RGXInvalidConstantKeyError("Constant with name not found.", name);
21
+ }
22
+ }
23
+ function assertNotHasRGXConstant(name) {
24
+ if (hasRGXConstant(name)) {
25
+ throw new errors_1.RGXConstantConflictError("Constant with name already defined.", name);
26
+ }
27
+ }
28
+ function defineRGXConstant(name, value) {
29
+ assertNotHasRGXConstant(name);
30
+ rgxConstants[name] = value;
31
+ return value;
32
+ }
33
+ function rgxConstant(name) {
34
+ assertHasRGXConstant(name);
35
+ return rgxConstants[name];
36
+ }
37
+ function deleteRGXConstant(name) {
38
+ assertHasRGXConstant(name);
39
+ delete rgxConstants[name];
40
+ }
41
+ // Control Characters
42
+ defineRGXConstant("newline", "\n");
43
+ defineRGXConstant("carriage-return", "\r");
44
+ defineRGXConstant("tab", "\t");
45
+ defineRGXConstant("null", "\0");
46
+ defineRGXConstant("form-feed", "\f");
47
+ // Special Characters
48
+ defineRGXConstant("any", {
49
+ rgxGroupWrap: false,
50
+ toRgx() {
51
+ return /./;
52
+ }
53
+ });
54
+ defineRGXConstant("start", {
55
+ rgxGroupWrap: false,
56
+ toRgx() {
57
+ return /^/;
58
+ }
59
+ });
60
+ defineRGXConstant("end", {
61
+ rgxGroupWrap: false,
62
+ toRgx() {
63
+ return /$/;
64
+ }
65
+ });
66
+ defineRGXConstant("word-bound", {
67
+ rgxGroupWrap: false,
68
+ toRgx() {
69
+ return /\b/;
70
+ }
71
+ });
72
+ defineRGXConstant("non-word-bound", {
73
+ rgxGroupWrap: false,
74
+ toRgx() {
75
+ return /\B/;
76
+ }
77
+ });
78
+ defineRGXConstant("word-bound-start", {
79
+ rgxGroupWrap: false,
80
+ toRgx() {
81
+ // Make sure there is a non-word character before and a word character after
82
+ return /(?<=\W)(?=\w)/;
83
+ }
84
+ });
85
+ defineRGXConstant("word-bound-end", {
86
+ rgxGroupWrap: false,
87
+ toRgx() {
88
+ // Make sure there is a word character before and a non-word character after
89
+ return /(?<=\w)(?=\W)/;
90
+ }
91
+ });
92
+ // Character Sets
93
+ defineRGXConstant("letter", {
94
+ rgxIsGroup: true,
95
+ rgxGroupWrap: false,
96
+ toRgx() {
97
+ return /[a-zA-Z]/;
98
+ }
99
+ });
100
+ defineRGXConstant("lowercase-letter", {
101
+ rgxIsGroup: true,
102
+ rgxGroupWrap: false,
103
+ toRgx() {
104
+ return /[a-z]/;
105
+ }
106
+ });
107
+ defineRGXConstant("uppercase-letter", {
108
+ rgxIsGroup: true,
109
+ rgxGroupWrap: false,
110
+ toRgx() {
111
+ return /[A-Z]/;
112
+ }
113
+ });
114
+ defineRGXConstant("non-letter", {
115
+ rgxIsGroup: true,
116
+ rgxGroupWrap: false,
117
+ toRgx() {
118
+ return /[^a-zA-Z]/;
119
+ }
120
+ });
121
+ defineRGXConstant("alphanumeric", {
122
+ rgxIsGroup: true,
123
+ rgxGroupWrap: false,
124
+ toRgx() {
125
+ return /[a-zA-Z0-9]/;
126
+ }
127
+ });
128
+ defineRGXConstant("non-alphanumeric", {
129
+ rgxIsGroup: true,
130
+ rgxGroupWrap: false,
131
+ toRgx() {
132
+ return /[^a-zA-Z0-9]/;
133
+ }
134
+ });
135
+ // Predefined Character Sets
136
+ defineRGXConstant("digit", {
137
+ rgxGroupWrap: false,
138
+ toRgx() {
139
+ return /\d/;
140
+ }
141
+ });
142
+ defineRGXConstant("non-digit", {
143
+ rgxGroupWrap: false,
144
+ toRgx() {
145
+ return /\D/;
146
+ }
147
+ });
148
+ defineRGXConstant("whitespace", {
149
+ rgxGroupWrap: false,
150
+ toRgx() {
151
+ return /\s/;
152
+ }
153
+ });
154
+ defineRGXConstant("non-whitespace", {
155
+ rgxGroupWrap: false,
156
+ toRgx() {
157
+ return /\S/;
158
+ }
159
+ });
160
+ defineRGXConstant("vertical-whitespace", {
161
+ rgxGroupWrap: false,
162
+ toRgx() {
163
+ return /\v/;
164
+ }
165
+ });
166
+ defineRGXConstant("word-char", {
167
+ rgxGroupWrap: false,
168
+ toRgx() {
169
+ return /\w/;
170
+ }
171
+ });
172
+ defineRGXConstant("non-word-char", {
173
+ rgxGroupWrap: false,
174
+ toRgx() {
175
+ return /\W/;
176
+ }
177
+ });
178
+ defineRGXConstant("backspace", {
179
+ rgxIsGroup: true,
180
+ rgxGroupWrap: false,
181
+ toRgx() {
182
+ return /[\b]/;
183
+ }
184
+ });
@@ -1,4 +1,4 @@
1
- export type RGXErrorCode = 'UNKNOWN' | 'INVALID_RGX_TOKEN' | 'INVALID_REGEX_STRING' | 'INVALID_REGEX_FLAGS' | 'INVALID_VANILLA_REGEX_FLAGS' | 'NOT_IMPLEMENTED' | 'NOT_SUPPORTED' | 'INVALID_IDENTIFIER' | 'OUT_OF_BOUNDS' | 'INVALID_FLAG_TRANSFORMER_KEY' | 'FLAG_TRANSFORMER_CONFLICT' | 'INSERTION_REJECTED';
1
+ export type RGXErrorCode = 'UNKNOWN' | 'INVALID_RGX_TOKEN' | 'INVALID_REGEX_STRING' | 'INVALID_REGEX_FLAGS' | 'INVALID_VANILLA_REGEX_FLAGS' | 'NOT_IMPLEMENTED' | 'NOT_SUPPORTED' | 'INVALID_IDENTIFIER' | 'OUT_OF_BOUNDS' | 'INVALID_FLAG_TRANSFORMER_KEY' | 'FLAG_TRANSFORMER_CONFLICT' | 'CONSTANT_CONFLICT' | 'INVALID_CONSTANT_KEY' | 'INSERTION_REJECTED';
2
2
  export declare class RGXError extends Error {
3
3
  _message: string;
4
4
  code: RGXErrorCode;
@@ -0,0 +1,6 @@
1
+ import { RGXError } from "./";
2
+ export declare class RGXConstantConflictError extends RGXError {
3
+ got: string;
4
+ constructor(message: string, got: string);
5
+ calcMessage(message: string): string;
6
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RGXConstantConflictError = void 0;
4
+ const errors_1 = require("./");
5
+ class RGXConstantConflictError extends errors_1.RGXError {
6
+ constructor(message, got) {
7
+ super(message, 'CONSTANT_CONFLICT');
8
+ this.name = 'RGXConstantConflictError';
9
+ this.got = got;
10
+ }
11
+ calcMessage(message) {
12
+ return `${message}; Got: ${JSON.stringify(this.got)}`;
13
+ }
14
+ }
15
+ exports.RGXConstantConflictError = RGXConstantConflictError;
@@ -10,3 +10,5 @@ export * from './invalidFlagTransformerKey';
10
10
  export * from './flagTransformerConflict';
11
11
  export * from './notSupported';
12
12
  export * from './insertionRejected';
13
+ export * from './constantConflict';
14
+ export * from './invalidConstantKey';
@@ -26,3 +26,5 @@ __exportStar(require("./invalidFlagTransformerKey"), exports);
26
26
  __exportStar(require("./flagTransformerConflict"), exports);
27
27
  __exportStar(require("./notSupported"), exports);
28
28
  __exportStar(require("./insertionRejected"), exports);
29
+ __exportStar(require("./constantConflict"), exports);
30
+ __exportStar(require("./invalidConstantKey"), exports);
@@ -0,0 +1,6 @@
1
+ import { RGXError } from "./";
2
+ export declare class RGXInvalidConstantKeyError extends RGXError {
3
+ got: string;
4
+ constructor(message: string, got: string);
5
+ calcMessage(message: string): string;
6
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RGXInvalidConstantKeyError = void 0;
4
+ const errors_1 = require("./");
5
+ class RGXInvalidConstantKeyError extends errors_1.RGXError {
6
+ constructor(message, got) {
7
+ super(message, 'INVALID_CONSTANT_KEY');
8
+ this.name = 'RGXInvalidConstantKeyError';
9
+ this.got = got;
10
+ }
11
+ calcMessage(message) {
12
+ return `${message}; Got: ${JSON.stringify(this.got)}`;
13
+ }
14
+ }
15
+ exports.RGXInvalidConstantKeyError = RGXInvalidConstantKeyError;
package/dist/index.d.ts CHANGED
@@ -11,5 +11,6 @@ export * from "./utils";
11
11
  export * from "./ExtRegExp";
12
12
  export * from "./flag-transformer";
13
13
  export * from "./clone";
14
+ export * from "./constants";
14
15
  export declare function rgxa(tokens: t.RGXToken[], flags?: string): ExtRegExp;
15
16
  export default function rgx(flags?: string): (strings: TemplateStringsArray, ...tokens: t.RGXToken[]) => ExtRegExp;
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ __exportStar(require("./utils"), exports);
32
32
  __exportStar(require("./ExtRegExp"), exports);
33
33
  __exportStar(require("./flag-transformer"), exports);
34
34
  __exportStar(require("./clone"), exports);
35
+ __exportStar(require("./constants"), exports);
35
36
  // Call this for certain class methods to work correctly
36
37
  (0, class_1.rgxClassInit)();
37
38
  // Call this for our custom flags to work correctly
@@ -1,17 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assureAcceptance = assureAcceptance;
4
+ const class_1 = require("../class");
4
5
  const errors_1 = require("../errors");
5
6
  const typeGuards_1 = require("../typeGuards");
6
7
  function assureAcceptance(tokens, flags) {
7
- for (const token of tokens) {
8
+ for (let i = 0; i < tokens.length; i++) {
9
+ const token = tokens[i];
8
10
  if ((0, typeGuards_1.isRGXConvertibleToken)(token) && token.rgxAcceptInsertion) {
9
11
  const messageOrAccepted = token.rgxAcceptInsertion(tokens, flags);
10
12
  if (messageOrAccepted === true)
11
13
  continue;
14
+ const extraMessage = `index ${i}, token type ${class_1.RGXClassToken.check(token) ? token.constructor.name : "unknown"}`;
12
15
  if (messageOrAccepted === false)
13
- throw new errors_1.RGXInsertionRejectedError();
14
- throw new errors_1.RGXInsertionRejectedError(messageOrAccepted);
16
+ throw new errors_1.RGXInsertionRejectedError(null, extraMessage);
17
+ throw new errors_1.RGXInsertionRejectedError(messageOrAccepted, extraMessage);
15
18
  }
16
19
  }
17
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/rgx",
3
- "version": "5.2.0",
3
+ "version": "5.4.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",