@ptolemy2002/rgx 2.5.1 → 2.5.2
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 +15 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ constructor(functionality: string, message?: string | null)
|
|
|
112
112
|
- `functionality` (`string`): The description of the unimplemented functionality.
|
|
113
113
|
|
|
114
114
|
#### Methods
|
|
115
|
-
- `toString()
|
|
115
|
+
- `toString() => string`: Returns a formatted string indicating the unimplemented functionality and any additional message.
|
|
116
116
|
|
|
117
117
|
### RGXTokenCollection
|
|
118
118
|
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.
|
|
@@ -129,11 +129,12 @@ constructor(tokens: RGXTokenCollectionInput = [], mode: RGXTokenCollectionMode =
|
|
|
129
129
|
#### Properties
|
|
130
130
|
- `tokens` (`RGXToken[]`): The array of RGX tokens managed by the collection. In almost all cases, use `getTokens()` instead of accessing this property directly, as it will be copied to prevent external mutation.
|
|
131
131
|
- `mode` (`RGXTokenCollectionMode`): The mode of the collection, either 'union' or 'concat'. This determines how the tokens in the collection will be resolved when `toRgx()` is called.
|
|
132
|
-
- `toRgx()
|
|
133
|
-
- `getTokens()
|
|
134
|
-
- `
|
|
135
|
-
- `
|
|
136
|
-
- `
|
|
132
|
+
- `toRgx() => RegExp`: A method that resolves the collection to a `RegExp` object based on the collection mode. In 'union' mode, the tokens are resolved as alternatives (using the `|` operator), while in 'concat' mode, the tokens are resolved as concatenated together. No flags are applied to the resulting `RegExp`. Since this method returns a `RegExp` (which is `RGXLiteralToken`), `RGXTokenCollection` instances satisfy the `RGXConvertibleToken` interface and can be used directly as tokens in `rgx`, `rgxa`, and other token-accepting functions.
|
|
133
|
+
- `getTokens() => RGXToken[]`: A method that returns a copy of the array of RGX tokens managed by the collection. This is used to prevent external mutation of the internal `tokens` array.
|
|
134
|
+
- `toArray() => RGXToken[]`: An alias for `getTokens()`, provided for convenience.
|
|
135
|
+
- `clone() => RGXTokenCollection`: A method that creates and returns a deep clone of the RGXTokenCollection instance. This is useful for creating a new collection with the same tokens and mode without affecting the original collection.
|
|
136
|
+
- `asConcat() => RGXTokenCollection`: If this collection is in 'union' mode, this method returns a new RGXTokenCollection instance with the same tokens but in 'concat' mode. If the collection is already in 'concat' mode, it simply returns itself.
|
|
137
|
+
- `asUnion() => RGXTokenCollection`: If this collection is in 'concat' mode, this method returns a new RGXTokenCollection instance with the same tokens but in 'union' mode. If the collection is already in 'union' mode, it simply returns itself.
|
|
137
138
|
|
|
138
139
|
Standard array properties and methods like `length`, `push`, `pop`, etc. are implemented to work with the internal `tokens` array, but providing collection instances instead of raw arrays when relevant (e.g., `map` has the third parameter typed as `RGXTokenCollection` instead of `RGXToken[]`).
|
|
139
140
|
|
|
@@ -141,14 +142,14 @@ Standard array properties and methods like `length`, `push`, `pop`, etc. are imp
|
|
|
141
142
|
An abstract base class for creating custom RGX token classes. Subclasses must implement the `toRgx()` method, which returns a value compatible with `RGXConvertibleTokenOutput`.
|
|
142
143
|
|
|
143
144
|
#### Abstract Methods
|
|
144
|
-
- `toRgx()
|
|
145
|
+
- `toRgx() => RGXConvertibleTokenOutput`: Must be implemented by subclasses to return the token's regex representation as a native/literal token or array of native/literal tokens.
|
|
145
146
|
|
|
146
147
|
#### Properties
|
|
147
148
|
- `isGroup` (`boolean`): Returns `false` by default. Subclasses can override this to indicate whether the token represents a group.
|
|
148
149
|
|
|
149
150
|
#### Methods
|
|
150
|
-
- `or(...others: RGXTokenCollectionInput[])
|
|
151
|
-
- `resolve()
|
|
151
|
+
- `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.
|
|
152
|
+
- `resolve() => ValidRegexString`: A convenience method that resolves this token by calling `resolveRGXToken(this)`, returning the resolved regex string representation. Since this method is defined on `RGXClassToken`, it is available on all subclasses including `RGXClassUnionToken`.
|
|
152
153
|
|
|
153
154
|
### RGXClassUnionToken extends RGXClassToken
|
|
154
155
|
A class representing a union (alternation) of RGX tokens. This is typically created via the `or()` method on `RGXClassToken`, but can also be instantiated directly.
|
|
@@ -166,10 +167,10 @@ constructor(tokens: RGXTokenCollectionInput = [])
|
|
|
166
167
|
- `isGroup` (`boolean`): Returns `true`, indicating this token represents a group.
|
|
167
168
|
|
|
168
169
|
#### Methods
|
|
169
|
-
- `add(token: RGXToken, pos?: RGXUnionInsertionPosition)
|
|
170
|
-
- `concat(pos?: RGXUnionInsertionPosition, ...others: RGXTokenCollectionInput[])
|
|
171
|
-
- `cleanTokens()
|
|
172
|
-
- `toRgx()
|
|
170
|
+
- `add(token: RGXToken, pos?: RGXUnionInsertionPosition) => this`: Adds a token to the union. The `pos` parameter controls where the token is inserted: `'prefix'` inserts at the beginning, `'suffix'` (default) appends to the end. Returns `this` for chaining.
|
|
171
|
+
- `concat(pos?: RGXUnionInsertionPosition, ...others: RGXTokenCollectionInput[]) => this`: Concatenates additional tokens into the union. The `pos` parameter controls insertion position: `'suffix'` (default) appends to the end, `'prefix'` prepends to the beginning. Returns `this` for chaining.
|
|
172
|
+
- `cleanTokens() => this`: Expands any nested union tokens and removes duplicates from the internal token collection. Returns `this` for chaining. Called automatically during construction and after `add` or `concat`.
|
|
173
|
+
- `toRgx() => RegExp`: Resolves the union by calling `toRgx()` on the internal `RGXTokenCollection`, returning a `RegExp`.
|
|
173
174
|
|
|
174
175
|
## Functions
|
|
175
176
|
The following functions are exported by the library:
|
|
@@ -432,7 +433,7 @@ A helper function that resolves an array of RGX tokens and concatenates their re
|
|
|
432
433
|
|
|
433
434
|
### rgx
|
|
434
435
|
```typescript
|
|
435
|
-
function rgx(flags?: string): (strings: TemplateStringsArray, ...tokens: RGXToken[]) =>RegExp
|
|
436
|
+
function rgx(flags?: string): (strings: TemplateStringsArray, ...tokens: RGXToken[]) => RegExp
|
|
436
437
|
```
|
|
437
438
|
|
|
438
439
|
Creates and returns a template tag function that constructs a `RegExp` 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.
|