@ptolemy2002/rgx 7.7.0 → 7.7.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.
@@ -1,7 +1,8 @@
1
1
  import { RGXError } from "./base";
2
2
  export declare class RGXPartValidationFailedError extends RGXError {
3
+ id: string;
3
4
  gotRaw: string;
4
5
  gotTransformed: unknown;
5
- constructor(message: string, gotRaw: string, gotTransformed: unknown);
6
+ constructor(id: string | null, message: string, gotRaw: string, gotTransformed: unknown);
6
7
  calcMessage(message: string): string;
7
8
  }
@@ -3,14 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RGXPartValidationFailedError = void 0;
4
4
  const base_1 = require("./base");
5
5
  class RGXPartValidationFailedError extends base_1.RGXError {
6
- constructor(message, gotRaw, gotTransformed) {
6
+ constructor(id, message, gotRaw, gotTransformed) {
7
7
  super(message, 'PART_VALIDATION_FAILED');
8
8
  this.name = 'RGXPartValidationFailedError';
9
+ this.id = id ?? 'unknown';
9
10
  this.gotRaw = gotRaw;
10
11
  this.gotTransformed = gotTransformed;
11
12
  }
12
13
  calcMessage(message) {
13
- return `${message}; Got: ${this.gotRaw} (transformed: ${JSON.stringify(this.gotTransformed)})`;
14
+ return `${message}; ID: ${this.id}; Got: ${this.gotRaw} (transformed: ${JSON.stringify(this.gotTransformed)})`;
14
15
  }
15
16
  }
16
17
  exports.RGXPartValidationFailedError = RGXPartValidationFailedError;
@@ -10,13 +10,23 @@ const accentPatterns = [
10
10
  "(o|ó|ò|ö|ô|õ)", "(O|Ó|Ò|Ö|Ô|Õ)",
11
11
  "(u|ú|ù|ü|û)", "(U|Ú|Ù|Ü|Û)"
12
12
  ];
13
+ const nonEscapeBound = (0, resolve_1.resolveRGXToken)((0, constants_1.rgxConstant)("non-escape-bound"));
14
+ const nonLocalizedFlagBound = (0, resolve_1.resolveRGXToken)({
15
+ rgxGroupWrap: false,
16
+ rgxIsRepeatable: false,
17
+ toRgx() { return /(?<!\(\?\-?[ims]*)/; }
18
+ });
19
+ const nonCharacterClassBound = (0, resolve_1.resolveRGXToken)({
20
+ rgxGroupWrap: false,
21
+ rgxIsRepeatable: false,
22
+ toRgx() { return /(?<!\[[^\]]*)/; }
23
+ });
13
24
  const accentInsensitiveFlagTransformer = function (exp) {
14
25
  let source = exp.source;
15
26
  const flags = exp.flags;
16
- const nonEscapeBound = (0, resolve_1.resolveRGXToken)((0, constants_1.rgxConstant)("non-escape-bound"));
17
27
  accentPatterns.forEach((pattern) => {
18
28
  // Replace any of the characters in the pattern with the pattern itself
19
- source = source.replaceAll(new RegExp(nonEscapeBound + pattern, "g"), pattern);
29
+ source = source.replaceAll(new RegExp(nonEscapeBound + nonLocalizedFlagBound + nonCharacterClassBound + pattern, "g"), pattern);
20
30
  });
21
31
  return new RegExp(source, flags);
22
32
  };
package/dist/index.js CHANGED
@@ -54,6 +54,7 @@ function rgx(flags = '', multiline = true) {
54
54
  };
55
55
  }
56
56
  function rgxwa(source, tokens, options = {}) {
57
+ (0, internal_1.assureAcceptance)(tokens, '');
57
58
  return new walker_1.RGXWalker(source, tokens, options);
58
59
  }
59
60
  function rgxw(source, { multiline = true, ...options } = {}) {
package/dist/types.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { RGXClassToken } from "./class";
3
3
  import type { ExtRegExp } from "./ExtRegExp";
4
4
  import type { RGXTokenCollection } from "./collection";
5
5
  import type { RGXWalkerOptions } from "./walker";
6
+ import type { RGXPart, RGXWalker } from "./walker";
6
7
  export type RGXNoOpToken = null | undefined;
7
8
  export type RGXLiteralToken = RegExp;
8
9
  export type RGXNativeToken = string | number | boolean | RGXNoOpToken;
@@ -27,7 +28,7 @@ export type RGXRepeatableConvertibleToken = RGXConvertibleToken & {
27
28
  };
28
29
  export type RGXTokenType = 'no-op' | 'literal' | 'native' | 'convertible' | 'class' | RGXTokenType[];
29
30
  export type RGXTokenTypeFlat = Exclude<RGXTokenType, RGXTokenType[]> | "array";
30
- export type RGXTokenTypeGuardInput = "repeatable" | RGXTokenTypeFlat | null | RGXClassTokenConstructor | typeof RegExp | typeof ExtRegExp | typeof RGXTokenCollection | RGXTokenTypeGuardInput[];
31
+ export type RGXTokenTypeGuardInput = "repeatable" | RGXTokenTypeFlat | null | RGXClassTokenConstructor | typeof RegExp | typeof ExtRegExp | typeof RGXTokenCollection | typeof RGXWalker | typeof RGXPart | RGXTokenTypeGuardInput[];
31
32
  export type RGXTokenFromType<T extends RGXTokenTypeGuardInput> = T extends null ? RGXToken : T extends 'no-op' ? RGXNoOpToken : T extends 'literal' ? RGXLiteralToken : T extends 'native' ? RGXNativeToken : T extends 'convertible' ? RGXConvertibleToken : T extends 'class' ? RGXClassToken : T extends 'array' ? RGXToken[] : T extends 'repeatable' ? Exclude<RGXToken, RGXConvertibleToken> | RGXRepeatableConvertibleToken : T extends new (...args: unknown[]) => infer R ? R : T extends RGXTokenTypeGuardInput[] ? {
32
33
  [K in keyof T]: T[K] extends RGXTokenTypeGuardInput ? RGXTokenFromType<T[K]> : never;
33
34
  } : never;
@@ -49,6 +50,6 @@ export type ValidRegexFlags = Branded<string, [ValidRegexFlagsBrandSymbol]> | Va
49
50
  export declare const validIdentifierSymbol: unique symbol;
50
51
  export type ValidIdentifierBrandSymbol = typeof validIdentifierSymbol;
51
52
  export type ValidIdentifier = Branded<string, [ValidIdentifierBrandSymbol]>;
52
- export type RGXWOptions<R = unknown> = Omit<RGXWalkerOptions<R>, "startingSourcePosition"> & {
53
+ export type RGXWOptions<R = unknown> = RGXWalkerOptions<R> & {
53
54
  multiline?: boolean;
54
55
  };
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.regexWithFlags = regexWithFlags;
4
- const typeGuards_1 = require("../typeGuards");
5
- const normalizeRegexFlags_1 = require("./normalizeRegexFlags");
6
4
  const ExtRegExp_1 = require("../ExtRegExp");
5
+ const normalizeRegexFlags_1 = require("./normalizeRegexFlags");
6
+ const ExtRegExp_2 = require("../ExtRegExp");
7
7
  function regexWithFlags(exp, flags, replace = false) {
8
- (0, typeGuards_1.assertValidVanillaRegexFlags)(flags);
8
+ (0, ExtRegExp_1.assertValidRegexFlags)(flags);
9
9
  if (replace)
10
- return new ExtRegExp_1.ExtRegExp(exp.source, flags);
10
+ return new ExtRegExp_2.ExtRegExp(exp.source, flags);
11
11
  const existingFlags = exp.flags;
12
12
  const newFlags = existingFlags + flags;
13
- return new ExtRegExp_1.ExtRegExp(exp.source, (0, normalizeRegexFlags_1.normalizeVanillaRegexFlags)(newFlags));
13
+ return new ExtRegExp_2.ExtRegExp(exp.source, (0, normalizeRegexFlags_1.normalizeRegexFlags)(newFlags));
14
14
  }
@@ -25,7 +25,7 @@ class RGXPart {
25
25
  if (result === true)
26
26
  return;
27
27
  const message = typeof result === "string" ? result : "Part Validation Failed";
28
- throw new errors_1.RGXPartValidationFailedError(message, capture.raw, capture.value);
28
+ throw new errors_1.RGXPartValidationFailedError(this.id, message, capture.raw, capture.value);
29
29
  }
30
30
  // Properties used for conversion to an RGXToken
31
31
  get rgxIsGroup() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/rgx",
3
- "version": "7.7.0",
3
+ "version": "7.7.2",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",