@ptolemy2002/rgx 4.6.1 → 4.7.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
@@ -10,7 +10,10 @@ type RGXLiteralToken = RegExp;
10
10
  type RGXNativeToken = string | number | boolean | RGXNoOpToken;
11
11
  type RGXConvertibleToken = { toRgx: () => RGXToken, readonly rgxGroupWrap?: boolean };
12
12
  type RGXToken = RGXNativeToken | RGXLiteralToken | RGXConvertibleToken | RGXToken[];
13
+
13
14
  type RGXClassTokenConstructor = new (...args: unknown[]) => RGXClassToken;
15
+ type RGXGroupedToken = RGXToken[] | RGXLiteralToken | (RGXClassToken & { isGroup: true }) | RGXGroupedConvertibleToken;
16
+ type RGXGroupedConvertibleToken = { toRgx: () => RGXGroupedToken, readonly rgxGroupWrap: true };
14
17
 
15
18
  const validRegexSymbol = Symbol('rgx.ValidRegex');
16
19
  type ValidRegexBrandSymbol = typeof validRegexSymbol;
@@ -83,6 +86,9 @@ constructor(message: string, code?: RGXErrorCode)
83
86
  #### Properties
84
87
  - `code` (`RGXErrorCode`): The error code associated with the error, which can be used to identify the type of error that occurred.
85
88
 
89
+ #### Methods
90
+ - `toString() => string`: Returns a formatted string in the format `${name}: ${message}`. Subclasses customize the message portion via internal formatting rather than overriding `toString()` directly, so all `RGXError` subclasses produce consistently formatted strings through this single method.
91
+
86
92
  ### RGXInvalidTokenError extends RGXError
87
93
  A specific error class for invalid RGX tokens. This error is thrown when a value fails validation as a specific RGX token type. The error code is set to `INVALID_RGX_TOKEN` on instantiation.
88
94
 
@@ -137,9 +143,6 @@ constructor(functionality: string, message?: string | null)
137
143
  #### Properties
138
144
  - `functionality` (`string`): The description of the unimplemented functionality.
139
145
 
140
- #### Methods
141
- - `toString() => string`: Returns a formatted string indicating the unimplemented functionality and any additional message.
142
-
143
146
  ### RGXInvalidIdentifierError extends RGXError
144
147
  A specific error class for invalid identifiers. This error is thrown when a string fails validation as a valid identifier. The error code is set to `INVALID_IDENTIFIER` on instantiation.
145
148
 
@@ -153,9 +156,6 @@ constructor(message: string, got: string)
153
156
  #### Properties
154
157
  - `got` (`string`): The actual string that was received, which failed validation.
155
158
 
156
- #### Methods
157
- - `toString() => string`: Returns a formatted string indicating the invalid identifier and the reason for failure.
158
-
159
159
  ### RGXInvalidRegexFlagsError extends RGXError
160
160
  A specific error class for invalid regex flags (including both vanilla and custom registered flags). This error is thrown when a string fails validation as valid regex flags. The error code is set to `INVALID_REGEX_FLAGS` on instantiation.
161
161
 
@@ -169,9 +169,6 @@ constructor(message: string, got: string)
169
169
  #### Properties
170
170
  - `got` (`string`): The actual string that was received, which failed validation.
171
171
 
172
- #### Methods
173
- - `toString() => string`: Returns a formatted string indicating the invalid flags and the reason for failure.
174
-
175
172
  ### RGXInvalidFlagTransformerKeyError extends RGXError
176
173
  A specific error class for invalid flag transformer keys. This error is thrown when an invalid key is provided to `registerFlagTransformer` (e.g., a key that is not a single character). The error code is set to `INVALID_FLAG_TRANSFORMER_KEY` on instantiation.
177
174
 
@@ -185,9 +182,6 @@ constructor(message: string, got: string)
185
182
  #### Properties
186
183
  - `got` (`string`): The actual key string that was received, which failed validation.
187
184
 
