@isopodlabs/utilities 1.5.5 → 1.5.7
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 -1
- package/dist/algorithm.d.ts +2 -1
- package/dist/algorithm.js +5 -1
- package/dist/array.d.ts +6 -0
- package/dist/array.js +57 -0
- package/dist/async.d.ts +4 -0
- package/dist/async.js +65 -0
- package/dist/bits.d.ts +111 -0
- package/dist/bits.js +617 -0
- package/dist/glob.d.ts +4 -0
- package/dist/glob.js +112 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +17 -4
- package/dist/insensitive.d.ts +1 -1
- package/dist/insensitive.js +2 -10
- package/dist/iterator.d.ts +1 -12
- package/dist/iterator.js +37 -94
- package/dist/object.d.ts +5 -2
- package/dist/object.js +18 -5
- package/dist/regex.d.ts +103 -0
- package/dist/regex.js +1044 -0
- package/dist/regexp.d.ts +90 -0
- package/dist/regexp.js +659 -0
- package/dist/string.d.ts +0 -4
- package/dist/string.js +0 -107
- package/package.json +2 -3
package/dist/glob.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseGlob = parseGlob;
|
|
4
|
+
exports.anchoredRe = anchoredRe;
|
|
5
|
+
exports.globToRe = globToRe;
|
|
6
|
+
exports.globToReMulti = globToReMulti;
|
|
7
|
+
const posixClasses = {
|
|
8
|
+
alnum: '\\p{L}\\p{Nl}\\p{Nd}',
|
|
9
|
+
alpha: '\\p{L}\\p{Nl}',
|
|
10
|
+
ascii: '\\x00-\\x7f',
|
|
11
|
+
blank: '\\p{Zs}\\t',
|
|
12
|
+
cntrl: '\\p{Cc}',
|
|
13
|
+
digit: '\\p{Nd}',
|
|
14
|
+
graph: '^\\p{Z}\\p{C}',
|
|
15
|
+
lower: '\\p{Ll}',
|
|
16
|
+
print: '\\p{C}',
|
|
17
|
+
punct: '\\p{P}',
|
|
18
|
+
space: '\\p{Z}\\t\\r\\n\\v\\f',
|
|
19
|
+
upper: '\\p{Lu}',
|
|
20
|
+
word: '\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}',
|
|
21
|
+
xdigit: 'A-Fa-f0-9',
|
|
22
|
+
};
|
|
23
|
+
//-----------------------------------------------------------------------------
|
|
24
|
+
// Glob pattern to regex
|
|
25
|
+
//-----------------------------------------------------------------------------
|
|
26
|
+
function parseGlob(glob) {
|
|
27
|
+
let result = '';
|
|
28
|
+
let depth = 0;
|
|
29
|
+
for (let i = 0; i < glob.length; ++i) {
|
|
30
|
+
let c = glob[i];
|
|
31
|
+
switch (c) {
|
|
32
|
+
case '\\':
|
|
33
|
+
c = glob[++i];
|
|
34
|
+
if ('*?+.,^$()|[]a-zA-Z'.includes(c))
|
|
35
|
+
result += '\\';
|
|
36
|
+
break;
|
|
37
|
+
case '*':
|
|
38
|
+
if (glob[i + 1] === '*') {
|
|
39
|
+
result += '.*';
|
|
40
|
+
++i;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
result += '[^/]*';
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
46
|
+
case '?':
|
|
47
|
+
c = '.';
|
|
48
|
+
break;
|
|
49
|
+
case '+':
|
|
50
|
+
case '.':
|
|
51
|
+
case '^':
|
|
52
|
+
case '$':
|
|
53
|
+
case '(':
|
|
54
|
+
case ')':
|
|
55
|
+
case '|':
|
|
56
|
+
result += `\\`;
|
|
57
|
+
break;
|
|
58
|
+
case '[': {
|
|
59
|
+
const end = glob.indexOf(']', i + 1);
|
|
60
|
+
if (end > i) {
|
|
61
|
+
const next = glob[i + 1];
|
|
62
|
+
if (next === ':' && glob[end - 1] === ':') {
|
|
63
|
+
const p = posixClasses[glob.slice(i + 2, end - 1)];
|
|
64
|
+
if (p) {
|
|
65
|
+
result += `[${p}]`;
|
|
66
|
+
i = end;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
console.log(`Warning: Unknown POSIX class ${glob.slice(i + 2, end - 1)} in glob pattern ${glob}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const neg = next === '!' || next === '^';
|
|
74
|
+
result += `[${neg ? '^' : ''}${glob.slice(neg ? i + 2 : i + 1, end)}]`;
|
|
75
|
+
i = end;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
result += '\\';
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case '{':
|
|
82
|
+
++depth;
|
|
83
|
+
c = '(';
|
|
84
|
+
break;
|
|
85
|
+
case '}':
|
|
86
|
+
if (depth > 0) {
|
|
87
|
+
--depth;
|
|
88
|
+
c = ')';
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
case ',':
|
|
92
|
+
if (depth > 0)
|
|
93
|
+
c = '|';
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
result += c;
|
|
97
|
+
}
|
|
98
|
+
if (depth > 0) {
|
|
99
|
+
console.log(`Warning: Unmatched { in glob pattern ${glob}`);
|
|
100
|
+
result += ')'.repeat(depth);
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
function anchoredRe(re) {
|
|
105
|
+
return new RegExp(`^${re}$`);
|
|
106
|
+
}
|
|
107
|
+
function globToRe(glob) {
|
|
108
|
+
return anchoredRe(parseGlob(glob));
|
|
109
|
+
}
|
|
110
|
+
function globToReMulti(globs) {
|
|
111
|
+
return anchoredRe(globs.map(parseGlob).join('|'));
|
|
112
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,10 @@ export * from './object';
|
|
|
2
2
|
export * from './iterator';
|
|
3
3
|
export * from './string';
|
|
4
4
|
export * from './algorithm';
|
|
5
|
+
export * from './glob';
|
|
6
|
+
export * as bits from './bits';
|
|
7
|
+
export * as array from './array';
|
|
8
|
+
export * as async from './async';
|
|
5
9
|
export * as insensitive from './insensitive';
|
|
10
|
+
export declare function parallel(...fns: (() => any)[]): Promise<any[]>;
|
|
11
|
+
export declare function serial(...fns: (() => any)[]): Promise<any[]>;
|
package/dist/index.js
CHANGED
|
@@ -15,9 +15,6 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
-
};
|
|
21
18
|
var __importStar = (this && this.__importStar) || (function () {
|
|
22
19
|
var ownKeys = function(o) {
|
|
23
20
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
@@ -35,10 +32,26 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
32
|
return result;
|
|
36
33
|
};
|
|
37
34
|
})();
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.insensitive = void 0;
|
|
39
|
+
exports.insensitive = exports.async = exports.array = exports.bits = void 0;
|
|
40
|
+
exports.parallel = parallel;
|
|
41
|
+
exports.serial = serial;
|
|
42
|
+
const async = __importStar(require("./async"));
|
|
40
43
|
__exportStar(require("./object"), exports);
|
|
41
44
|
__exportStar(require("./iterator"), exports);
|
|
42
45
|
__exportStar(require("./string"), exports);
|
|
43
46
|
__exportStar(require("./algorithm"), exports);
|
|
47
|
+
__exportStar(require("./glob"), exports);
|
|
48
|
+
exports.bits = __importStar(require("./bits"));
|
|
49
|
+
exports.array = __importStar(require("./array"));
|
|
50
|
+
exports.async = __importStar(require("./async"));
|
|
44
51
|
exports.insensitive = __importStar(require("./insensitive"));
|
|
52
|
+
async function parallel(...fns) {
|
|
53
|
+
return async.map(fns, f => f());
|
|
54
|
+
}
|
|
55
|
+
async function serial(...fns) {
|
|
56
|
+
return async.mapSerial(fns, f => f());
|
|
57
|
+
}
|
package/dist/insensitive.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare class CaseInsensitiveString2 extends CaseInsensitiveString {
|
|
|
19
19
|
}
|
|
20
20
|
export declare function String(value: string): CaseInsensitiveString;
|
|
21
21
|
export declare function String2(value: string): CaseInsensitiveString2;
|
|
22
|
-
export declare function compare(a: string, b: string): 0 | 1 | -1;
|
|
22
|
+
export declare function compare(a: string | CaseInsensitiveString, b: string | CaseInsensitiveString): 0 | 1 | -1;
|
|
23
23
|
export declare function Record<T>(obj: Record<string, T>): Record<string, T>;
|
|
24
24
|
export declare function Record2<T>(obj: Record<string, T>): Record<string, T>;
|
|
25
25
|
export declare class Map<T> extends globalThis.Map<string, T> {
|
package/dist/insensitive.js
CHANGED
|
@@ -60,11 +60,7 @@ function Record2(obj) {
|
|
|
60
60
|
}
|
|
61
61
|
class Map extends globalThis.Map {
|
|
62
62
|
constructor(entries) {
|
|
63
|
-
super();
|
|
64
|
-
if (entries) {
|
|
65
|
-
for (const [key, value] of entries)
|
|
66
|
-
this.set(key, value);
|
|
67
|
-
}
|
|
63
|
+
super(Array.from(entries || []).map(([k, v]) => [k.toUpperCase(), v]));
|
|
68
64
|
}
|
|
69
65
|
delete(key) { return super.delete(key.toUpperCase()); }
|
|
70
66
|
get(key) { return super.get(key.toUpperCase()); }
|
|
@@ -74,11 +70,7 @@ class Map extends globalThis.Map {
|
|
|
74
70
|
exports.Map = Map;
|
|
75
71
|
class Set extends globalThis.Set {
|
|
76
72
|
constructor(values) {
|
|
77
|
-
super();
|
|
78
|
-
if (values) {
|
|
79
|
-
for (const value of values)
|
|
80
|
-
this.add(value);
|
|
81
|
-
}
|
|
73
|
+
super(Array.from(values || []).map(v => v.toUpperCase()));
|
|
82
74
|
}
|
|
83
75
|
add(value) { return super.add(value.toUpperCase()); }
|
|
84
76
|
delete(value) { return super.delete(value.toUpperCase()); }
|
package/dist/iterator.d.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
export type SpreadType<T> = T extends Iterable<infer U> ? U[] : never;
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function arrayCompare<T>(arr1: T[], arr2: T[]): number;
|
|
4
|
-
export declare function arrayEqual<T>(arr1: T[], arr2: T[]): boolean;
|
|
5
|
-
export declare function arrayRotate<T>(array: T[], start: number, end: number, shift: number): void;
|
|
6
|
-
export declare function arrayReverse<T>(array: T[], start: number, end: number): void;
|
|
7
|
-
export declare function arrayMake<T>(n: number, constructor: new () => T): T[];
|
|
2
|
+
export declare function remove<T>(iterable: Iterable<T>, item: T): boolean;
|
|
8
3
|
export declare function forEach<T>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => void): void;
|
|
9
4
|
export declare function find<T>(iterable: Iterable<T> | undefined, func: (v: T) => boolean): T | undefined;
|
|
10
5
|
export declare function map<T, U>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => U): U[];
|
|
11
6
|
export declare function reduce<T, U>(iterable: Iterable<T>, func: (acc: U, v: T, i: number, iterable: Iterable<T>) => U, initialValue: U): U;
|
|
12
7
|
export declare function filter<T>(iterable: Iterable<T>, func: (v: T, i: number) => unknown): T[];
|
|
13
|
-
export declare function asyncMap<T, U>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => Promise<U>): Promise<U[]>;
|
|
14
|
-
export declare function asyncMapSerial<T, U>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => Promise<U>): Promise<U[]>;
|
|
15
|
-
export declare function asyncReduce<T, U>(iterable: Iterable<T>, func: (acc: U, v: T, i: number, iterable: Iterable<T>) => Promise<U>, initialValue: U): Promise<U>;
|
|
16
|
-
export declare function asyncFilter<T>(iterable: Iterable<T>, func: (v: T) => Promise<unknown>): Promise<T[]>;
|
|
17
|
-
export declare function parallel(...fns: (() => any)[]): Promise<any[]>;
|
|
18
|
-
export declare function serial(...fns: (() => any)[]): Promise<any[]>;
|
package/dist/iterator.js
CHANGED
|
@@ -1,67 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.arrayCompare = arrayCompare;
|
|
5
|
-
exports.arrayEqual = arrayEqual;
|
|
6
|
-
exports.arrayRotate = arrayRotate;
|
|
7
|
-
exports.arrayReverse = arrayReverse;
|
|
8
|
-
exports.arrayMake = arrayMake;
|
|
36
|
+
exports.remove = remove;
|
|
9
37
|
exports.forEach = forEach;
|
|
10
38
|
exports.find = find;
|
|
11
39
|
exports.map = map;
|
|
12
40
|
exports.reduce = reduce;
|
|
13
41
|
exports.filter = filter;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports.asyncFilter = asyncFilter;
|
|
18
|
-
exports.parallel = parallel;
|
|
19
|
-
exports.serial = serial;
|
|
20
|
-
const object_1 = require("./object");
|
|
21
|
-
//remove element of array
|
|
22
|
-
function arrayRemove(array, item) {
|
|
23
|
-
const index = array.indexOf(item);
|
|
24
|
-
if (index === -1)
|
|
25
|
-
return false;
|
|
26
|
-
array.splice(index, 1);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
function arrayCompare(arr1, arr2) {
|
|
30
|
-
const length = Math.min(arr1.length, arr2.length);
|
|
31
|
-
for (let i = 0; i < length; i++) {
|
|
32
|
-
const r = (0, object_1.compare)(arr1[i], arr2[i]);
|
|
33
|
-
if (r)
|
|
34
|
-
return r;
|
|
35
|
-
}
|
|
36
|
-
return arr1.length - arr2.length;
|
|
37
|
-
}
|
|
38
|
-
function arrayEqual(arr1, arr2) {
|
|
39
|
-
if (arr1.length !== arr2.length)
|
|
40
|
-
return false;
|
|
41
|
-
for (let i = 0; i < arr1.length; i++) {
|
|
42
|
-
if (arr1[i] !== arr2[i])
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
function arrayRotate(array, start, end, shift) {
|
|
48
|
-
const length = end - start;
|
|
49
|
-
if (length > 1 && shift % length) {
|
|
50
|
-
shift = ((shift % length) + length) % length;
|
|
51
|
-
arrayReverse(array, start, end - 1);
|
|
52
|
-
arrayReverse(array, start, start + shift - 1);
|
|
53
|
-
arrayReverse(array, start + shift, end - 1);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function arrayReverse(array, start, end) {
|
|
57
|
-
while (start < end) {
|
|
58
|
-
[array[start], array[end]] = [array[end], array[start]];
|
|
59
|
-
start++;
|
|
60
|
-
end--;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function arrayMake(n, constructor) {
|
|
64
|
-
return Array.from({ length: n }, () => new constructor);
|
|
42
|
+
const array = __importStar(require("./array"));
|
|
43
|
+
function remove(iterable, item) {
|
|
44
|
+
return array.remove(Array.from(iterable), item);
|
|
65
45
|
}
|
|
66
46
|
function forEach(iterable, func) {
|
|
67
47
|
if (iterable) {
|
|
@@ -96,40 +76,3 @@ function filter(iterable, func) {
|
|
|
96
76
|
array.push(v);
|
|
97
77
|
return array;
|
|
98
78
|
}
|
|
99
|
-
async function asyncMap(iterable, func) {
|
|
100
|
-
return Promise.all(map(iterable, func));
|
|
101
|
-
}
|
|
102
|
-
async function asyncMapSerial(iterable, func) {
|
|
103
|
-
const results = [];
|
|
104
|
-
let i = 0;
|
|
105
|
-
for (const v of iterable || [])
|
|
106
|
-
results.push(await func(v, i++));
|
|
107
|
-
return results;
|
|
108
|
-
}
|
|
109
|
-
async function asyncReduce(iterable, func, initialValue) {
|
|
110
|
-
let i = 0;
|
|
111
|
-
let acc = initialValue;
|
|
112
|
-
for (const v of iterable)
|
|
113
|
-
acc = await func(acc, v, i++, iterable);
|
|
114
|
-
return acc;
|
|
115
|
-
/*
|
|
116
|
-
return reduce<T, Promise<U>>(
|
|
117
|
-
iterable,
|
|
118
|
-
async (promise, v, i, iterable) => func(await promise, v, i, iterable),
|
|
119
|
-
Promise.resolve(initialValue)
|
|
120
|
-
);
|
|
121
|
-
*/
|
|
122
|
-
}
|
|
123
|
-
async function asyncFilter(iterable, func) {
|
|
124
|
-
const filters = await Promise.all(map(iterable, func));
|
|
125
|
-
return filter(iterable, (_, i) => filters[i]);
|
|
126
|
-
}
|
|
127
|
-
async function parallel(...fns) {
|
|
128
|
-
return asyncMap(fns, f => f());
|
|
129
|
-
}
|
|
130
|
-
async function serial(...fns) {
|
|
131
|
-
const results = [];
|
|
132
|
-
for (const f of fns)
|
|
133
|
-
results.push(await f());
|
|
134
|
-
return results;
|
|
135
|
-
}
|
package/dist/object.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class Lazy<T> {
|
|
|
14
14
|
then<U>(this: T extends Promise<infer R> ? Lazy<T> : never, onFulfilled: (value: T extends Promise<infer R> ? R : never) => U): Promise<U>;
|
|
15
15
|
}
|
|
16
16
|
export declare class CallCombiner0 {
|
|
17
|
-
private timeout
|
|
17
|
+
private timeout?;
|
|
18
18
|
combine(delay: number, func: () => void): void;
|
|
19
19
|
pending(): boolean;
|
|
20
20
|
}
|
|
@@ -26,5 +26,8 @@ export declare class CallCombiner extends CallCombiner0 {
|
|
|
26
26
|
}
|
|
27
27
|
export declare function makeCache<T>(load: (key: string) => T): {
|
|
28
28
|
get: (fullpath: string) => T;
|
|
29
|
-
remove: (fullpath: string) =>
|
|
29
|
+
remove: (fullpath: string) => boolean;
|
|
30
|
+
clear: () => void;
|
|
30
31
|
};
|
|
32
|
+
export declare function union<T>(a: Set<T>, b: Set<T>): Set<T>;
|
|
33
|
+
export declare function difference<T>(a: Set<T>, b: Set<T>): [Set<T>, Set<T>];
|
package/dist/object.js
CHANGED
|
@@ -10,6 +10,8 @@ exports.compare = compare;
|
|
|
10
10
|
exports.reverse_compare = reverse_compare;
|
|
11
11
|
exports.reverse = reverse;
|
|
12
12
|
exports.makeCache = makeCache;
|
|
13
|
+
exports.union = union;
|
|
14
|
+
exports.difference = difference;
|
|
13
15
|
function mapObject(obj, func) {
|
|
14
16
|
return Object.fromEntries(Object.entries(obj).map(x => func(x)));
|
|
15
17
|
}
|
|
@@ -64,12 +66,12 @@ class Lazy {
|
|
|
64
66
|
}
|
|
65
67
|
exports.Lazy = Lazy;
|
|
66
68
|
class CallCombiner0 {
|
|
67
|
-
timeout
|
|
69
|
+
timeout;
|
|
68
70
|
combine(delay, func) {
|
|
69
71
|
if (this.timeout)
|
|
70
72
|
clearTimeout(this.timeout);
|
|
71
73
|
this.timeout = setTimeout(() => {
|
|
72
|
-
this.timeout =
|
|
74
|
+
this.timeout = undefined;
|
|
73
75
|
func();
|
|
74
76
|
}, delay);
|
|
75
77
|
}
|
|
@@ -99,8 +101,19 @@ function makeCache(load) {
|
|
|
99
101
|
cache[fullpath] = load(fullpath);
|
|
100
102
|
return cache[fullpath];
|
|
101
103
|
},
|
|
102
|
-
remove: (fullpath) =>
|
|
103
|
-
|
|
104
|
-
},
|
|
104
|
+
remove: (fullpath) => delete cache[fullpath],
|
|
105
|
+
clear: () => Object.keys(cache).forEach(k => delete cache[k]),
|
|
105
106
|
};
|
|
106
107
|
}
|
|
108
|
+
function union(a, b) {
|
|
109
|
+
return new Set([...a, ...b]);
|
|
110
|
+
}
|
|
111
|
+
function difference(a, b) {
|
|
112
|
+
const remaining = new Set(a);
|
|
113
|
+
const removed = new Set();
|
|
114
|
+
for (const item of b) {
|
|
115
|
+
if (remaining.delete(item))
|
|
116
|
+
removed.add(item);
|
|
117
|
+
}
|
|
118
|
+
return [remaining, removed];
|
|
119
|
+
}
|
package/dist/regex.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { SparseBits } from "./bits";
|
|
2
|
+
export declare class characterClass extends SparseBits {
|
|
3
|
+
type: 'class';
|
|
4
|
+
test(char: string): boolean;
|
|
5
|
+
mutable(): MutablecharacterClass;
|
|
6
|
+
isNegated(): boolean;
|
|
7
|
+
toString(): string;
|
|
8
|
+
}
|
|
9
|
+
declare class MutablecharacterClass extends characterClass {
|
|
10
|
+
setChar(char: string): void;
|
|
11
|
+
setString(c: string): this;
|
|
12
|
+
clearString(c: string): this;
|
|
13
|
+
}
|
|
14
|
+
export declare function range(from: string, to: string): MutablecharacterClass;
|
|
15
|
+
export declare function chars(chars: string): MutablecharacterClass;
|
|
16
|
+
export declare function union(...classes: characterClass[]): MutablecharacterClass;
|
|
17
|
+
export declare const any: characterClass;
|
|
18
|
+
export declare const digit: characterClass;
|
|
19
|
+
export declare const lower: characterClass;
|
|
20
|
+
export declare const upper: characterClass;
|
|
21
|
+
export declare const alpha: characterClass;
|
|
22
|
+
export declare const alnum: characterClass;
|
|
23
|
+
export declare const word: characterClass;
|
|
24
|
+
export declare const whitespace: characterClass;
|
|
25
|
+
export declare const hex: characterClass;
|
|
26
|
+
export declare const octal: characterClass;
|
|
27
|
+
export declare function text(c: string): string;
|
|
28
|
+
export declare function concatenation(parts: part[]): part[] | part;
|
|
29
|
+
interface alternation {
|
|
30
|
+
type: 'alt';
|
|
31
|
+
parts: part[];
|
|
32
|
+
}
|
|
33
|
+
export declare function alternation(parts: part[]): alternation | part;
|
|
34
|
+
type noncaptureOptions = 'ahead' | 'behind' | 'neg_ahead' | 'neg_behind' | 'atomic' | {
|
|
35
|
+
i?: boolean;
|
|
36
|
+
m?: boolean;
|
|
37
|
+
s?: boolean;
|
|
38
|
+
};
|
|
39
|
+
interface noncapture {
|
|
40
|
+
type: 'noncapture';
|
|
41
|
+
part: part;
|
|
42
|
+
options?: noncaptureOptions;
|
|
43
|
+
}
|
|
44
|
+
export declare function noncapture(part: part, options?: noncaptureOptions): noncapture;
|
|
45
|
+
export declare function lookAhead(part: part): noncapture;
|
|
46
|
+
export declare function negLookAhead(part: part): noncapture;
|
|
47
|
+
export declare function lookBehind(part: part): noncapture;
|
|
48
|
+
export declare function negLookBehind(part: part): noncapture;
|
|
49
|
+
interface capture {
|
|
50
|
+
type: 'capture';
|
|
51
|
+
name?: string;
|
|
52
|
+
part: part;
|
|
53
|
+
}
|
|
54
|
+
export declare function capture(part: part, name?: string): capture;
|
|
55
|
+
type quantifiedMod = 'greedy' | 'lazy' | 'possessive';
|
|
56
|
+
interface quantified {
|
|
57
|
+
type: 'quantified';
|
|
58
|
+
part: part;
|
|
59
|
+
min: number;
|
|
60
|
+
max: number;
|
|
61
|
+
mod: quantifiedMod;
|
|
62
|
+
}
|
|
63
|
+
export declare function repeatFrom(part: part, min: number, max?: number, mod?: quantifiedMod): quantified;
|
|
64
|
+
export declare function repeat(part: part, n: number, mod?: quantifiedMod): quantified;
|
|
65
|
+
export declare function zeroOrMore(part: part, mod?: quantifiedMod): quantified;
|
|
66
|
+
export declare function oneOrMore(part: part, mod?: quantifiedMod): quantified;
|
|
67
|
+
export declare function optional(part: part, mod?: quantifiedMod): quantified;
|
|
68
|
+
interface boundary {
|
|
69
|
+
type: 'wordbound' | 'nowordbound' | 'inputboundstart' | 'inputboundend';
|
|
70
|
+
}
|
|
71
|
+
export declare function boundary(type: boundary['type']): boundary;
|
|
72
|
+
export declare const wordBoundary: boundary;
|
|
73
|
+
export declare const nonWordBoundary: boundary;
|
|
74
|
+
export declare const startAnchor: boundary;
|
|
75
|
+
export declare const endAnchor: boundary;
|
|
76
|
+
interface reference {
|
|
77
|
+
type: 'reference';
|
|
78
|
+
value: number | string;
|
|
79
|
+
}
|
|
80
|
+
export declare function reference(value: number | string): reference;
|
|
81
|
+
export declare function anchored(part: part): part;
|
|
82
|
+
interface unicode {
|
|
83
|
+
type: 'unicode' | 'notunicode';
|
|
84
|
+
property: string;
|
|
85
|
+
}
|
|
86
|
+
type _part = alternation | noncapture | capture | characterClass | unicode | quantified | boundary | reference;
|
|
87
|
+
type part = string | part[] | _part;
|
|
88
|
+
export declare function parse(re: string, unicode?: boolean, extended?: boolean): part;
|
|
89
|
+
export declare function toRegExpString(part: part): string;
|
|
90
|
+
export declare function toRegExp(part: part, flags?: string): RegExp;
|
|
91
|
+
export declare function optimize(part: part): part;
|
|
92
|
+
interface DFAState {
|
|
93
|
+
nfaStates: Set<number>;
|
|
94
|
+
transitions: Map<string, DFAState>;
|
|
95
|
+
isAccepting: boolean;
|
|
96
|
+
}
|
|
97
|
+
export declare function runDFA(dfa: DFAState, str: string): boolean;
|
|
98
|
+
export declare function regexToDFA(part: part): DFAState;
|
|
99
|
+
export declare function parseGlob(glob: string): string;
|
|
100
|
+
export declare function anchoredRe(re: string): RegExp;
|
|
101
|
+
export declare function globToRe(glob: string): RegExp;
|
|
102
|
+
export declare function globToReMulti(globs: string[]): RegExp;
|
|
103
|
+
export {};
|