@zoodogood/utils 1.2.1-change.1449 → 1.2.4-change.1476
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/lib/primitives/CliParser.d.ts +3 -0
- package/lib/primitives/CliParser.js +19 -5
- package/package.json +1 -1
- package/readme.md +3 -0
|
@@ -20,8 +20,10 @@ declare class BracketsManager extends BracketsParser {
|
|
|
20
20
|
};
|
|
21
21
|
toStringGroup(index: number): string;
|
|
22
22
|
findPrimaryGroups(context: BracketsNamespace.Context): BracketsNamespace.GroupElement[];
|
|
23
|
+
groupStampRegex: RegExp;
|
|
23
24
|
findBracketStamp(text: string): RegExpMatchArray | null;
|
|
24
25
|
processBracketGroupFromStringStamp(raw: string): BracketsNamespace.GroupElement | null;
|
|
26
|
+
replaceBracketsStamps(text: string, replacer?: (group: BracketsNamespace.GroupElement) => string): string;
|
|
25
27
|
}
|
|
26
28
|
interface IFlagCapture {
|
|
27
29
|
name?: string;
|
|
@@ -38,6 +40,7 @@ declare class CapturedContent {
|
|
|
38
40
|
content: TCaptureValue;
|
|
39
41
|
context?: CliParserRunContext;
|
|
40
42
|
constructor(content: TCaptureValue);
|
|
43
|
+
isFlagMatchArray(): boolean;
|
|
41
44
|
setContextInstance(context: CapturedContent["context"]): this;
|
|
42
45
|
isRegexMatchArray(): boolean;
|
|
43
46
|
isString(): boolean;
|
|
@@ -4,6 +4,7 @@ class BracketsManager extends BracketsParser {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
super();
|
|
6
6
|
this.primary = [];
|
|
7
|
+
this.groupStampRegex = /\[Group\*(?<index>\d+)\]/;
|
|
7
8
|
this.addBracketVariant(...BracketsParser.defaultBracketVariants);
|
|
8
9
|
}
|
|
9
10
|
parse() {
|
|
@@ -27,7 +28,7 @@ class BracketsManager extends BracketsParser {
|
|
|
27
28
|
return context.groups.filter((group) => group.depth === 0);
|
|
28
29
|
}
|
|
29
30
|
findBracketStamp(text) {
|
|
30
|
-
return text.trim().match(
|
|
31
|
+
return text.trim().match(RegExp(`^${this.groupStampRegex.source}$`));
|
|
31
32
|
}
|
|
32
33
|
processBracketGroupFromStringStamp(raw) {
|
|
33
34
|
const match = this.findBracketStamp(raw);
|
|
@@ -37,6 +38,9 @@ class BracketsManager extends BracketsParser {
|
|
|
37
38
|
const { index } = match.groups;
|
|
38
39
|
return this.primary.at(+index);
|
|
39
40
|
}
|
|
41
|
+
replaceBracketsStamps(text, replacer = (group) => String(group === null || group === void 0 ? void 0 : group.content)) {
|
|
42
|
+
return text.replaceAll(RegExp(this.groupStampRegex, "g"), (full) => replacer(this.processBracketGroupFromStringStamp(full)));
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
class FlagsManager {
|
|
42
46
|
captureResidueFlags(context) {
|
|
@@ -51,15 +55,16 @@ class FlagsManager {
|
|
|
51
55
|
captureFlags(flags, context) {
|
|
52
56
|
for (const { name, capture, expectValue } of flags) {
|
|
53
57
|
for (const flag of capture) {
|
|
54
|
-
const regex = `(?<=^|\\s)${flag}${expectValue ? "(?:(?:\\s
|
|
58
|
+
const regex = `(?<=^|\\s)${flag}${expectValue ? "(?:(?:\\s+(?!-)|=)(?<value>[^\\s]+))" : ""}`;
|
|
55
59
|
const { parser } = context;
|
|
56
60
|
const captureName = name || flag;
|
|
57
61
|
const match = parser.replaceByMatch(RegExp(regex, "i"));
|
|
58
62
|
if (!match) {
|
|
59
|
-
context.captures.
|
|
63
|
+
!context.captures.has(`${captureName}`) &&
|
|
64
|
+
context.captures.set(`${captureName}`, null);
|
|
60
65
|
continue;
|
|
61
66
|
}
|
|
62
|
-
context.captures.set(`${captureName}`, new
|
|
67
|
+
context.captures.set(`${captureName}`, new CapturedContentFlagMatchArray(match).setContextInstance(context));
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
return this;
|
|
@@ -69,6 +74,9 @@ class CapturedContent {
|
|
|
69
74
|
constructor(content) {
|
|
70
75
|
this.content = content;
|
|
71
76
|
}
|
|
77
|
+
isFlagMatchArray() {
|
|
78
|
+
return this instanceof CapturedContentFlagMatchArray;
|
|
79
|
+
}
|
|
72
80
|
setContextInstance(context) {
|
|
73
81
|
this.context = context;
|
|
74
82
|
return this;
|
|
@@ -140,7 +148,7 @@ class CapturedContent {
|
|
|
140
148
|
content = this.regexArrayOrStringToString(content);
|
|
141
149
|
}
|
|
142
150
|
if (context && this.contentIsBracketGroupStamp(content, context)) {
|
|
143
|
-
return ((_a = this.contentToGroupElement(content, context)) === null || _a === void 0 ? void 0 : _a.
|
|
151
|
+
return ((_a = this.contentToGroupElement(content, context)) === null || _a === void 0 ? void 0 : _a.content) || content;
|
|
144
152
|
}
|
|
145
153
|
return content;
|
|
146
154
|
})(content);
|
|
@@ -150,6 +158,12 @@ class CapturedContent {
|
|
|
150
158
|
return value;
|
|
151
159
|
}
|
|
152
160
|
}
|
|
161
|
+
class CapturedContentFlagMatchArray extends CapturedContent {
|
|
162
|
+
valueOfFlag() {
|
|
163
|
+
var _a;
|
|
164
|
+
return ((_a = this.content.groups) === null || _a === void 0 ? void 0 : _a.value) || null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
153
167
|
class CliParserRunContext {
|
|
154
168
|
constructor(parser) {
|
|
155
169
|
this.input = "";
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -3,6 +3,9 @@ A set of utilities in different directions for primitive data types.
|
|
|
3
3
|
# Docs:
|
|
4
4
|
https://zoodogood.github.io/utils/public
|
|
5
5
|
|
|
6
|
+
> [!IMPORTANT]
|
|
7
|
+
> If you are using this library, please contact me urgently. As long as I am the only user of my library, I allow myself to change its components on the fly, breaking backwards compatibility.
|
|
8
|
+
|
|
6
9
|
```js
|
|
7
10
|
export { ending } from '@zoodogood/utils/primitives';
|
|
8
11
|
```
|