alemonjs 2.1.11 → 2.1.12
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/utils.d.ts +8 -4
- package/lib/utils.js +36 -8
- package/package.json +1 -1
package/lib/utils.d.ts
CHANGED
|
@@ -22,8 +22,12 @@ export declare const getPublicIP: (options?: Options & {
|
|
|
22
22
|
force?: boolean;
|
|
23
23
|
}) => Promise<string>;
|
|
24
24
|
export declare class Regular extends RegExp {
|
|
25
|
-
static
|
|
26
|
-
static
|
|
27
|
-
or(...
|
|
28
|
-
and(...
|
|
25
|
+
static create(pattern: RegExp | string, flags?: string): Regular;
|
|
26
|
+
private static mergeFlags;
|
|
27
|
+
static or(...regulars: RegExp[]): Regular;
|
|
28
|
+
static and(...regulars: RegExp[]): Regular;
|
|
29
|
+
or(...regulars: RegExp[]): Regular;
|
|
30
|
+
and(...regulars: RegExp[]): Regular;
|
|
31
|
+
withFlags(flags: 'i' | 'g' | 'm' | 's' | 'u' | 'y'): Regular;
|
|
32
|
+
withoutFlags(flagsToRemove: 'i' | 'g' | 'm' | 's' | 'u' | 'y'): Regular;
|
|
29
33
|
}
|
package/lib/utils.js
CHANGED
|
@@ -137,17 +137,45 @@ const getPublicIP = async (options = {}) => {
|
|
|
137
137
|
});
|
|
138
138
|
};
|
|
139
139
|
class Regular extends RegExp {
|
|
140
|
-
static
|
|
141
|
-
return new Regular(
|
|
140
|
+
static create(pattern, flags) {
|
|
141
|
+
return new Regular(pattern, flags);
|
|
142
|
+
}
|
|
143
|
+
static mergeFlags(...flags) {
|
|
144
|
+
const flagSet = new Set();
|
|
145
|
+
for (const flagStr of flags) {
|
|
146
|
+
for (const char of flagStr) {
|
|
147
|
+
flagSet.add(char);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return Array.from(flagSet).sort().join('');
|
|
151
|
+
}
|
|
152
|
+
static or(...regulars) {
|
|
153
|
+
const source = regulars.map(reg => `(?:${reg.source})`).join('|');
|
|
154
|
+
const flags = Regular.mergeFlags(...regulars.map(reg => reg.flags));
|
|
155
|
+
return new Regular(`(?:${source})`, flags);
|
|
142
156
|
}
|
|
143
|
-
static and(...
|
|
144
|
-
|
|
157
|
+
static and(...regulars) {
|
|
158
|
+
const lookAHeads = regulars.map(reg => `(?=.*${reg.source})`).join('');
|
|
159
|
+
const flags = Regular.mergeFlags(...regulars.map(reg => reg.flags));
|
|
160
|
+
return new Regular(`${lookAHeads}.*`, flags);
|
|
145
161
|
}
|
|
146
|
-
or(...
|
|
147
|
-
return Regular.or(this, ...
|
|
162
|
+
or(...regulars) {
|
|
163
|
+
return Regular.or(this, ...regulars);
|
|
148
164
|
}
|
|
149
|
-
and(...
|
|
150
|
-
return Regular.and(this, ...
|
|
165
|
+
and(...regulars) {
|
|
166
|
+
return Regular.and(this, ...regulars);
|
|
167
|
+
}
|
|
168
|
+
withFlags(flags) {
|
|
169
|
+
const mergedFlags = Regular.mergeFlags(this.flags, flags);
|
|
170
|
+
return new Regular(this.source, mergedFlags);
|
|
171
|
+
}
|
|
172
|
+
withoutFlags(flagsToRemove) {
|
|
173
|
+
const currentFlagsSet = new Set(this.flags);
|
|
174
|
+
for (const char of flagsToRemove) {
|
|
175
|
+
currentFlagsSet.delete(char);
|
|
176
|
+
}
|
|
177
|
+
const newFlags = Array.from(currentFlagsSet).sort().join('');
|
|
178
|
+
return new Regular(this.source, newFlags);
|
|
151
179
|
}
|
|
152
180
|
}
|
|
153
181
|
|