@ptolemy2002/rgx 12.8.0 → 13.0.1
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 +1 -0
- package/dist/collection.js +1 -1
- package/dist/concat.js +1 -1
- package/dist/constants.d.ts +12 -2
- package/dist/constants.js +12 -5
- package/dist/index.d.ts +4 -4
- package/dist/index.js +23 -21
- package/dist/resolve.d.ts +6 -1
- package/dist/resolve.js +5 -5
- package/dist/utils/createRGXBounds.d.ts +2 -0
- package/dist/utils/createRGXBounds.js +31 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ Because there is so much to document, it has been broken up into multiple files.
|
|
|
20
20
|
- [regexWithFlags](./docs/util/regexWithFlags.md) - The `regexWithFlags` function, which creates a new regular expression with the same source as a given regular expression but with different flags.
|
|
21
21
|
- [createRegex](./docs/util/createRegex.md) - The `createRegex` function, which safely constructs a `RegExp` or `ExtRegExp` from a pattern string, converting `SyntaxError` into `RGXInvalidRegexStringError`.
|
|
22
22
|
- [createRGXClassGuardFunction](./docs/util/createRGXClassGuardFunction.md) - The `createRGXClassGuardFunction` and `createAssertRGXClassGuardFunction` utilities for creating type guard and assertion functions for class instances.
|
|
23
|
+
- [createRGXBounds](./docs/util/createRGXBounds.md) - The `createRGXBounds` function, which creates a pair of zero-width boundary tokens representing the start and end of a region delimited by two patterns.
|
|
23
24
|
- `class` - A directory containing documentation for all classes in the library.
|
|
24
25
|
- [collection](./docs/class/collection.md) - The `RGXTokenCollection` class, which is a collection of tokens.
|
|
25
26
|
- [RGXError](./docs/class/RGXError.md) - Details on all custom error classes and the base `RGXError` class.
|
package/dist/collection.js
CHANGED
|
@@ -28,7 +28,7 @@ class RGXTokenCollection {
|
|
|
28
28
|
if (this.mode === 'union') {
|
|
29
29
|
// The RegExp will already be wrapped with resolveRGXToken,
|
|
30
30
|
// so we don't need to wrap it again here.
|
|
31
|
-
pattern = (0, resolve_1.resolveRGXToken)(this.tokens, false);
|
|
31
|
+
pattern = (0, resolve_1.resolveRGXToken)(this.tokens, { groupWrap: false });
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
pattern = (0, concat_1.rgxConcat)(this.tokens);
|
package/dist/concat.js
CHANGED
|
@@ -7,7 +7,7 @@ const resolve_1 = require("./resolve");
|
|
|
7
7
|
// Wrapper for letting an array of tokens be resolved as a concatenation instead of a union.
|
|
8
8
|
function rgxConcat(tokens, groupWrap = true, currentFlags = '') {
|
|
9
9
|
(0, ExtRegExp_1.assertValidRegexFlags)(currentFlags);
|
|
10
|
-
const result = tokens.map(t => (0, resolve_1.resolveRGXToken)(t, groupWrap,
|
|
10
|
+
const result = tokens.map(t => (0, resolve_1.resolveRGXToken)(t, { groupWrap, currentFlags })).join('');
|
|
11
11
|
(0, internal_1.assureAcceptance)(tokens, currentFlags);
|
|
12
12
|
return result;
|
|
13
13
|
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RGXClassToken } from "./class";
|
|
1
2
|
import { RGXToken } from "./types";
|
|
2
3
|
export declare const RGX_PREDEFINED_CONSTANTS: {
|
|
3
4
|
readonly newline: "\n";
|
|
@@ -103,6 +104,15 @@ export declare const RGX_PREDEFINED_CONSTANTS: {
|
|
|
103
104
|
readonly rgxGroupWrap: false;
|
|
104
105
|
readonly toRgx: () => RegExp;
|
|
105
106
|
};
|
|
107
|
+
readonly "non-newline-whitespace": {
|
|
108
|
+
readonly rgxIsGroup: true;
|
|
109
|
+
readonly rgxGroupWrap: false;
|
|
110
|
+
readonly toRgx: () => RegExp;
|
|
111
|
+
};
|
|
112
|
+
readonly "non-newline-whitespace-block": {
|
|
113
|
+
readonly rgxGroupWrap: false;
|
|
114
|
+
readonly toRgx: () => RegExp;
|
|
115
|
+
};
|
|
106
116
|
readonly "vertical-whitespace": {
|
|
107
117
|
readonly rgxGroupWrap: false;
|
|
108
118
|
readonly toRgx: () => RegExp;
|
|
@@ -137,6 +147,6 @@ export declare function listRGXConstants(): string[];
|
|
|
137
147
|
export declare function hasRGXConstant(name: RGXConstantName): boolean;
|
|
138
148
|
export declare function assertHasRGXConstant(name: RGXConstantName): void;
|
|
139
149
|
export declare function assertNotHasRGXConstant(name: RGXConstantName): void;
|
|
140
|
-
export declare function defineRGXConstant(name: RGXConstantName, value: RGXToken):
|
|
141
|
-
export declare function rgxConstant(name: RGXConstantName):
|
|
150
|
+
export declare function defineRGXConstant(name: RGXConstantName, value: RGXToken): RGXClassToken;
|
|
151
|
+
export declare function rgxConstant(name: RGXConstantName): RGXClassToken;
|
|
142
152
|
export declare function deleteRGXConstant(name: RGXConstantName): void;
|
package/dist/constants.js
CHANGED
|
@@ -10,7 +10,6 @@ exports.rgxConstant = rgxConstant;
|
|
|
10
10
|
exports.deleteRGXConstant = deleteRGXConstant;
|
|
11
11
|
const class_1 = require("./class");
|
|
12
12
|
const errors_1 = require("./errors");
|
|
13
|
-
const typeGuards_1 = require("./typeGuards");
|
|
14
13
|
const rgxConstants = {};
|
|
15
14
|
exports.RGX_PREDEFINED_CONSTANTS = {
|
|
16
15
|
// Control Characters
|
|
@@ -63,7 +62,7 @@ exports.RGX_PREDEFINED_CONSTANTS = {
|
|
|
63
62
|
rgxIsRepeatable: false,
|
|
64
63
|
toRgx() {
|
|
65
64
|
// Make sure there is a non-word character before and a word character after
|
|
66
|
-
return /(?<=\W)(?=\w)/;
|
|
65
|
+
return /(?<=\W|^)(?=\w)/;
|
|
67
66
|
}
|
|
68
67
|
},
|
|
69
68
|
"word-bound-end": {
|
|
@@ -71,7 +70,7 @@ exports.RGX_PREDEFINED_CONSTANTS = {
|
|
|
71
70
|
rgxIsRepeatable: false,
|
|
72
71
|
toRgx() {
|
|
73
72
|
// Make sure there is a word character before and a non-word character after
|
|
74
|
-
return /(?<=\w)(?=\W)/;
|
|
73
|
+
return /(?<=\w)(?=\W|$)/;
|
|
75
74
|
}
|
|
76
75
|
},
|
|
77
76
|
// Character Sets
|
|
@@ -126,6 +125,15 @@ exports.RGX_PREDEFINED_CONSTANTS = {
|
|
|
126
125
|
rgxGroupWrap: false,
|
|
127
126
|
toRgx() { return /\S/; }
|
|
128
127
|
},
|
|
128
|
+
"non-newline-whitespace": {
|
|
129
|
+
rgxIsGroup: true,
|
|
130
|
+
rgxGroupWrap: false,
|
|
131
|
+
toRgx() { return /[^\n\S]/; }
|
|
132
|
+
},
|
|
133
|
+
"non-newline-whitespace-block": {
|
|
134
|
+
rgxGroupWrap: false,
|
|
135
|
+
toRgx() { return /[^\n\S]+/; }
|
|
136
|
+
},
|
|
129
137
|
"vertical-whitespace": {
|
|
130
138
|
rgxGroupWrap: false,
|
|
131
139
|
toRgx() { return /\v/; }
|
|
@@ -180,8 +188,7 @@ function assertNotHasRGXConstant(name) {
|
|
|
180
188
|
}
|
|
181
189
|
function defineRGXConstant(name, value) {
|
|
182
190
|
assertNotHasRGXConstant(name);
|
|
183
|
-
|
|
184
|
-
rgxConstants[name] = (0, typeGuards_1.isRGXNativeToken)(value) ? (0, class_1.rgxClassWrapper)(value) : value;
|
|
191
|
+
rgxConstants[name] = class_1.RGXClassToken.check(value) ? value : (0, class_1.rgxClassWrapper)(value);
|
|
185
192
|
return rgxConstants[name];
|
|
186
193
|
}
|
|
187
194
|
function rgxConstant(name) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as t from "./types";
|
|
2
2
|
import { ExtRegExp } from "./ExtRegExp";
|
|
3
3
|
import { RGXTokenOrPart, RGXWalker } from "./walker";
|
|
4
|
+
export declare function rgxa(tokens: t.RGXToken[], flags?: string): ExtRegExp;
|
|
5
|
+
export default function rgx(flags?: string, { multiline, verbatim }?: t.RGXOptions): (strings: TemplateStringsArray, ...tokens: t.RGXToken[]) => ExtRegExp;
|
|
6
|
+
export declare function rgxwa<R = unknown, S = unknown, T = unknown>(source: string, tokens: RGXTokenOrPart<R, S, T>[], options?: Omit<t.RGXWOptions<R, S>, "multiline">): RGXWalker<R, S>;
|
|
7
|
+
export declare function rgxw<R = unknown, S = unknown, T = unknown>(source: string, { multiline, verbatim, ...options }?: t.RGXWOptions<R, S>): (strings: TemplateStringsArray, ...tokens: RGXTokenOrPart<R, S, T>[]) => RGXWalker<R, S>;
|
|
4
8
|
export * from "./errors";
|
|
5
9
|
export * from "./types";
|
|
6
10
|
export * from "./typeGuards";
|
|
@@ -15,7 +19,3 @@ export * from "./clone";
|
|
|
15
19
|
export * from "./constants";
|
|
16
20
|
export * from "./walker";
|
|
17
21
|
export * from "./lexer";
|
|
18
|
-
export declare function rgxa(tokens: t.RGXToken[], flags?: string): ExtRegExp;
|
|
19
|
-
export default function rgx(flags?: string, { multiline, verbatim }?: t.RGXOptions): (strings: TemplateStringsArray, ...tokens: t.RGXToken[]) => ExtRegExp;
|
|
20
|
-
export declare function rgxwa<R = unknown, S = unknown, T = unknown>(source: string, tokens: RGXTokenOrPart<R, S, T>[], options?: Omit<t.RGXWOptions<R, S>, "multiline">): RGXWalker<R, S>;
|
|
21
|
-
export declare function rgxw<R = unknown, S = unknown, T = unknown>(source: string, { multiline, verbatim, ...options }?: t.RGXWOptions<R, S>): (strings: TemplateStringsArray, ...tokens: RGXTokenOrPart<R, S, T>[]) => RGXWalker<R, S>;
|
package/dist/index.js
CHANGED
|
@@ -21,46 +21,48 @@ exports.rgxw = rgxw;
|
|
|
21
21
|
const class_1 = require("./class");
|
|
22
22
|
const flag_transformer_1 = require("./flag-transformer");
|
|
23
23
|
const concat_1 = require("./concat");
|
|
24
|
-
const
|
|
24
|
+
const assureAcceptance_1 = require("./internal/assureAcceptance");
|
|
25
|
+
const taggedTemplateToArray_1 = require("./internal/taggedTemplateToArray");
|
|
25
26
|
const ExtRegExp_1 = require("./ExtRegExp");
|
|
26
27
|
const walker_1 = require("./walker");
|
|
27
|
-
const
|
|
28
|
-
__exportStar(require("./errors"), exports);
|
|
29
|
-
__exportStar(require("./types"), exports);
|
|
30
|
-
__exportStar(require("./typeGuards"), exports);
|
|
31
|
-
__exportStar(require("./collection"), exports);
|
|
32
|
-
__exportStar(require("./class"), exports);
|
|
33
|
-
__exportStar(require("./resolve"), exports);
|
|
34
|
-
__exportStar(require("./concat"), exports);
|
|
35
|
-
__exportStar(require("./utils"), exports);
|
|
36
|
-
__exportStar(require("./ExtRegExp"), exports);
|
|
37
|
-
__exportStar(require("./flag-transformer"), exports);
|
|
38
|
-
__exportStar(require("./clone"), exports);
|
|
39
|
-
__exportStar(require("./constants"), exports);
|
|
40
|
-
__exportStar(require("./walker"), exports);
|
|
41
|
-
__exportStar(require("./lexer"), exports);
|
|
28
|
+
const createRegex_1 = require("./utils/createRegex");
|
|
42
29
|
// Call this for certain class methods to work correctly
|
|
43
30
|
(0, class_1.rgxClassInit)();
|
|
44
31
|
// Call this for our custom flags to work correctly
|
|
45
32
|
(0, flag_transformer_1.registerCustomFlagTransformers)();
|
|
46
33
|
function rgxa(tokens, flags = '') {
|
|
47
34
|
(0, ExtRegExp_1.assertValidRegexFlags)(flags);
|
|
48
|
-
(0,
|
|
35
|
+
(0, assureAcceptance_1.assureAcceptance)(tokens, flags);
|
|
49
36
|
const pattern = (0, concat_1.rgxConcat)(tokens, true, flags);
|
|
50
|
-
return (0,
|
|
37
|
+
return (0, createRegex_1.createRegex)(pattern, flags, true);
|
|
51
38
|
}
|
|
52
39
|
function rgx(flags = '', { multiline = true, verbatim = true } = {}) {
|
|
53
40
|
return (strings, ...tokens) => {
|
|
54
41
|
// It is safe to assert the result because we know there will be no parts passed in here.
|
|
55
|
-
return rgxa((0,
|
|
42
|
+
return rgxa((0, taggedTemplateToArray_1.rgxTaggedTemplateToArray)(strings, tokens, multiline, verbatim), flags);
|
|
56
43
|
};
|
|
57
44
|
}
|
|
58
45
|
function rgxwa(source, tokens, options = {}) {
|
|
59
|
-
(0,
|
|
46
|
+
(0, assureAcceptance_1.assureAcceptance)(tokens.map(t => walker_1.RGXPart.check(t) ? t.token : t), '');
|
|
60
47
|
return new walker_1.RGXWalker(source, tokens, options);
|
|
61
48
|
}
|
|
62
49
|
function rgxw(source, { multiline = true, verbatim = true, ...options } = {}) {
|
|
63
50
|
return (strings, ...tokens) => {
|
|
64
|
-
return rgxwa(source, (0,
|
|
51
|
+
return rgxwa(source, (0, taggedTemplateToArray_1.rgxTaggedTemplateToArray)(strings, tokens, multiline, verbatim), options);
|
|
65
52
|
};
|
|
66
53
|
}
|
|
54
|
+
// Do all exports after to avoid circular dependencies issues.
|
|
55
|
+
__exportStar(require("./errors"), exports);
|
|
56
|
+
__exportStar(require("./types"), exports);
|
|
57
|
+
__exportStar(require("./typeGuards"), exports);
|
|
58
|
+
__exportStar(require("./collection"), exports);
|
|
59
|
+
__exportStar(require("./class"), exports);
|
|
60
|
+
__exportStar(require("./resolve"), exports);
|
|
61
|
+
__exportStar(require("./concat"), exports);
|
|
62
|
+
__exportStar(require("./utils"), exports);
|
|
63
|
+
__exportStar(require("./ExtRegExp"), exports);
|
|
64
|
+
__exportStar(require("./flag-transformer"), exports);
|
|
65
|
+
__exportStar(require("./clone"), exports);
|
|
66
|
+
__exportStar(require("./constants"), exports);
|
|
67
|
+
__exportStar(require("./walker"), exports);
|
|
68
|
+
__exportStar(require("./lexer"), exports);
|
package/dist/resolve.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import * as t from "./types";
|
|
2
|
+
export type ResolveRGXTokenOptions = {
|
|
3
|
+
groupWrap?: boolean;
|
|
4
|
+
topLevel?: boolean;
|
|
5
|
+
currentFlags?: string;
|
|
6
|
+
};
|
|
2
7
|
export declare function escapeRegex(value: string): t.ValidRegexString;
|
|
3
|
-
export declare function resolveRGXToken(token: t.RGXToken, groupWrap
|
|
8
|
+
export declare function resolveRGXToken(token: t.RGXToken, { groupWrap, topLevel, currentFlags }?: ResolveRGXTokenOptions): t.ValidRegexString;
|
package/dist/resolve.js
CHANGED
|
@@ -58,7 +58,7 @@ function localizableVanillaRegexFlagDiff(prev, next) {
|
|
|
58
58
|
return `${added}`;
|
|
59
59
|
return `${added}-${removed}`;
|
|
60
60
|
}
|
|
61
|
-
function resolveRGXToken(token, groupWrap = true, topLevel = true, currentFlags = '') {
|
|
61
|
+
function resolveRGXToken(token, { groupWrap = true, topLevel = true, currentFlags = '' } = {}) {
|
|
62
62
|
(0, ExtRegExp_1.assertValidRegexFlags)(currentFlags);
|
|
63
63
|
const innerResolve = () => {
|
|
64
64
|
if (tg.isRGXNoOpToken(token))
|
|
@@ -86,7 +86,7 @@ function resolveRGXToken(token, groupWrap = true, topLevel = true, currentFlags
|
|
|
86
86
|
return String(token.toRgx());
|
|
87
87
|
// The top-level group-wrapping preference propogates to a direct convertible token, but after that
|
|
88
88
|
// the preference falls back to true whenever a token doesn't explicitly specify a preference.
|
|
89
|
-
return resolveRGXToken(token.toRgx(), token.rgxGroupWrap ?? (topLevel ? groupWrap : true), false, currentFlags);
|
|
89
|
+
return resolveRGXToken(token.toRgx(), { groupWrap: token.rgxGroupWrap ?? (topLevel ? groupWrap : true), topLevel: false, currentFlags });
|
|
90
90
|
}
|
|
91
91
|
// Interpret arrays as unions
|
|
92
92
|
if (tg.isRGXArrayToken(token, false)) {
|
|
@@ -97,11 +97,11 @@ function resolveRGXToken(token, groupWrap = true, topLevel = true, currentFlags
|
|
|
97
97
|
token = [...(0, class_1.removeRgxUnionDuplicates)(...token)];
|
|
98
98
|
// Don't preserve group wrapping preference for the recursive calls
|
|
99
99
|
if (groupWrap)
|
|
100
|
-
return '(?:' + token.map(t => resolveRGXToken(t, true, false, currentFlags)).join('|') + ')';
|
|
100
|
+
return '(?:' + token.map(t => resolveRGXToken(t, { groupWrap: true, topLevel: false, currentFlags })).join('|') + ')';
|
|
101
101
|
else
|
|
102
|
-
return token.map(t => resolveRGXToken(t, true, false, currentFlags)).join('|');
|
|
102
|
+
return token.map(t => resolveRGXToken(t, { groupWrap: true, topLevel: false, currentFlags })).join('|');
|
|
103
103
|
}
|
|
104
|
-
return resolveRGXToken(token[0], true, false, currentFlags);
|
|
104
|
+
return resolveRGXToken(token[0], { groupWrap: true, topLevel: false, currentFlags });
|
|
105
105
|
}
|
|
106
106
|
// Ignoring this line since it should be impossible to reach if the types are correct, but we need it to satisfy the return type
|
|
107
107
|
/* istanbul ignore next */
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRGXBounds = createRGXBounds;
|
|
4
|
+
const typeGuards_1 = require("../typeGuards");
|
|
5
|
+
const createRegex_1 = require("./createRegex");
|
|
6
|
+
const resolve_1 = require("../resolve");
|
|
7
|
+
function convertNoGroupWrap(token) {
|
|
8
|
+
const boundPart = { rgxGroupWrap: false };
|
|
9
|
+
if ((0, typeGuards_1.isRGXConvertibleToken)(token)) {
|
|
10
|
+
return { ...token, ...boundPart };
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return token;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function convertToBound(token) {
|
|
17
|
+
// Bounds are not groups themselves, cannot be repeated (since they don't consume characters)
|
|
18
|
+
// and should never be group wrapped
|
|
19
|
+
const boundPart = { rgxGroupWrap: false, rgxIsGroup: false, rgxIsRepeatable: false };
|
|
20
|
+
return {
|
|
21
|
+
...boundPart,
|
|
22
|
+
toRgx: () => token
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function createRGXBounds(before, after, flags = "") {
|
|
26
|
+
const resolvedBefore = (0, resolve_1.resolveRGXToken)(convertNoGroupWrap(before), { groupWrap: false, currentFlags: flags });
|
|
27
|
+
const resolvedAfter = (0, resolve_1.resolveRGXToken)(convertNoGroupWrap(after), { groupWrap: false, currentFlags: flags });
|
|
28
|
+
const startBound = convertToBound((0, createRegex_1.createRegex)(`(?<=${resolvedBefore})(?=${resolvedAfter})`, flags, true));
|
|
29
|
+
const endBound = convertToBound((0, createRegex_1.createRegex)(`(?<=${resolvedAfter})(?=${resolvedBefore})`, flags, true));
|
|
30
|
+
return [startBound, endBound];
|
|
31
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -20,3 +20,4 @@ __exportStar(require("./regexWithFlags"), exports);
|
|
|
20
20
|
__exportStar(require("./normalizeRegexFlags"), exports);
|
|
21
21
|
__exportStar(require("./createRGXClassGuardFunction"), exports);
|
|
22
22
|
__exportStar(require("./createRegex"), exports);
|
|
23
|
+
__exportStar(require("./createRGXBounds"), exports);
|