188
- #### Methods
189
- - `toString() => string`: Returns a formatted string indicating the invalid key and the reason for failure.
190
-
191
185
  ### RGXFlagTransformerConflictError extends RGXError
192
186
  A specific error class for flag transformer conflicts. This error is thrown when attempting to register a flag transformer with a key that conflicts with an existing vanilla regex flag or an already-registered transformer. The error code is set to `FLAG_TRANSFORMER_CONFLICT` on instantiation.
193
187
 
@@ -201,9 +195,6 @@ constructor(message: string, got: string)
201
195
  #### Properties
202
196
  - `got` (`string`): The conflicting key string.
203
197
 
204
- #### Methods
205
- - `toString() => string`: Returns a formatted string indicating the conflict and the reason for failure.
206
-
207
198
  ### RGXOutOfBoundsError extends RGXError
208
199
  A specific error class for out-of-bounds values. This error is thrown when a numeric value falls outside an expected range. The error code is set to `OUT_OF_BOUNDS` on instantiation.
209
200
 
@@ -229,7 +220,6 @@ constructor(message: string, got: number, { min, max, inclusiveLeft, inclusiveRi
229
220
  - `failedAtMin() => boolean`: Returns `true` if the `got` value is below the minimum bound (respecting `inclusiveLeft`), otherwise `false`. Returns `false` if `min` is `null`.
230
221
  - `failedAtMax() => boolean`: Returns `true` if the `got` value is above the maximum bound (respecting `inclusiveRight`), otherwise `false`. Returns `false` if `max` is `null`.
231
222
  - `failedAtAny() => boolean`: Returns `true` if the value failed at either the minimum or maximum bound.
232
- - `toString() => string`: Returns a formatted string indicating the out-of-bounds value, the expected range, and which bound was violated.
233
223
 
234
224
  ### RGXTokenCollection
235
225
  A class representing a collection of RGX tokens. This class manages collections of RGX tokens like an array, but with additional metadata about the collection mode (union or concat). Since `toRgx()` returns a `RegExp`, instances of this class satisfy the `RGXConvertibleToken` interface and can be used directly as tokens in `rgx`, `rgxa`, and other token-accepting functions.
@@ -326,8 +316,8 @@ constructor(args?: RGXGroupTokenArgs, tokens?: RGXTokenCollectionInput)
326
316
  - `tokens` (`RGXTokenCollection`): The internal collection of tokens managed in 'concat' mode.
327
317
  - `name` (`string | null`): The name of the group. Setting this to a non-null value validates it as a valid identifier via `assertValidIdentifier`.
328
318
  - `capturing` (`boolean`): Whether the group is capturing. Any named group is automatically capturing (returns `true` when `name` is not `null`). Setting this to `false` also clears `name` to `null`.
329
- - `isGroup` (`boolean`): Returns `true`, indicating this token represents a group.
330
- - `rgxGroupWrap` (`boolean`): Returns `false`, since the group already wraps itself, preventing the resolver from double-wrapping.
319
+ - `isGroup` (`true`): Returns `true` as a constant, indicating this token represents a group.
320
+ - `rgxGroupWrap` (`false`): Returns `false` as a constant, since the group already wraps itself, preventing the resolver from double-wrapping.
331
321
 
332
322
  #### Methods
333
323
  - `toRgx() => RegExp`: Resolves the group by concatenating the internal tokens and wrapping the result in the appropriate group syntax: `(?<name>...)` for named groups, `(?:...)` for non-capturing groups, or `(...)` for capturing groups.
@@ -345,16 +335,16 @@ A function `rgxRepeat` is provided with the same parameters as this class' const
345
335
  ```typescript
346
336
  constructor(token: RGXToken, min?: number, max?: number | null)
347
337
  ```
348
- - `token` (`RGXToken`): The token to repeat. If the token is not already a group (i.e., not an array, `RegExp`, or an `RGXClassToken` with `isGroup` set to `true`), it will be automatically wrapped in an `RGXGroupToken` that is non-capturing.
338
+ - `token` (`RGXToken`): The token to repeat. If the token is not already a grouped token, it will be automatically wrapped in a non-capturing `RGXGroupToken`.
349
339
  - `min` (`number`, optional): The minimum number of repetitions. Must be >= 0 and <= `max` (when `max` is not `null`). Non-integer values are floored. Defaults to `1`.
350
340
  - `max` (`number | null`, optional): The maximum number of repetitions. Must be >= `min` when not `null`. Non-integer values are floored. Pass `null` for unlimited repetitions. Defaults to `min`.
351
341
 
352
342
  #### Properties
353
- - `token` (`RGXToken`): The token being repeated. Setting this will automatically wrap non-group tokens in an `RGXGroupToken`.
343
+ - `token` (`RGXGroupedToken`): The token being repeated. Setting this will automatically wrap non-grouped tokens in a non-capturing `RGXGroupToken`.
354
344
  - `min` (`number`): The minimum number of repetitions. Setting this validates that the value is >= 0 and <= `max` (when `max` is not `null`), and floors non-integer values. Throws `RGXOutOfBoundsError` if validation fails.
355
345
  - `max` (`number | null`): The maximum number of repetitions. Setting this validates that the value is >= `min` when not `null`, and floors non-integer values. Pass `null` for unlimited. Throws `RGXOutOfBoundsError` if validation fails.
356
346
  - `repeaterSuffix` (`string`): Returns the regex quantifier suffix based on the current `min` and `max` values: `*` for `{0,}`, `+` for `{1,}`, `?` for `{0,1}`, `{n}` for exact repetitions, `{n,}` for minimum-only, `{n,m}` for a range, or an empty string for `{1,1}` (exactly once, no quantifier needed).
357
- - `rgxGroupWrap` (`boolean`): Returns `false`, since the quantifier suffix binds tightly to the preceding group and does not need additional wrapping.
347
+ - `rgxGroupWrap` (`false`): Returns `false` as a constant, since the quantifier suffix binds tightly to the preceding group and does not need additional wrapping.
358
348
 
359
349
  #### Methods
360
350
  - `toRgx() => RGXToken`: Resolves the repeat token to a `RegExp` by resolving the inner token and appending the `repeaterSuffix`. Returns `null` (a no-op) when both `min` and `max` are `0`.
@@ -639,6 +629,34 @@ Asserts that the given value is a valid RGX token, optionally narrowed to a spec
639
629
  #### Returns
640
630
  - `void`: This function does not return a value, but will throw an error if the assertion fails.
641
631
 
632
+ ### isRGXGroupedToken
633
+ ```typescript
634
+ function isRGXGroupedToken(value: unknown, contentCheck?: boolean): value is RGXGroupedToken
635
+ ```
636
+
637
+ Checks if the given value is a grouped token — a token that is implicitly or explicitly a group. Arrays and literal tokens (`RegExp`) are implicitly groups. Class tokens are only groups if they have the `isGroup` property set to `true`. Convertible tokens are groups if they have `rgxGroupWrap` set to `true` and their `toRgx()` method returns a grouped token.
638
+
639
+ #### Parameters
640
+ - `value` (`unknown`): The value to check.
641
+ - `contentCheck` (`boolean`, optional): Whether to validate the contents of array tokens and the return values of convertible tokens. Defaults to `true`. When `false`, arrays are accepted without checking their elements, and convertible tokens with `rgxGroupWrap` set to `true` are accepted without checking their `toRgx()` return value.
642
+
643
+ #### Returns
644
+ - `boolean`: `true` if the value is a grouped token, otherwise `false`.
645
+
646
+ ### assertRGXGroupedToken
647
+ ```typescript
648
+ function assertRGXGroupedToken(value: unknown, contentCheck?: boolean): asserts value is RGXGroupedToken
649
+ ```
650
+
651
+ Asserts that the given value is a grouped token. Uses the same logic as `isRGXGroupedToken`. If the assertion fails, an `RGXInvalidTokenError` will be thrown.
652
+
653
+ #### Parameters
654
+ - `value` (`unknown`): The value to assert.
655
+ - `contentCheck` (`boolean`, optional): Whether to validate the contents of array tokens and the return values of convertible tokens. Defaults to `true`. When `false`, arrays are accepted without checking their elements, and convertible tokens with `rgxGroupWrap` set to `true` are accepted without checking their `toRgx()` return value.
656
+
657
+ #### Returns
658
+ - `void`: This function does not return a value, but will throw an error if the assertion fails.
659
+
642
660
  ### isValidRegexString
643
661
  ```typescript
644
662
  function isValidRegexString(value: string): value is ValidRegexString
@@ -14,8 +14,8 @@ export declare class RGXGroupToken extends RGXClassToken {
14
14
  set name(value: string | null);
15
15
  get capturing(): boolean;
16
16
  set capturing(value: boolean);
17
- get isGroup(): boolean;
18
- get rgxGroupWrap(): boolean;
17
+ get isGroup(): true;
18
+ get rgxGroupWrap(): false;
19
19
  constructor({ name, capturing }?: RGXGroupTokenArgs, tokens?: RGXTokenCollectionInput);
20
20
  toRgx(): RegExp;
21
21
  }
@@ -1,7 +1,7 @@
1
- import { RGXToken } from "../types";
1
+ import { RGXGroupedToken, RGXToken } from "../types";
2
2
  import { RGXClassToken } from "./base";
3
3
  export declare class RGXRepeatToken extends RGXClassToken {
4
- _token: RGXToken;
4
+ _token: RGXGroupedToken;
5
5
  _min: number;
6
6
  _max: number | null;
7
7
  static check: (value: unknown) => value is RGXRepeatToken;
@@ -12,7 +12,7 @@ export declare class RGXRepeatToken extends RGXClassToken {
12
12
  set max(value: number | null);
13
13
  get token(): RGXToken;
14
14
  set token(value: RGXToken);
15
- get rgxGroupWrap(): boolean;
15
+ get rgxGroupWrap(): false;
16
16
  constructor(token: RGXToken, min?: number, max?: number | null);
17
17
  get repeaterSuffix(): string;
18
18
  toRgx(): RGXToken;
@@ -30,12 +30,8 @@ class RGXRepeatToken extends base_1.RGXClassToken {
30
30
  return this._token;
31
31
  }
32
32
  set token(value) {
33
- // Arrays and Literals are implicitly grouped.
34
- const isGroup = (0, typeGuards_1.isRGXToken)(value, "array") ||
35
- (0, typeGuards_1.isRGXToken)(value, "literal") ||
36
- ((0, typeGuards_1.isRGXToken)(value, "class") && value.isGroup);
37
- // Make sure we are always working with a group token.
38
- if (isGroup)
33
+ // Make sure we are always working with a grouped token.
34
+ if ((0, typeGuards_1.isRGXGroupedToken)(value))
39
35
  this._token = value;
40
36
  else
41
37
  this._token = new group_1.RGXGroupToken({ capturing: false }, value);
@@ -1,5 +1,10 @@
1
1
  export type RGXErrorCode = 'UNKNOWN' | 'INVALID_RGX_TOKEN' | 'INVALID_REGEX_STRING' | 'INVALID_REGEX_FLAGS' | 'INVALID_VANILLA_REGEX_FLAGS' | 'NOT_IMPLEMENTED' | 'INVALID_IDENTIFIER' | 'OUT_OF_BOUNDS' | 'INVALID_FLAG_TRANSFORMER_KEY' | 'FLAG_TRANSFORMER_CONFLICT';
2
2
  export declare class RGXError extends Error {
3
+ _message: string;
3
4
  code: RGXErrorCode;
5
+ get message(): string;
6
+ set message(value: string);
4
7
  constructor(message: string, code?: RGXErrorCode);
8
+ calcMessage(message: string): string;
9
+ toString(): string;
5
10
  }
@@ -2,13 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RGXError = void 0;
4
4
  class RGXError extends Error {
5
+ get message() {
6
+ return this.calcMessage(this._message);
7
+ }
8
+ set message(value) {
9
+ this._message = value;
10
+ }
5
11
  constructor(message, code) {
6
- super(message);
12
+ super();
7
13
  this.code = 'UNKNOWN';
8
14
  this.name = 'RGXError';
15
+ this.message = message;
9
16
  if (code) {
10
17
  this.code = code;
11
18
  }
12
19
  }
20
+ calcMessage(message) {
21
+ return message;
22
+ }
23
+ toString() {
24
+ return `${this.name}: ${this.message}`;
25
+ }
13
26
  }
14
27
  exports.RGXError = RGXError;
@@ -2,5 +2,5 @@ import { RGXError } from "./";
2
2
  export declare class RGXFlagTransformerConflictError extends RGXError {
3
3
  got: string;
4
4
  constructor(message: string, got: string);
5
- toString(): string;
5
+ calcMessage(message: string): string;
6
6
  }
@@ -8,8 +8,8 @@ class RGXFlagTransformerConflictError extends errors_1.RGXError {
8
8
  this.name = 'RGXFlagTransformerConflictError';
9
9
  this.got = got;
10
10
  }
11
- toString() {
12
- return `${this.name}: ${this.message}; Got: ${JSON.stringify(this.got)}`;
11
+ calcMessage(message) {
12
+ return `${message}; Got: ${JSON.stringify(this.got)}`;
13
13
  }
14
14
  }
15
15
  exports.RGXFlagTransformerConflictError = RGXFlagTransformerConflictError;
@@ -2,5 +2,5 @@ import { RGXError } from "./";
2
2
  export declare class RGXInvalidFlagTransformerKeyError extends RGXError {
3
3
  got: string;
4
4
  constructor(message: string, got: string);
5
- toString(): string;
5
+ calcMessage(message: string): string;
6
6
  }
@@ -8,8 +8,8 @@ class RGXInvalidFlagTransformerKeyError extends errors_1.RGXError {
8
8
  this.name = 'RGXInvalidFlagTransformerKeyError';
9
9
  this.got = got;
10
10
  }
11
- toString() {
12
- return `${this.name}: ${this.message}; Got: ${JSON.stringify(this.got)}`;
11
+ calcMessage(message) {
12
+ return `${message}; Got: ${JSON.stringify(this.got)}`;
13
13
  }
14
14
  }
15
15
  exports.RGXInvalidFlagTransformerKeyError = RGXInvalidFlagTransformerKeyError;
@@ -2,5 +2,5 @@ import { RGXError } from "./";
2
2
  export declare class RGXInvalidIdentifierError extends RGXError {
3
3
  got: string;
4
4
  constructor(message: string, got: string);
5
- toString(): string;
5
+ calcMessage(message: string): string;
6
6
  }
@@ -8,8 +8,8 @@ class RGXInvalidIdentifierError extends errors_1.RGXError {
8
8
  this.name = 'RGXInvalidIdentifierError';
9
9
  this.got = got;
10
10
  }
11
- toString() {
12
- return `${this.name}: ${this.message}; Got: ${JSON.stringify(this.got)}`;
11
+ calcMessage(message) {
12
+ return `${message}; Got: ${JSON.stringify(this.got)}`;
13
13
  }
14
14
  }
15
15
  exports.RGXInvalidIdentifierError = RGXInvalidIdentifierError;
@@ -2,5 +2,5 @@ import { RGXError } from "./";
2
2
  export declare class RGXInvalidRegexFlagsError extends RGXError {
3
3
  got: string;
4
4
  constructor(message: string, got: string);
5
- toString(): string;
5
+ calcMessage(message: string): string;
6
6
  }
@@ -8,8 +8,8 @@ class RGXInvalidRegexFlagsError extends errors_1.RGXError {
8
8
  this.name = 'RGXInvalidRegexFlagsError';
9
9
  this.got = got;
10
10
  }
11
- toString() {
12
- return `${this.name}: ${this.message}; Got: ${JSON.stringify(this.got)}`;
11
+ calcMessage(message) {
12
+ return `${message}; Got: ${JSON.stringify(this.got)}`;
13
13
  }
14
14
  }
15
15
  exports.RGXInvalidRegexFlagsError = RGXInvalidRegexFlagsError;
@@ -2,5 +2,5 @@ import { RGXError } from "./";
2
2
  export declare class RGXInvalidRegexStringError extends RGXError {
3
3
  got: string;
4
4
  constructor(message: string, got: string);
5
- toString(): string;
5
+ calcMessage(message: string): string;
6
6
  }
@@ -8,8 +8,8 @@ class RGXInvalidRegexStringError extends errors_1.RGXError {
8
8
  this.name = 'RGXInvalidRegexStringError';
9
9
  this.got = got;
10
10
  }
11
- toString() {
12
- return `${this.name}: ${this.message}; Got: ${JSON.stringify(this.got)}`;
11
+ calcMessage(message) {
12
+ return `${message}; Got: ${JSON.stringify(this.got)}`;
13
13
  }
14
14
  }
15
15
  exports.RGXInvalidRegexStringError = RGXInvalidRegexStringError;
@@ -12,5 +12,5 @@ export declare class RGXInvalidTokenError extends RGXError {
12
12
  got: unknown;
13
13
  setExpected(expected: ExpectedTokenType | null): string;
14
14
  constructor(message: string, expected: ExpectedTokenType | null, got: unknown);
15
- toString(): string;
15
+ calcMessage(message: string): string;
16
16
  }
@@ -6,7 +6,7 @@ const js_utils_1 = require("@ptolemy2002/js-utils");
6
6
  const class_1 = require("../class");
7
7
  const tokenExpectationMap = {
8
8
  'no-op': ['null', 'undefined'],
9
- 'literal': ['RegExp'],
9
+ 'literal': ['RegExp', 'ExtRegExp'],
10
10
  'native': ['string', 'number', 'boolean', 'null', 'undefined'],
11
11
  'convertible': ['object with a toRgx method that returns a valid native/literal token or an array of valid native/literal tokens'],
12
12
  'array': ['array of native/literal/convertible tokens'],
@@ -45,9 +45,9 @@ class RGXInvalidTokenError extends errors_1.RGXError {
45
45
  this.got = got;
46
46
  this.setExpected(expected);
47
47
  }
48
- toString() {
48
+ calcMessage(message) {
49
49
  const gotString = class_1.RGXClassToken.check(this.got) ? `instance of ${this.got.constructor.name}` : JSON.stringify(this.got);
50
- return `${this.name}: ${this.message}; Expected: ${this.expected}; Got: [${gotString}]`;
50
+ return `${message}; Expected: ${this.expected}; Got: [${gotString}]`;
51
51
  }
52
52
  }
53
53
  exports.RGXInvalidTokenError = RGXInvalidTokenError;
@@ -2,5 +2,5 @@ import { RGXError } from "./";
2
2
  export declare class RGXInvalidVanillaRegexFlagsError extends RGXError {
3
3
  got: string;
4
4
  constructor(message: string, got: string);
5
- toString(): string;
5
+ calcMessage(message: string): string;
6
6
  }
@@ -8,8 +8,8 @@ class RGXInvalidVanillaRegexFlagsError extends errors_1.RGXError {
8
8
  this.name = 'RGXInvalidVanillaRegexFlagsError';
9
9
  this.got = got;
10
10
  }
11
- toString() {
12
- return `${this.name}: ${this.message}; Got: ${JSON.stringify(this.got)}`;
11
+ calcMessage(message) {
12
+ return `${message}; Got: ${JSON.stringify(this.got)}`;
13
13
  }
14
14
  }
15
15
  exports.RGXInvalidVanillaRegexFlagsError = RGXInvalidVanillaRegexFlagsError;
@@ -2,5 +2,5 @@ import { RGXError } from "./base";
2
2
  export declare class RGXNotImplementedError extends RGXError {
3
3
  functionality: string;
4
4
  constructor(functionality: string, message?: string | null);
5
- toString(): string;
5
+ calcMessage(message: string): string;
6
6
  }
@@ -8,10 +8,10 @@ class RGXNotImplementedError extends base_1.RGXError {
8
8
  this.functionality = functionality;
9
9
  this.name = "RGXNotImplementedError";
10
10
  }
11
- toString() {
12
- const result = `${this.name}: ${this.functionality} is not implemented yet.`;
13
- if (this.message)
14
- return result + ` Additional info: ${this.message}`;
11
+ calcMessage(message) {
12
+ const result = `${this.functionality} is not implemented yet.`;
13
+ if (message)
14
+ return result + ` Additional info: ${message}`;
15
15
  else
16
16
  return result;
17
17
  }
@@ -14,7 +14,7 @@ export declare class RGXOutOfBoundsError extends RGXError {
14
14
  failedAtMin(): boolean;
15
15
  failedAtMax(): boolean;
16
16
  failedAtAny(): boolean;
17
- toString(): string;
17
+ calcMessage(message: string): string;
18
18
  }
19
19
  export declare function isInRange(value: number, { min, max, inclusiveLeft, inclusiveRight }?: RangeObject): boolean;
20
20
  export declare function assertInRange(value: number, range?: RangeObject, message?: string): void;
@@ -41,7 +41,7 @@ class RGXOutOfBoundsError extends base_1.RGXError {
41
41
  failedAtAny() {
42
42
  return this.failedAtMin() || this.failedAtMax();
43
43
  }
44
- toString() {
44
+ calcMessage(message) {
45
45
  const rangeParts = [];
46
46
  if (this.min !== null) {
47
47
  if (this.inclusiveLeft)
@@ -58,7 +58,7 @@ class RGXOutOfBoundsError extends base_1.RGXError {
58
58
  const rangeStr = rangeParts.join(" and ");
59
59
  // Determine which one was failed
60
60
  if (!this.failedAtAny()) {
61
- return `${this.name}: ${this.message}; Got: [${this.got}]; Expected: [${rangeStr}]`;
61
+ return `${message}; Got: [${this.got}]; Expected: [${rangeStr}]`;
62
62
  }
63
63
  else if (this.failedAtMin()) {
64
64
  let thirdPart;
@@ -66,7 +66,7 @@ class RGXOutOfBoundsError extends base_1.RGXError {
66
66
  thirdPart = `${this.got} == ${this.min}`;
67
67
  else
68
68
  thirdPart = `${this.got} < ${this.min}`;
69
- return `${this.name}: ${this.message}; Got: [${this.got}]; Expected: [${rangeStr}]; ${thirdPart}`;
69
+ return `${message}; Got: [${this.got}]; Expected: [${rangeStr}]; ${thirdPart}`;
70
70
  }
71
71
  else {
72
72
  let thirdPart;
@@ -74,7 +74,7 @@ class RGXOutOfBoundsError extends base_1.RGXError {
74
74
  thirdPart = `${this.got} == ${this.max}`;
75
75
  else
76
76
  thirdPart = `${this.got} > ${this.max}`;
77
- return `${this.name}: ${this.message}; Got: [${this.got}]; Expected: [${rangeStr}]; ${thirdPart}`;
77
+ return `${message}; Got: [${this.got}]; Expected: [${rangeStr}]; ${thirdPart}`;
78
78
  }
79
79
  }
80
80
  }
@@ -16,6 +16,8 @@ export declare function rgxTokenTypeToFlat(type: t.RGXTokenType): t.RGXTokenType
16
16
  export declare function rgxTokenTypeGuardInputToFlat(type: t.RGXTokenTypeGuardInput): t.RGXTokenTypeFlat | null;
17
17
  export declare function isRGXToken<T extends t.RGXTokenTypeGuardInput = null>(value: unknown, type?: T, matchLength?: boolean): value is t.RGXTokenFromType<T>;
18
18
  export declare function assertRGXToken<T extends t.RGXTokenTypeGuardInput = null>(value: unknown, type?: T, matchLength?: boolean): asserts value is t.RGXTokenFromType<T>;
19
+ export declare function isRGXGroupedToken(value: unknown, contentCheck?: boolean): value is t.RGXGroupedToken;
20
+ export declare function assertRGXGroupedToken(value: unknown, contentCheck?: boolean): asserts value is t.RGXGroupedToken;
19
21
  export declare function isValidRegexString(value: string): value is t.ValidRegexString;
20
22
  export declare function assertValidRegexString(value: string): asserts value is t.ValidRegexString;
21
23
  export declare function isValidVanillaRegexFlags(value: string): value is t.ValidVanillaRegexFlags;
@@ -53,6 +53,8 @@ exports.rgxTokenTypeToFlat = rgxTokenTypeToFlat;
53
53
  exports.rgxTokenTypeGuardInputToFlat = rgxTokenTypeGuardInputToFlat;
54
54
  exports.isRGXToken = isRGXToken;
55
55
  exports.assertRGXToken = assertRGXToken;
56
+ exports.isRGXGroupedToken = isRGXGroupedToken;
57
+ exports.assertRGXGroupedToken = assertRGXGroupedToken;
56
58
  exports.isValidRegexString = isValidRegexString;
57
59
  exports.assertValidRegexString = assertValidRegexString;
58
60
  exports.isValidVanillaRegexFlags = isValidVanillaRegexFlags;
@@ -193,6 +195,19 @@ function assertRGXToken(value, type = null, matchLength = true) {
193
195
  throw new e.RGXInvalidTokenError("Invalid RGX token", flatType === null ? null : { type: "tokenType", values: [flatType] }, value);
194
196
  }
195
197
  }
198
+ function isRGXGroupedToken(value, contentCheck = true) {
199
+ // Arrays and Literals are implicitly groups.
200
+ // Classes are only groups if they have the isGroup property set to true.
201
+ return (isRGXArrayToken(value, contentCheck) ||
202
+ isRGXToken(value, "literal") ||
203
+ (isRGXToken(value, "class") && value.isGroup) ||
204
+ (isRGXConvertibleToken(value, false) && value.rgxGroupWrap === true && (!contentCheck || isRGXGroupedToken(value.toRgx()))));
205
+ }
206
+ function assertRGXGroupedToken(value, contentCheck = true) {
207
+ if (!isRGXGroupedToken(value, contentCheck)) {
208
+ throw new e.RGXInvalidTokenError("Invalid group token, class token is not group, or convertible token is not group wrapped.", { type: "custom", values: ['array', 'literal', 'class', 'convertible'] }, value);
209
+ }
210
+ }
196
211
  function isValidRegexString(value) {
197
212
  try {
198
213
  new RegExp(value);
package/dist/types.d.ts CHANGED
@@ -11,6 +11,13 @@ export type RGXConvertibleToken = {
11
11
  };
12
12
  export type RGXToken = RGXNativeToken | RGXLiteralToken | RGXConvertibleToken | RGXToken[];
13
13
  export type RGXClassTokenConstructor = new (...args: unknown[]) => RGXClassToken;
14
+ export type RGXGroupedToken = RGXToken[] | RGXLiteralToken | (RGXClassToken & {
15
+ isGroup: true;
16
+ }) | RGXGroupedConvertibleToken;
17
+ export type RGXGroupedConvertibleToken = {
18
+ toRgx: () => RGXGroupedToken;
19
+ readonly rgxGroupWrap: true;
20
+ };
14
21
  export type RGXTokenType = 'no-op' | 'literal' | 'native' | 'convertible' | 'class' | RGXTokenType[];
15
22
  export type RGXTokenTypeFlat = Exclude<RGXTokenType, RGXTokenType[]> | "array";
16
23
  export type RGXTokenTypeGuardInput = RGXTokenTypeFlat | null | RGXClassTokenConstructor | typeof ExtRegExp | typeof RGXTokenCollection | RGXTokenTypeGuardInput[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/rgx",
3
- "version": "4.6.1",
3
+ "version": "4.7.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",