@ls-stack/utils 3.61.0 → 3.62.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/dist/regexUtils.cjs +60 -0
- package/dist/regexUtils.d.cts +17 -0
- package/dist/regexUtils.d.ts +17 -0
- package/dist/regexUtils.js +33 -0
- package/package.json +5 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/regexUtils.ts
|
|
21
|
+
var regexUtils_exports = {};
|
|
22
|
+
__export(regexUtils_exports, {
|
|
23
|
+
escapeRegExp: () => escapeRegExp,
|
|
24
|
+
getRegexMatchAll: () => getRegexMatchAll,
|
|
25
|
+
getRegexMatches: () => getRegexMatches
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(regexUtils_exports);
|
|
28
|
+
function getRegexMatches(string, regex) {
|
|
29
|
+
const [fullMatch, ...groups] = regex.exec(string) || [void 0];
|
|
30
|
+
return { groups, fullMatch };
|
|
31
|
+
}
|
|
32
|
+
function* getRegexMatchAll(str, regexp) {
|
|
33
|
+
const flags = regexp.global ? regexp.flags : `${regexp.flags}g`;
|
|
34
|
+
const re = new RegExp(regexp, flags);
|
|
35
|
+
let match;
|
|
36
|
+
let lastIndex = 0;
|
|
37
|
+
while (match = re.exec(str)) {
|
|
38
|
+
const [fullMatch, ...groups] = match;
|
|
39
|
+
const prevLastIndex = lastIndex;
|
|
40
|
+
lastIndex = re.lastIndex;
|
|
41
|
+
yield {
|
|
42
|
+
groups,
|
|
43
|
+
fullMatch,
|
|
44
|
+
namedGroups: match.groups,
|
|
45
|
+
start: match.index,
|
|
46
|
+
end: lastIndex,
|
|
47
|
+
prevEnd: prevLastIndex
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
var SPECIAL_REGEX_CHARS = /[.*+?^${}()|[\]\\]/g;
|
|
52
|
+
function escapeRegExp(value) {
|
|
53
|
+
return value.replace(SPECIAL_REGEX_CHARS, "\\$&");
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
escapeRegExp,
|
|
58
|
+
getRegexMatchAll,
|
|
59
|
+
getRegexMatches
|
|
60
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare function getRegexMatches(string: string, regex: RegExp): {
|
|
2
|
+
groups: (string | undefined)[];
|
|
3
|
+
fullMatch: string | undefined;
|
|
4
|
+
};
|
|
5
|
+
declare function getRegexMatchAll(str: string, regexp: RegExp): Generator<{
|
|
6
|
+
groups: (string | undefined)[];
|
|
7
|
+
fullMatch: string;
|
|
8
|
+
namedGroups: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
} | undefined;
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
prevEnd: number;
|
|
14
|
+
}, void, unknown>;
|
|
15
|
+
declare function escapeRegExp(value: string): string;
|
|
16
|
+
|
|
17
|
+
export { escapeRegExp, getRegexMatchAll, getRegexMatches };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare function getRegexMatches(string: string, regex: RegExp): {
|
|
2
|
+
groups: (string | undefined)[];
|
|
3
|
+
fullMatch: string | undefined;
|
|
4
|
+
};
|
|
5
|
+
declare function getRegexMatchAll(str: string, regexp: RegExp): Generator<{
|
|
6
|
+
groups: (string | undefined)[];
|
|
7
|
+
fullMatch: string;
|
|
8
|
+
namedGroups: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
} | undefined;
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
prevEnd: number;
|
|
14
|
+
}, void, unknown>;
|
|
15
|
+
declare function escapeRegExp(value: string): string;
|
|
16
|
+
|
|
17
|
+
export { escapeRegExp, getRegexMatchAll, getRegexMatches };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/regexUtils.ts
|
|
2
|
+
function getRegexMatches(string, regex) {
|
|
3
|
+
const [fullMatch, ...groups] = regex.exec(string) || [void 0];
|
|
4
|
+
return { groups, fullMatch };
|
|
5
|
+
}
|
|
6
|
+
function* getRegexMatchAll(str, regexp) {
|
|
7
|
+
const flags = regexp.global ? regexp.flags : `${regexp.flags}g`;
|
|
8
|
+
const re = new RegExp(regexp, flags);
|
|
9
|
+
let match;
|
|
10
|
+
let lastIndex = 0;
|
|
11
|
+
while (match = re.exec(str)) {
|
|
12
|
+
const [fullMatch, ...groups] = match;
|
|
13
|
+
const prevLastIndex = lastIndex;
|
|
14
|
+
lastIndex = re.lastIndex;
|
|
15
|
+
yield {
|
|
16
|
+
groups,
|
|
17
|
+
fullMatch,
|
|
18
|
+
namedGroups: match.groups,
|
|
19
|
+
start: match.index,
|
|
20
|
+
end: lastIndex,
|
|
21
|
+
prevEnd: prevLastIndex
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
var SPECIAL_REGEX_CHARS = /[.*+?^${}()|[\]\\]/g;
|
|
26
|
+
function escapeRegExp(value) {
|
|
27
|
+
return value.replace(SPECIAL_REGEX_CHARS, "\\$&");
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
escapeRegExp,
|
|
31
|
+
getRegexMatchAll,
|
|
32
|
+
getRegexMatches
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Universal TypeScript utilities for browser and Node.js",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.62.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -152,6 +152,10 @@
|
|
|
152
152
|
"import": "./dist/promiseUtils.js",
|
|
153
153
|
"require": "./dist/promiseUtils.cjs"
|
|
154
154
|
},
|
|
155
|
+
"./regexUtils": {
|
|
156
|
+
"import": "./dist/regexUtils.js",
|
|
157
|
+
"require": "./dist/regexUtils.cjs"
|
|
158
|
+
},
|
|
155
159
|
"./retryOnError": {
|
|
156
160
|
"import": "./dist/retryOnError.js",
|
|
157
161
|
"require": "./dist/retryOnError.cjs"
|