@isopodlabs/utilities 1.5.2 → 1.5.4
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/algorithm.js +5 -19
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/insensitive.d.ts +2 -2
- package/dist/iterator.d.ts +8 -10
- package/dist/iterator.js +47 -40
- package/dist/object.d.ts +30 -0
- package/dist/object.js +106 -0
- package/dist/string.d.ts +4 -0
- package/dist/string.js +107 -0
- package/dist/utils.d.ts +0 -7
- package/dist/utils.js +1 -28
- package/package.json +1 -1
package/dist/algorithm.js
CHANGED
|
@@ -6,7 +6,7 @@ exports.argmin = argmin;
|
|
|
6
6
|
exports.min = min;
|
|
7
7
|
exports.argmax = argmax;
|
|
8
8
|
exports.max = max;
|
|
9
|
-
const
|
|
9
|
+
const object_1 = require("./object");
|
|
10
10
|
function partition(array, func) {
|
|
11
11
|
const partitions = {};
|
|
12
12
|
for (const i of array)
|
|
@@ -24,21 +24,7 @@ function lowerBound(array, value, func) {
|
|
|
24
24
|
}
|
|
25
25
|
return i;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
export function argmin<T>(array: T[], func?: (i: T) => number) {
|
|
29
|
-
let mini = 0;
|
|
30
|
-
let minv = func ? func(array[0]) : array[0];
|
|
31
|
-
for (let i = 1; i < array.length; i++) {
|
|
32
|
-
const v = func ? func(array[i]) : array[i];
|
|
33
|
-
if (v < minv) {
|
|
34
|
-
mini = i;
|
|
35
|
-
minv = v;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return mini;
|
|
39
|
-
}
|
|
40
|
-
*/
|
|
41
|
-
function argmin(array, func = utils_1.compare) {
|
|
27
|
+
function argmin(array, func = object_1.compare) {
|
|
42
28
|
let mini = 0;
|
|
43
29
|
for (let i = 1; i < array.length; i++) {
|
|
44
30
|
const v = func(array[i], array[mini]);
|
|
@@ -47,10 +33,10 @@ function argmin(array, func = utils_1.compare) {
|
|
|
47
33
|
}
|
|
48
34
|
return mini;
|
|
49
35
|
}
|
|
50
|
-
function min(array, func =
|
|
36
|
+
function min(array, func = object_1.compare) {
|
|
51
37
|
return array[argmin(array, func)];
|
|
52
38
|
}
|
|
53
|
-
function argmax(array, func =
|
|
39
|
+
function argmax(array, func = object_1.compare) {
|
|
54
40
|
let maxi = 0;
|
|
55
41
|
for (let i = 1; i < array.length; i++) {
|
|
56
42
|
const v = func(array[i], array[maxi]);
|
|
@@ -59,6 +45,6 @@ function argmax(array, func = utils_1.compare) {
|
|
|
59
45
|
}
|
|
60
46
|
return maxi;
|
|
61
47
|
}
|
|
62
|
-
function max(array, func =
|
|
48
|
+
function max(array, func = object_1.compare) {
|
|
63
49
|
return array[argmax(array, func)];
|
|
64
50
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.insensitive = void 0;
|
|
40
|
-
__exportStar(require("./
|
|
40
|
+
__exportStar(require("./object"), exports);
|
|
41
41
|
__exportStar(require("./iterator"), exports);
|
|
42
42
|
__exportStar(require("./string"), exports);
|
|
43
43
|
__exportStar(require("./algorithm"), exports);
|
package/dist/insensitive.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ declare class CaseInsensitiveString {
|
|
|
10
10
|
endsWith(searchString: string, position?: number): boolean;
|
|
11
11
|
indexOf(searchString: string, position?: number): number;
|
|
12
12
|
lastIndexOf(searchString: string, position?: number): number;
|
|
13
|
-
compare(other: string | CaseInsensitiveString):
|
|
13
|
+
compare(other: string | CaseInsensitiveString): 0 | 1 | -1;
|
|
14
14
|
}
|
|
15
15
|
declare class CaseInsensitiveString2 extends CaseInsensitiveString {
|
|
16
16
|
private orig;
|
|
@@ -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):
|
|
22
|
+
export declare function compare(a: string, b: string): 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/iterator.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
export type SpreadType<T> = T extends Iterable<infer U> ? U[] : never;
|
|
2
|
-
export declare function arrayAppend<T, U extends Iterable<T>>(array: T[], items: U): void;
|
|
3
2
|
export declare function arrayRemove<T>(array: T[], item: T): boolean;
|
|
4
3
|
export declare function arrayCompare<T>(arr1: T[], arr2: T[]): number;
|
|
5
4
|
export declare function arrayEqual<T>(arr1: T[], arr2: T[]): boolean;
|
|
6
5
|
export declare function arrayRotate<T>(array: T[], start: number, end: number, shift: number): void;
|
|
7
6
|
export declare function arrayReverse<T>(array: T[], start: number, end: number): void;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
7
|
+
export declare function arrayMake<T>(n: number, constructor: new () => T): T[];
|
|
8
|
+
export declare function forEach<T>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => void): void;
|
|
9
|
+
export declare function find<T>(iterable: Iterable<T> | undefined, func: (v: T) => boolean): T | undefined;
|
|
10
|
+
export declare function map<T, U>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => U): U[];
|
|
11
|
+
export declare function reduce<T, U>(iterable: Iterable<T>, func: (acc: U, v: T, i: number, iterable: Iterable<T>) => U, initialValue: U): U;
|
|
12
|
+
export declare function filter<T>(iterable: Iterable<T>, func: (v: T, i: number) => unknown): T[];
|
|
12
13
|
export declare function asyncMap<T, U>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => Promise<U>): Promise<U[]>;
|
|
13
|
-
export declare function asyncReduce<T, U>(
|
|
14
|
+
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>;
|
|
15
|
+
export declare function asyncFilter<T>(iterable: Iterable<T>, func: (v: T) => Promise<unknown>): Promise<T[]>;
|
|
14
16
|
export declare function parallel(...fns: (() => any)[]): Promise<any[]>;
|
|
15
17
|
export declare function serial(...fns: (() => any)[]): Promise<any[]>;
|
|
16
|
-
export declare function filterIterable<T>(iterable: Iterable<T>, func: (v: T, i: number) => boolean): T[];
|
|
17
|
-
export declare function asyncFilter<T>(iterable: Iterable<T>, func: (v: T) => Promise<boolean>): Promise<T[]>;
|
|
18
|
-
export declare function mapObject<T, U>(obj: Record<string, T>, func: (x: [k: string, v: T]) => [k: string, v: U]): Record<string, U>;
|
|
19
|
-
export declare function filterObject<T>(obj: Record<string, T>, func: (x: [k: string, v: T]) => boolean): Record<string, T>;
|
package/dist/iterator.js
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.arrayAppend = arrayAppend;
|
|
4
3
|
exports.arrayRemove = arrayRemove;
|
|
5
4
|
exports.arrayCompare = arrayCompare;
|
|
6
5
|
exports.arrayEqual = arrayEqual;
|
|
7
6
|
exports.arrayRotate = arrayRotate;
|
|
8
7
|
exports.arrayReverse = arrayReverse;
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
8
|
+
exports.arrayMake = arrayMake;
|
|
9
|
+
exports.forEach = forEach;
|
|
10
|
+
exports.find = find;
|
|
11
|
+
exports.map = map;
|
|
12
|
+
exports.reduce = reduce;
|
|
13
|
+
exports.filter = filter;
|
|
13
14
|
exports.asyncMap = asyncMap;
|
|
14
15
|
exports.asyncReduce = asyncReduce;
|
|
16
|
+
exports.asyncFilter = asyncFilter;
|
|
15
17
|
exports.parallel = parallel;
|
|
16
18
|
exports.serial = serial;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
exports.mapObject = mapObject;
|
|
20
|
-
exports.filterObject = filterObject;
|
|
21
|
-
const utils_1 = require("./utils");
|
|
22
|
-
function arrayAppend(array, items) {
|
|
23
|
-
for (const i of items)
|
|
24
|
-
array.push(i);
|
|
25
|
-
}
|
|
19
|
+
const object_1 = require("./object");
|
|
20
|
+
//remove element of array
|
|
26
21
|
function arrayRemove(array, item) {
|
|
27
22
|
const index = array.indexOf(item);
|
|
28
23
|
if (index === -1)
|
|
@@ -33,7 +28,7 @@ function arrayRemove(array, item) {
|
|
|
33
28
|
function arrayCompare(arr1, arr2) {
|
|
34
29
|
const length = Math.min(arr1.length, arr2.length);
|
|
35
30
|
for (let i = 0; i < length; i++) {
|
|
36
|
-
const r = (0,
|
|
31
|
+
const r = (0, object_1.compare)(arr1[i], arr2[i]);
|
|
37
32
|
if (r)
|
|
38
33
|
return r;
|
|
39
34
|
}
|
|
@@ -64,17 +59,17 @@ function arrayReverse(array, start, end) {
|
|
|
64
59
|
end--;
|
|
65
60
|
}
|
|
66
61
|
}
|
|
67
|
-
function
|
|
62
|
+
function arrayMake(n, constructor) {
|
|
68
63
|
return Array.from({ length: n }, () => new constructor);
|
|
69
64
|
}
|
|
70
|
-
function
|
|
65
|
+
function forEach(iterable, func) {
|
|
71
66
|
if (iterable) {
|
|
72
67
|
let i = 0;
|
|
73
68
|
for (const v of iterable)
|
|
74
69
|
func(v, i++);
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
|
-
function
|
|
72
|
+
function find(iterable, func) {
|
|
78
73
|
if (iterable) {
|
|
79
74
|
for (const v of iterable) {
|
|
80
75
|
if (func(v))
|
|
@@ -82,25 +77,17 @@ function findIterable(iterable, func) {
|
|
|
82
77
|
}
|
|
83
78
|
}
|
|
84
79
|
}
|
|
85
|
-
function
|
|
80
|
+
function map(iterable, func) {
|
|
86
81
|
return iterable ? Array.from(iterable, func) : [];
|
|
87
82
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
async function parallel(...fns) {
|
|
95
|
-
return asyncMap(fns, f => f());
|
|
96
|
-
}
|
|
97
|
-
async function serial(...fns) {
|
|
98
|
-
const results = [];
|
|
99
|
-
for (const f of fns)
|
|
100
|
-
results.push(await f());
|
|
101
|
-
return results;
|
|
83
|
+
function reduce(iterable, func, initialValue) {
|
|
84
|
+
let i = 0;
|
|
85
|
+
let acc = initialValue;
|
|
86
|
+
for (const v of iterable)
|
|
87
|
+
acc = func(acc, v, i++, iterable);
|
|
88
|
+
return acc;
|
|
102
89
|
}
|
|
103
|
-
function
|
|
90
|
+
function filter(iterable, func) {
|
|
104
91
|
const array = [];
|
|
105
92
|
let i = 0;
|
|
106
93
|
for (const v of iterable)
|
|
@@ -108,13 +95,33 @@ function filterIterable(iterable, func) {
|
|
|
108
95
|
array.push(v);
|
|
109
96
|
return array;
|
|
110
97
|
}
|
|
98
|
+
async function asyncMap(iterable, func) {
|
|
99
|
+
return Promise.all(map(iterable, func));
|
|
100
|
+
}
|
|
101
|
+
async function asyncReduce(iterable, func, initialValue) {
|
|
102
|
+
let i = 0;
|
|
103
|
+
let acc = initialValue;
|
|
104
|
+
for (const v of iterable)
|
|
105
|
+
acc = await func(acc, v, i++, iterable);
|
|
106
|
+
return acc;
|
|
107
|
+
/*
|
|
108
|
+
return reduce<T, Promise<U>>(
|
|
109
|
+
iterable,
|
|
110
|
+
async (promise, v, i, iterable) => func(await promise, v, i, iterable),
|
|
111
|
+
Promise.resolve(initialValue)
|
|
112
|
+
);
|
|
113
|
+
*/
|
|
114
|
+
}
|
|
111
115
|
async function asyncFilter(iterable, func) {
|
|
112
|
-
const filters = await Promise.all(
|
|
113
|
-
return
|
|
116
|
+
const filters = await Promise.all(map(iterable, func));
|
|
117
|
+
return filter(iterable, (_, i) => filters[i]);
|
|
114
118
|
}
|
|
115
|
-
function
|
|
116
|
-
return
|
|
119
|
+
async function parallel(...fns) {
|
|
120
|
+
return asyncMap(fns, f => f());
|
|
117
121
|
}
|
|
118
|
-
function
|
|
119
|
-
|
|
122
|
+
async function serial(...fns) {
|
|
123
|
+
const results = [];
|
|
124
|
+
for (const f of fns)
|
|
125
|
+
results.push(await f());
|
|
126
|
+
return results;
|
|
120
127
|
}
|
package/dist/object.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare function mapObject<T, U>(obj: Record<string, T>, func: (x: [k: string, v: T]) => [k: string, v: U]): Record<string, U>;
|
|
2
|
+
export declare function filterObject<T>(obj: Record<string, T>, func: (x: [k: string, v: T]) => boolean): Record<string, T>;
|
|
3
|
+
export declare function merge(...list: Record<string, any>[]): Record<string, any>;
|
|
4
|
+
export declare function isEmpty(obj: object): boolean;
|
|
5
|
+
export declare function clone<T extends object>(obj: T): T;
|
|
6
|
+
export declare function compare<T>(a: T, b: T): number;
|
|
7
|
+
export declare function reverse_compare<T>(a: T, b: T): number;
|
|
8
|
+
export declare function reverse<T, R>(func: (a: T, b: T) => R): (a: T, b: T) => R;
|
|
9
|
+
export declare class Lazy<T> {
|
|
10
|
+
private factory;
|
|
11
|
+
private _value;
|
|
12
|
+
constructor(factory: () => T);
|
|
13
|
+
get value(): T;
|
|
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
|
+
}
|
|
16
|
+
export declare class CallCombiner0 {
|
|
17
|
+
private timeout;
|
|
18
|
+
combine(delay: number, func: () => void): void;
|
|
19
|
+
pending(): boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare class CallCombiner extends CallCombiner0 {
|
|
22
|
+
private func;
|
|
23
|
+
private delay;
|
|
24
|
+
constructor(func: () => void, delay: number);
|
|
25
|
+
trigger(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function makeCache<T>(load: (key: string) => T): {
|
|
28
|
+
get: (fullpath: string) => T;
|
|
29
|
+
remove: (fullpath: string) => void;
|
|
30
|
+
};
|
package/dist/object.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CallCombiner = exports.CallCombiner0 = exports.Lazy = void 0;
|
|
4
|
+
exports.mapObject = mapObject;
|
|
5
|
+
exports.filterObject = filterObject;
|
|
6
|
+
exports.merge = merge;
|
|
7
|
+
exports.isEmpty = isEmpty;
|
|
8
|
+
exports.clone = clone;
|
|
9
|
+
exports.compare = compare;
|
|
10
|
+
exports.reverse_compare = reverse_compare;
|
|
11
|
+
exports.reverse = reverse;
|
|
12
|
+
exports.makeCache = makeCache;
|
|
13
|
+
function mapObject(obj, func) {
|
|
14
|
+
return Object.fromEntries(Object.entries(obj).map(x => func(x)));
|
|
15
|
+
}
|
|
16
|
+
function filterObject(obj, func) {
|
|
17
|
+
return Object.fromEntries(Object.entries(obj).filter(x => func(x)));
|
|
18
|
+
}
|
|
19
|
+
function merge(...list) {
|
|
20
|
+
function isObject(value) {
|
|
21
|
+
return typeof value === 'object' && value !== null;
|
|
22
|
+
}
|
|
23
|
+
function recurse(target, source) {
|
|
24
|
+
for (const key in source) {
|
|
25
|
+
if (isObject(source[key]) && isObject(target[key]))
|
|
26
|
+
recurse(target[key], source[key]);
|
|
27
|
+
else
|
|
28
|
+
target[key] = source[key];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
}
|
|
32
|
+
return list.reduce((merged, r) => recurse(merged, r), {});
|
|
33
|
+
}
|
|
34
|
+
function isEmpty(obj) {
|
|
35
|
+
return Object.keys(obj).length === 0;
|
|
36
|
+
}
|
|
37
|
+
function clone(obj) {
|
|
38
|
+
return Object.assign(Object.create(Object.getPrototypeOf(obj)), obj);
|
|
39
|
+
}
|
|
40
|
+
function compare(a, b) {
|
|
41
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
42
|
+
}
|
|
43
|
+
function reverse_compare(a, b) {
|
|
44
|
+
return compare(b, a);
|
|
45
|
+
}
|
|
46
|
+
function reverse(func) {
|
|
47
|
+
return (a, b) => func(b, a);
|
|
48
|
+
}
|
|
49
|
+
class Lazy {
|
|
50
|
+
factory;
|
|
51
|
+
_value;
|
|
52
|
+
constructor(factory) {
|
|
53
|
+
this.factory = factory;
|
|
54
|
+
}
|
|
55
|
+
get value() {
|
|
56
|
+
if (this._value === undefined)
|
|
57
|
+
this._value = this.factory();
|
|
58
|
+
return this._value;
|
|
59
|
+
}
|
|
60
|
+
// Add 'then' method only when T is a Promise
|
|
61
|
+
then(onFulfilled) {
|
|
62
|
+
return this.value.then(onFulfilled);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.Lazy = Lazy;
|
|
66
|
+
class CallCombiner0 {
|
|
67
|
+
timeout = null;
|
|
68
|
+
combine(delay, func) {
|
|
69
|
+
if (this.timeout)
|
|
70
|
+
clearTimeout(this.timeout);
|
|
71
|
+
this.timeout = setTimeout(() => {
|
|
72
|
+
this.timeout = null;
|
|
73
|
+
func();
|
|
74
|
+
}, delay);
|
|
75
|
+
}
|
|
76
|
+
pending() {
|
|
77
|
+
return !!this.timeout;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.CallCombiner0 = CallCombiner0;
|
|
81
|
+
class CallCombiner extends CallCombiner0 {
|
|
82
|
+
func;
|
|
83
|
+
delay;
|
|
84
|
+
constructor(func, delay) {
|
|
85
|
+
super();
|
|
86
|
+
this.func = func;
|
|
87
|
+
this.delay = delay;
|
|
88
|
+
}
|
|
89
|
+
trigger() {
|
|
90
|
+
super.combine(this.delay, this.func);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.CallCombiner = CallCombiner;
|
|
94
|
+
function makeCache(load) {
|
|
95
|
+
const cache = {};
|
|
96
|
+
return {
|
|
97
|
+
get: (fullpath) => {
|
|
98
|
+
if (!cache[fullpath])
|
|
99
|
+
cache[fullpath] = load(fullpath);
|
|
100
|
+
return cache[fullpath];
|
|
101
|
+
},
|
|
102
|
+
remove: (fullpath) => {
|
|
103
|
+
delete cache[fullpath];
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
package/dist/string.d.ts
CHANGED
|
@@ -26,3 +26,7 @@ export declare class StringParser {
|
|
|
26
26
|
match(re: RegExp): string | undefined;
|
|
27
27
|
exec(re: RegExp): RegExpExecArray | undefined;
|
|
28
28
|
}
|
|
29
|
+
export declare function parseGlob(glob: string): string;
|
|
30
|
+
export declare function anchoredRe(re: string): RegExp;
|
|
31
|
+
export declare function globToRe(glob: string): RegExp;
|
|
32
|
+
export declare function globToReMulti(globs: string[]): RegExp;
|
package/dist/string.js
CHANGED
|
@@ -17,6 +17,10 @@ exports.splitEvery = splitEvery;
|
|
|
17
17
|
exports.tag = tag;
|
|
18
18
|
exports.previousChar = previousChar;
|
|
19
19
|
exports.hasCustomToString = hasCustomToString;
|
|
20
|
+
exports.parseGlob = parseGlob;
|
|
21
|
+
exports.anchoredRe = anchoredRe;
|
|
22
|
+
exports.globToRe = globToRe;
|
|
23
|
+
exports.globToReMulti = globToReMulti;
|
|
20
24
|
function firstOf(value, find) {
|
|
21
25
|
let index = value.length;
|
|
22
26
|
for (const c of find) {
|
|
@@ -161,3 +165,106 @@ class StringParser {
|
|
|
161
165
|
}
|
|
162
166
|
}
|
|
163
167
|
exports.StringParser = StringParser;
|
|
168
|
+
const posixClasses = {
|
|
169
|
+
alnum: '\\p{L}\\p{Nl}\\p{Nd}',
|
|
170
|
+
alpha: '\\p{L}\\p{Nl}',
|
|
171
|
+
ascii: '\\x00-\\x7f',
|
|
172
|
+
blank: '\\p{Zs}\\t',
|
|
173
|
+
cntrl: '\\p{Cc}',
|
|
174
|
+
digit: '\\p{Nd}',
|
|
175
|
+
graph: '^\\p{Z}\\p{C}',
|
|
176
|
+
lower: '\\p{Ll}',
|
|
177
|
+
print: '\\p{C}',
|
|
178
|
+
punct: '\\p{P}',
|
|
179
|
+
space: '\\p{Z}\\t\\r\\n\\v\\f',
|
|
180
|
+
upper: '\\p{Lu}',
|
|
181
|
+
word: '\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}',
|
|
182
|
+
xdigit: 'A-Fa-f0-9',
|
|
183
|
+
};
|
|
184
|
+
function parseGlob(glob) {
|
|
185
|
+
let result = '';
|
|
186
|
+
let depth = 0;
|
|
187
|
+
for (let i = 0; i < glob.length; ++i) {
|
|
188
|
+
let c = glob[i];
|
|
189
|
+
switch (c) {
|
|
190
|
+
case '\\':
|
|
191
|
+
c = glob[++i];
|
|
192
|
+
if ('*?+.,^$()|[]a-zA-Z'.includes(c))
|
|
193
|
+
result += '\\';
|
|
194
|
+
break;
|
|
195
|
+
case '*':
|
|
196
|
+
if (glob[i + 1] === '*') {
|
|
197
|
+
result += '.*';
|
|
198
|
+
++i;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
result += '[^/]*';
|
|
202
|
+
}
|
|
203
|
+
continue;
|
|
204
|
+
case '?':
|
|
205
|
+
c = '.';
|
|
206
|
+
break;
|
|
207
|
+
case '+':
|
|
208
|
+
case '.':
|
|
209
|
+
case '^':
|
|
210
|
+
case '$':
|
|
211
|
+
case '(':
|
|
212
|
+
case ')':
|
|
213
|
+
case '|':
|
|
214
|
+
result += `\\`;
|
|
215
|
+
break;
|
|
216
|
+
case '[': {
|
|
217
|
+
const end = glob.indexOf(']', i + 1);
|
|
218
|
+
if (end > i) {
|
|
219
|
+
const next = glob[i + 1];
|
|
220
|
+
if (next === ':' && glob[end - 1] === ':') {
|
|
221
|
+
const p = posixClasses[glob.slice(i + 2, end - 1)];
|
|
222
|
+
if (p) {
|
|
223
|
+
result += `[${p}]`;
|
|
224
|
+
i = end;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
console.log(`Warning: Unknown POSIX class ${glob.slice(i + 2, end - 1)} in glob pattern ${glob}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const neg = next === '!' || next === '^';
|
|
232
|
+
result += `[${neg ? '^' : ''}${glob.slice(neg ? i + 2 : i + 1, end)}]`;
|
|
233
|
+
i = end;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
result += '\\';
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
case '{':
|
|
240
|
+
++depth;
|
|
241
|
+
c = '(';
|
|
242
|
+
break;
|
|
243
|
+
case '}':
|
|
244
|
+
if (depth > 0) {
|
|
245
|
+
--depth;
|
|
246
|
+
c = ')';
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
case ',':
|
|
250
|
+
if (depth > 0)
|
|
251
|
+
c = '|';
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
result += c;
|
|
255
|
+
}
|
|
256
|
+
if (depth > 0) {
|
|
257
|
+
console.log(`Warning: Unmatched { in glob pattern ${glob}`);
|
|
258
|
+
result += ')'.repeat(depth);
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
function anchoredRe(re) {
|
|
263
|
+
return new RegExp(`^${re}$`);
|
|
264
|
+
}
|
|
265
|
+
function globToRe(glob) {
|
|
266
|
+
return anchoredRe(parseGlob(glob));
|
|
267
|
+
}
|
|
268
|
+
function globToReMulti(globs) {
|
|
269
|
+
return anchoredRe(globs.map(parseGlob).join('|'));
|
|
270
|
+
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -5,13 +5,6 @@ export declare class Lazy<T> {
|
|
|
5
5
|
get value(): T;
|
|
6
6
|
then<U>(this: T extends Promise<infer R> ? Lazy<T> : never, onFulfilled: (value: T extends Promise<infer R> ? R : never) => U): Promise<U>;
|
|
7
7
|
}
|
|
8
|
-
export declare class AsyncLazy<T> {
|
|
9
|
-
private factory;
|
|
10
|
-
private _value;
|
|
11
|
-
constructor(factory: () => Promise<T>);
|
|
12
|
-
get value(): (T & {}) | null;
|
|
13
|
-
then(fn: (v: T) => void): void;
|
|
14
|
-
}
|
|
15
8
|
export declare class CallCombiner0 {
|
|
16
9
|
private timeout;
|
|
17
10
|
combine(delay: number, func: () => void): void;
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CallCombiner = exports.CallCombiner0 = exports.
|
|
3
|
+
exports.CallCombiner = exports.CallCombiner0 = exports.Lazy = void 0;
|
|
4
4
|
exports.makeCache = makeCache;
|
|
5
5
|
exports.compare = compare;
|
|
6
6
|
exports.reverse_compare = reverse_compare;
|
|
@@ -25,33 +25,6 @@ class Lazy {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.Lazy = Lazy;
|
|
28
|
-
class AsyncLazy {
|
|
29
|
-
factory;
|
|
30
|
-
_value;
|
|
31
|
-
constructor(factory) {
|
|
32
|
-
this.factory = factory;
|
|
33
|
-
}
|
|
34
|
-
get value() {
|
|
35
|
-
if (this._value === undefined) {
|
|
36
|
-
this._value = null;
|
|
37
|
-
this.factory().then(v => this._value = v);
|
|
38
|
-
}
|
|
39
|
-
return this._value;
|
|
40
|
-
}
|
|
41
|
-
then(fn) {
|
|
42
|
-
if (this._value === undefined) {
|
|
43
|
-
this._value = null;
|
|
44
|
-
this.factory().then(v => {
|
|
45
|
-
this._value = v;
|
|
46
|
-
fn(v);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
else if (this._value !== null) {
|
|
50
|
-
fn(this._value);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.AsyncLazy = AsyncLazy;
|
|
55
28
|
class CallCombiner0 {
|
|
56
29
|
timeout = null;
|
|
57
30
|
combine(delay, func) {
|