@ptolemy2002/rgx 6.0.0 → 6.1.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
@@ -97,6 +97,10 @@ type RGXWalkerOptions<R> = {
97
97
  startingSourcePosition?: number;
98
98
  reduced?: R;
99
99
  };
100
+
101
+ type RGXWOptions<R = unknown> = Omit<RGXWalkerOptions<R>, "startingSourcePosition"> & {
102
+ multiline?: boolean;
103
+ };
100
104
  ```
101
105
 
102
106
  ## Classes
@@ -1151,6 +1155,37 @@ As an alternative to using the `rgx` template tag, you can directly call `rgxa`
1151
1155
  #### Returns
1152
1156
  - `ExtRegExp`: An `ExtRegExp` object constructed from the resolved tokens and the provided flags.
1153
1157
 
1158
+ ### rgxw
1159
+ ```typescript
1160
+ function rgxw<R = unknown>(source: string, {multiline=true, ...options}: RGXWOptions<R> = {}): (strings: TemplateStringsArray, ...tokens: RGXToken[]
1161
+ ) => RGXWalker<R>
1162
+ ```
1163
+ A helper function that creates an `RGXWalker` instance from an interpolation of strings and tokens. The token array is processed exactly like in `rgx`, but instead of returning an `ExtRegExp`, it returns an `RGXWalker` that can be used to walk through matches of the regex pattern in the source string.
1164
+
1165
+ #### Parameters
1166
+ - `source` (`string`): An arbitrary string value that will be included in the `source` property of the walker object.
1167
+ - `options` (`RGXWOptions<R>`, optional): Additional options for configuring the behavior of the resulting `RGXWalker`. This includes:
1168
+ - `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.
1169
+ - `reduced` (`R`, optional): An optional initial value for the walker's `reduced` property, which can be used to accumulate results across matches.
1170
+
1171
+ #### Returns
1172
+ - `(strings: TemplateStringsArray, ...tokens: RGXToken[]) => RGXWalker<R>`: A template tag function that takes a template literal and returns an `RGXWalker` instance configured with the provided source, the provided tokens, and the specified options.
1173
+
1174
+ ### rgxwa
1175
+ ```typescript
1176
+ function rgxwa<R = unknown>(source: string, tokens: RGXToken[], options: Omit<RGXWOptions<R>, "multiline"> = {}): RGXWalker<R>
1177
+ ```
1178
+ As an alternative to using the `rgxw` template tag, you can directly call `rgxwa` with a source string, an array of RGX tokens, and options to get an `RGXWalker` instance. This is useful in cases where you don't want to use a template literal. The token array is processed exactly like in `rgxa`, and the provided options are passed through to configure the resulting walker.
1179
+
1180
+ #### Parameters
1181
+ - `source` (`string`): An arbitrary string value that will be included in the `source` property of the walker object.
1182
+ - `tokens` (`RGXToken[]`): The RGX tokens to be resolved and concatenated to form the regex pattern for the walker.
1183
+ - `options` (`Omit<RGXWOptions<R>, "multiline">`, optional): Additional options for configuring the behavior of the resulting `RGXWalker`, excluding the `multiline` option which is not applicable when not using a template literal. This includes:
1184
+ - `reduced` (`R`, optional): An optional initial value for the walker's `reduced` property, which can be used to accumulate results across matches.
1185
+
1186
+ #### Returns
1187
+ - `RGXWalker<R>`: An `RGXWalker` instance configured with the provided source, the resolved tokens, and the specified options.
1188
+
1154
1189
  ### expandRgxUnionTokens
1155
1190
  ```typescript
1156
1191
  function expandRgxUnionTokens(...tokens: RGXTokenCollectionInput[]): RGXTokenCollection
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as t from "./types";
2
2
  import { ExtRegExp } from "./ExtRegExp";
3
+ import { RGXWalker } from "./walker";
3
4
  export * from "./errors";
4
5
  export * from "./types";
5
6
  export * from "./typeGuards";
@@ -15,3 +16,5 @@ export * from "./constants";
15
16
  export * from "./walker";
16
17
  export declare function rgxa(tokens: t.RGXToken[], flags?: string): ExtRegExp;
17
18
  export default function rgx(flags?: string, multiline?: boolean): (strings: TemplateStringsArray, ...tokens: t.RGXToken[]) => ExtRegExp;
19
+ export declare function rgxwa<R = unknown>(source: string, tokens: t.RGXToken[], options?: Omit<t.RGXWOptions<R>, "multiline">): RGXWalker<R>;
20
+ export declare function rgxw<R = unknown>(source: string, { multiline, ...options }?: t.RGXWOptions<R>): (strings: TemplateStringsArray, ...tokens: t.RGXToken[]) => RGXWalker<R>;
package/dist/index.js CHANGED
@@ -16,11 +16,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.rgxa = rgxa;
18
18
  exports.default = rgx;
19
+ exports.rgxwa = rgxwa;
20
+ exports.rgxw = rgxw;
19
21
  const class_1 = require("./class");
20
22
  const flag_transformer_1 = require("./flag-transformer");
21
23
  const concat_1 = require("./concat");
22
24
  const internal_1 = require("./internal");
23
25
  const ExtRegExp_1 = require("./ExtRegExp");
26
+ const walker_1 = require("./walker");
24
27
  __exportStar(require("./errors"), exports);
25
28
  __exportStar(require("./types"), exports);
26
29
  __exportStar(require("./typeGuards"), exports);
@@ -50,3 +53,11 @@ function rgx(flags = '', multiline = true) {
50
53
  return rgxa((0, internal_1.taggedTemplateToArray)(strings, tokens, multiline), flags);
51
54
  };
52
55
  }
56
+ function rgxwa(source, tokens, options = {}) {
57
+ return new walker_1.RGXWalker(source, tokens, options);
58
+ }
59
+ function rgxw(source, { multiline = true, ...options } = {}) {
60
+ return (strings, ...tokens) => {
61
+ return rgxwa(source, (0, internal_1.taggedTemplateToArray)(strings, tokens, multiline), options);
62
+ };
63
+ }
package/dist/types.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Branded } from "@ptolemy2002/ts-brand-utils";
2
2
  import type { RGXClassToken } from "./class";
3
3
  import type { ExtRegExp } from "./ExtRegExp";
4
4
  import type { RGXTokenCollection } from "./collection";
5
+ import type { RGXWalkerOptions } from "./walker";
5
6
  export type RGXNoOpToken = null | undefined;
6
7
  export type RGXLiteralToken = RegExp;
7
8
  export type RGXNativeToken = string | number | boolean | RGXNoOpToken;
@@ -45,3 +46,6 @@ export type ValidRegexFlags = Branded<string, [ValidRegexFlagsBrandSymbol]> | Va
45
46
  export declare const validIdentifierSymbol: unique symbol;
46
47
  export type ValidIdentifierBrandSymbol = typeof validIdentifierSymbol;
47
48
  export type ValidIdentifier = Branded<string, [ValidIdentifierBrandSymbol]>;
49
+ export type RGXWOptions<R = unknown> = Omit<RGXWalkerOptions<R>, "startingSourcePosition"> & {
50
+ multiline?: boolean;
51
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/rgx",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",