@isopodlabs/utilities 1.5.0 → 1.5.2
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.d.ts +4 -1
- package/dist/algorithm.js +33 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +24 -0
- package/dist/insensitive.d.ts +20 -4
- package/dist/insensitive.js +42 -13
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +16 -0
- package/package.json +1 -1
- package/dist/CaseInsensitive.d.ts +0 -22
- package/dist/CaseInsensitive.js +0 -58
- package/dist/glob.d.ts +0 -20
- package/dist/glob.js +0 -156
package/dist/algorithm.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
type PartitionIndex<U> = U extends boolean ? 'true' | 'false' : U;
|
|
2
2
|
export declare function partition<T, U extends keyof any | boolean>(array: Iterable<T>, func: (v: T) => U): Record<PartitionIndex<U>, T[]>;
|
|
3
3
|
export declare function lowerBound<T>(array: T[], value: T, func: (a: T, b: T, i: number) => boolean): number;
|
|
4
|
-
export declare function argmin<T>(array: T[], func?: (
|
|
4
|
+
export declare function argmin<T>(array: T[], func?: (a: T, b: T) => number): number;
|
|
5
|
+
export declare function min<T>(array: T[], func?: (a: T, b: T) => number): T;
|
|
6
|
+
export declare function argmax<T>(array: T[], func?: (a: T, b: T) => number): number;
|
|
7
|
+
export declare function max<T>(array: T[], func?: (a: T, b: T) => number): T;
|
|
5
8
|
export {};
|
package/dist/algorithm.js
CHANGED
|
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.partition = partition;
|
|
4
4
|
exports.lowerBound = lowerBound;
|
|
5
5
|
exports.argmin = argmin;
|
|
6
|
+
exports.min = min;
|
|
7
|
+
exports.argmax = argmax;
|
|
8
|
+
exports.max = max;
|
|
9
|
+
const utils_1 = require("./utils");
|
|
6
10
|
function partition(array, func) {
|
|
7
11
|
const partitions = {};
|
|
8
12
|
for (const i of array)
|
|
@@ -20,9 +24,10 @@ function lowerBound(array, value, func) {
|
|
|
20
24
|
}
|
|
21
25
|
return i;
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let
|
|
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];
|
|
26
31
|
for (let i = 1; i < array.length; i++) {
|
|
27
32
|
const v = func ? func(array[i]) : array[i];
|
|
28
33
|
if (v < minv) {
|
|
@@ -31,4 +36,29 @@ function argmin(array, func) {
|
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
return mini;
|
|
39
|
+
}
|
|
40
|
+
*/
|
|
41
|
+
function argmin(array, func = utils_1.compare) {
|
|
42
|
+
let mini = 0;
|
|
43
|
+
for (let i = 1; i < array.length; i++) {
|
|
44
|
+
const v = func(array[i], array[mini]);
|
|
45
|
+
if (v < 0)
|
|
46
|
+
mini = i;
|
|
47
|
+
}
|
|
48
|
+
return mini;
|
|
49
|
+
}
|
|
50
|
+
function min(array, func = utils_1.compare) {
|
|
51
|
+
return array[argmin(array, func)];
|
|
52
|
+
}
|
|
53
|
+
function argmax(array, func = utils_1.compare) {
|
|
54
|
+
let maxi = 0;
|
|
55
|
+
for (let i = 1; i < array.length; i++) {
|
|
56
|
+
const v = func(array[i], array[maxi]);
|
|
57
|
+
if (v > 0)
|
|
58
|
+
maxi = i;
|
|
59
|
+
}
|
|
60
|
+
return maxi;
|
|
61
|
+
}
|
|
62
|
+
function max(array, func = utils_1.compare) {
|
|
63
|
+
return array[argmax(array, func)];
|
|
34
64
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,11 +10,35 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
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
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
16
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.insensitive = void 0;
|
|
17
40
|
__exportStar(require("./utils"), exports);
|
|
18
41
|
__exportStar(require("./iterator"), exports);
|
|
19
42
|
__exportStar(require("./string"), exports);
|
|
20
43
|
__exportStar(require("./algorithm"), exports);
|
|
44
|
+
exports.insensitive = __importStar(require("./insensitive"));
|
package/dist/insensitive.d.ts
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
declare class CaseInsensitiveString {
|
|
2
2
|
private value;
|
|
3
3
|
constructor(value: string);
|
|
4
4
|
get length(): number;
|
|
5
5
|
toString(): string;
|
|
6
|
+
toUpperCase(): string;
|
|
7
|
+
toLowerCase(): string;
|
|
6
8
|
includes(searchString: string, position?: number): boolean;
|
|
7
9
|
startsWith(searchString: string, position?: number): boolean;
|
|
8
10
|
endsWith(searchString: string, position?: number): boolean;
|
|
9
11
|
indexOf(searchString: string, position?: number): number;
|
|
10
12
|
lastIndexOf(searchString: string, position?: number): number;
|
|
11
|
-
compare(other: string):
|
|
13
|
+
compare(other: string | CaseInsensitiveString): 1 | -1 | 0;
|
|
12
14
|
}
|
|
13
|
-
|
|
15
|
+
declare class CaseInsensitiveString2 extends CaseInsensitiveString {
|
|
14
16
|
private orig;
|
|
15
17
|
constructor(orig: string);
|
|
16
18
|
toString(): string;
|
|
17
19
|
}
|
|
18
20
|
export declare function String(value: string): CaseInsensitiveString;
|
|
19
21
|
export declare function String2(value: string): CaseInsensitiveString2;
|
|
20
|
-
export declare function compare(a: string, b: string):
|
|
22
|
+
export declare function compare(a: string, b: string): 1 | -1 | 0;
|
|
21
23
|
export declare function Record<T>(obj: Record<string, T>): Record<string, T>;
|
|
22
24
|
export declare function Record2<T>(obj: Record<string, T>): Record<string, T>;
|
|
25
|
+
export declare class Map<T> extends globalThis.Map<string, T> {
|
|
26
|
+
constructor(entries?: Iterable<[string, T]>);
|
|
27
|
+
delete(key: string): boolean;
|
|
28
|
+
get(key: string): T | undefined;
|
|
29
|
+
has(key: string): boolean;
|
|
30
|
+
set(key: string, value: T): this;
|
|
31
|
+
}
|
|
32
|
+
export declare class Set extends globalThis.Set<string> {
|
|
33
|
+
constructor(values?: Iterable<string>);
|
|
34
|
+
add(value: string): this;
|
|
35
|
+
delete(value: string): boolean;
|
|
36
|
+
has(value: string): boolean;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
package/dist/insensitive.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Set = exports.Map = void 0;
|
|
4
4
|
exports.String = String;
|
|
5
5
|
exports.String2 = String2;
|
|
6
6
|
exports.compare = compare;
|
|
@@ -8,17 +8,18 @@ exports.Record = Record;
|
|
|
8
8
|
exports.Record2 = Record2;
|
|
9
9
|
class CaseInsensitiveString {
|
|
10
10
|
value;
|
|
11
|
-
constructor(value) { this.value = value.
|
|
11
|
+
constructor(value) { this.value = value.toUpperCase(); }
|
|
12
12
|
get length() { return this.value.length; }
|
|
13
13
|
toString() { return this.value; }
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
14
|
+
toUpperCase() { return this.value; }
|
|
15
|
+
toLowerCase() { return this.value.toLowerCase(); }
|
|
16
|
+
includes(searchString, position) { return this.value.includes(searchString.toUpperCase(), position); }
|
|
17
|
+
startsWith(searchString, position) { return this.value.startsWith(searchString.toUpperCase(), position); }
|
|
18
|
+
endsWith(searchString, position) { return this.value.endsWith(searchString.toUpperCase(), position); }
|
|
19
|
+
indexOf(searchString, position) { return this.value.indexOf(searchString.toUpperCase(), position); }
|
|
20
|
+
lastIndexOf(searchString, position) { return this.value.lastIndexOf(searchString.toUpperCase(), position); }
|
|
21
|
+
compare(other) { const bi = other.toUpperCase(); return this.value < bi ? -1 : this.value > bi ? 1 : 0; }
|
|
22
|
+
}
|
|
22
23
|
// keeps original string
|
|
23
24
|
class CaseInsensitiveString2 extends CaseInsensitiveString {
|
|
24
25
|
orig;
|
|
@@ -28,7 +29,6 @@ class CaseInsensitiveString2 extends CaseInsensitiveString {
|
|
|
28
29
|
}
|
|
29
30
|
toString() { return this.orig; }
|
|
30
31
|
}
|
|
31
|
-
exports.CaseInsensitiveString2 = CaseInsensitiveString2;
|
|
32
32
|
function String(value) {
|
|
33
33
|
return new CaseInsensitiveString(value);
|
|
34
34
|
}
|
|
@@ -44,6 +44,8 @@ function Record(obj) {
|
|
|
44
44
|
get: (target, name) => target[name.toUpperCase()],
|
|
45
45
|
set: (target, name, value) => (target[name.toUpperCase()] = value, true),
|
|
46
46
|
has: (target, name) => name.toUpperCase() in target,
|
|
47
|
+
ownKeys: (target) => Object.keys(target),
|
|
48
|
+
getOwnPropertyDescriptor: (target, name) => Object.getOwnPropertyDescriptor(target, name),
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
// keeps original record
|
|
@@ -52,7 +54,34 @@ function Record2(obj) {
|
|
|
52
54
|
get: (target, name) => target[name.toUpperCase()],
|
|
53
55
|
set: (target, name, value) => (target[name.toUpperCase()] = value, true),
|
|
54
56
|
has: (target, name) => name.toUpperCase() in target,
|
|
55
|
-
ownKeys: (
|
|
56
|
-
getOwnPropertyDescriptor: (target, name) => Object.getOwnPropertyDescriptor(
|
|
57
|
+
ownKeys: (_target) => Object.keys(obj),
|
|
58
|
+
getOwnPropertyDescriptor: (target, name) => Object.getOwnPropertyDescriptor(target, name)
|
|
57
59
|
});
|
|
58
60
|
}
|
|
61
|
+
class Map extends globalThis.Map {
|
|
62
|
+
constructor(entries) {
|
|
63
|
+
super();
|
|
64
|
+
if (entries) {
|
|
65
|
+
for (const [key, value] of entries)
|
|
66
|
+
this.set(key, value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
delete(key) { return super.delete(key.toUpperCase()); }
|
|
70
|
+
get(key) { return super.get(key.toUpperCase()); }
|
|
71
|
+
has(key) { return super.has(key.toUpperCase()); }
|
|
72
|
+
set(key, value) { return super.set(key.toUpperCase(), value); }
|
|
73
|
+
}
|
|
74
|
+
exports.Map = Map;
|
|
75
|
+
class Set extends globalThis.Set {
|
|
76
|
+
constructor(values) {
|
|
77
|
+
super();
|
|
78
|
+
if (values) {
|
|
79
|
+
for (const value of values)
|
|
80
|
+
this.add(value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
add(value) { return super.add(value.toUpperCase()); }
|
|
84
|
+
delete(value) { return super.delete(value.toUpperCase()); }
|
|
85
|
+
has(value) { return super.has(value.toUpperCase()); }
|
|
86
|
+
}
|
|
87
|
+
exports.Set = Set;
|
package/dist/utils.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ export declare class Lazy<T> {
|
|
|
3
3
|
private _value;
|
|
4
4
|
constructor(factory: () => T);
|
|
5
5
|
get value(): T;
|
|
6
|
+
then<U>(this: T extends Promise<infer R> ? Lazy<T> : never, onFulfilled: (value: T extends Promise<infer R> ? R : never) => U): Promise<U>;
|
|
6
7
|
}
|
|
7
8
|
export declare class AsyncLazy<T> {
|
|
8
9
|
private factory;
|
|
9
10
|
private _value;
|
|
10
11
|
constructor(factory: () => Promise<T>);
|
|
11
12
|
get value(): (T & {}) | null;
|
|
13
|
+
then(fn: (v: T) => void): void;
|
|
12
14
|
}
|
|
13
15
|
export declare class CallCombiner0 {
|
|
14
16
|
private timeout;
|
package/dist/utils.js
CHANGED
|
@@ -19,6 +19,10 @@ class Lazy {
|
|
|
19
19
|
this._value = this.factory();
|
|
20
20
|
return this._value;
|
|
21
21
|
}
|
|
22
|
+
// Add 'then' method only when T is a Promise
|
|
23
|
+
then(onFulfilled) {
|
|
24
|
+
return this.value.then(onFulfilled);
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
exports.Lazy = Lazy;
|
|
24
28
|
class AsyncLazy {
|
|
@@ -34,6 +38,18 @@ class AsyncLazy {
|
|
|
34
38
|
}
|
|
35
39
|
return this._value;
|
|
36
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
|
+
}
|
|
37
53
|
}
|
|
38
54
|
exports.AsyncLazy = AsyncLazy;
|
|
39
55
|
class CallCombiner0 {
|
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export declare class CaseInsensitiveString {
|
|
2
|
-
private value;
|
|
3
|
-
constructor(value: string);
|
|
4
|
-
get length(): number;
|
|
5
|
-
toString(): string;
|
|
6
|
-
includes(searchString: string, position?: number): boolean;
|
|
7
|
-
startsWith(searchString: string, position?: number): boolean;
|
|
8
|
-
endsWith(searchString: string, position?: number): boolean;
|
|
9
|
-
indexOf(searchString: string, position?: number): number;
|
|
10
|
-
lastIndexOf(searchString: string, position?: number): number;
|
|
11
|
-
compare(other: string): 1 | -1 | 0;
|
|
12
|
-
}
|
|
13
|
-
export declare class CaseInsensitiveString2 extends CaseInsensitiveString {
|
|
14
|
-
private orig;
|
|
15
|
-
constructor(orig: string);
|
|
16
|
-
toString(): string;
|
|
17
|
-
}
|
|
18
|
-
export declare function String(value: string): CaseInsensitiveString;
|
|
19
|
-
export declare function String2(value: string): CaseInsensitiveString2;
|
|
20
|
-
export declare function compare(a: string, b: string): 1 | -1 | 0;
|
|
21
|
-
export declare function Record<T>(obj: Record<string, T>): Record<string, T>;
|
|
22
|
-
export declare function Record2<T>(obj: Record<string, T>): Record<string, T>;
|
package/dist/CaseInsensitive.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CaseInsensitiveString2 = exports.CaseInsensitiveString = void 0;
|
|
4
|
-
exports.String = String;
|
|
5
|
-
exports.String2 = String2;
|
|
6
|
-
exports.compare = compare;
|
|
7
|
-
exports.Record = Record;
|
|
8
|
-
exports.Record2 = Record2;
|
|
9
|
-
class CaseInsensitiveString {
|
|
10
|
-
value;
|
|
11
|
-
constructor(value) { this.value = value.toLowerCase(); }
|
|
12
|
-
get length() { return this.value.length; }
|
|
13
|
-
toString() { return this.value; }
|
|
14
|
-
includes(searchString, position) { return this.value.includes(searchString.toLowerCase(), position); }
|
|
15
|
-
startsWith(searchString, position) { return this.value.startsWith(searchString.toLowerCase(), position); }
|
|
16
|
-
endsWith(searchString, position) { return this.value.endsWith(searchString.toLowerCase(), position); }
|
|
17
|
-
indexOf(searchString, position) { return this.value.indexOf(searchString.toLowerCase(), position); }
|
|
18
|
-
lastIndexOf(searchString, position) { return this.value.lastIndexOf(searchString.toLowerCase(), position); }
|
|
19
|
-
compare(other) { const bi = other.toLowerCase(); return this.value < bi ? -1 : this.value > bi ? 1 : 0; }
|
|
20
|
-
}
|
|
21
|
-
exports.CaseInsensitiveString = CaseInsensitiveString;
|
|
22
|
-
// keeps original string
|
|
23
|
-
class CaseInsensitiveString2 extends CaseInsensitiveString {
|
|
24
|
-
orig;
|
|
25
|
-
constructor(orig) {
|
|
26
|
-
super(orig);
|
|
27
|
-
this.orig = orig;
|
|
28
|
-
}
|
|
29
|
-
toString() { return this.orig; }
|
|
30
|
-
}
|
|
31
|
-
exports.CaseInsensitiveString2 = CaseInsensitiveString2;
|
|
32
|
-
function String(value) {
|
|
33
|
-
return new CaseInsensitiveString(value);
|
|
34
|
-
}
|
|
35
|
-
function String2(value) {
|
|
36
|
-
return new CaseInsensitiveString2(value);
|
|
37
|
-
}
|
|
38
|
-
function compare(a, b) {
|
|
39
|
-
const ai = a.toUpperCase(), bi = b.toUpperCase();
|
|
40
|
-
return ai < bi ? -1 : ai > bi ? 1 : 0;
|
|
41
|
-
}
|
|
42
|
-
function Record(obj) {
|
|
43
|
-
return new Proxy(obj, {
|
|
44
|
-
get: (target, name) => target[name.toUpperCase()],
|
|
45
|
-
set: (target, name, value) => (target[name.toUpperCase()] = value, true),
|
|
46
|
-
has: (target, name) => name.toUpperCase() in target,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
// keeps original record
|
|
50
|
-
function Record2(obj) {
|
|
51
|
-
return new Proxy(Object.entries(obj).reduce((acc, [key, value]) => ((acc[key.toUpperCase()] = value), acc), {}), {
|
|
52
|
-
get: (target, name) => target[name.toUpperCase()],
|
|
53
|
-
set: (target, name, value) => (target[name.toUpperCase()] = value, true),
|
|
54
|
-
has: (target, name) => name.toUpperCase() in target,
|
|
55
|
-
ownKeys: (target) => Object.keys(obj),
|
|
56
|
-
getOwnPropertyDescriptor: (target, name) => Object.getOwnPropertyDescriptor(obj, name)
|
|
57
|
-
});
|
|
58
|
-
}
|
package/dist/glob.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface Patcher {
|
|
2
|
-
patch(input: string): string;
|
|
3
|
-
}
|
|
4
|
-
export declare function patch<T>(patcher: Patcher, input: T): T;
|
|
5
|
-
export declare class MapPatcher implements Patcher {
|
|
6
|
-
matches: Record<string, string>;
|
|
7
|
-
constructor(matches: Record<string, string>);
|
|
8
|
-
add(key: string, value: string): this;
|
|
9
|
-
patch(input: string): string;
|
|
10
|
-
}
|
|
11
|
-
export declare function globRe(glob: string): RegExp;
|
|
12
|
-
export declare class Glob {
|
|
13
|
-
glob: string;
|
|
14
|
-
re: RegExp;
|
|
15
|
-
constructor(glob: string);
|
|
16
|
-
test(match: string): boolean;
|
|
17
|
-
star(match: string): string;
|
|
18
|
-
}
|
|
19
|
-
export declare function isWild(glob: string): boolean;
|
|
20
|
-
export declare function expandGlobs(patterns: string[], cwd: string): Promise<string[]>;
|
package/dist/glob.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
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
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Glob = exports.MapPatcher = void 0;
|
|
37
|
-
exports.patch = patch;
|
|
38
|
-
exports.globRe = globRe;
|
|
39
|
-
exports.isWild = isWild;
|
|
40
|
-
exports.expandGlobs = expandGlobs;
|
|
41
|
-
const path = __importStar(require("path"));
|
|
42
|
-
const fs = __importStar(require("fs"));
|
|
43
|
-
function patch(patcher, input) {
|
|
44
|
-
if (typeof input === 'string')
|
|
45
|
-
return patcher.patch(input);
|
|
46
|
-
if (typeof input === 'object' && input !== null) {
|
|
47
|
-
if (Array.isArray(input))
|
|
48
|
-
return input.map(value => patch(patcher, value));
|
|
49
|
-
return Object.entries(input).reduce((acc, [key, value]) => {
|
|
50
|
-
acc[key] = patch(patcher, value);
|
|
51
|
-
return acc;
|
|
52
|
-
}, Object.create(Object.getPrototypeOf(input)));
|
|
53
|
-
}
|
|
54
|
-
return input;
|
|
55
|
-
}
|
|
56
|
-
class MapPatcher {
|
|
57
|
-
matches;
|
|
58
|
-
constructor(matches) {
|
|
59
|
-
this.matches = matches;
|
|
60
|
-
}
|
|
61
|
-
add(key, value) {
|
|
62
|
-
this.matches[key] = value;
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
patch(input) {
|
|
66
|
-
for (const [key, value] of Object.entries(this.matches))
|
|
67
|
-
input = input.replaceAll(key, value);
|
|
68
|
-
return input;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.MapPatcher = MapPatcher;
|
|
72
|
-
function globRe(glob) {
|
|
73
|
-
const regex = glob
|
|
74
|
-
.replace(/[.+^${}()|[\]\\]/g, '\\$&') // Escape regex chars except * and ?
|
|
75
|
-
.replace(/\*/g, '[^/]*') // * matches any chars except dir separator
|
|
76
|
-
.replace(/\*\*/g, '.*') // ** matches any chars
|
|
77
|
-
.replace(/\?/g, '.'); // ? matches single char
|
|
78
|
-
return new RegExp(`^${regex}$`);
|
|
79
|
-
}
|
|
80
|
-
class Glob {
|
|
81
|
-
glob;
|
|
82
|
-
re;
|
|
83
|
-
constructor(glob) {
|
|
84
|
-
this.glob = glob;
|
|
85
|
-
this.re = globRe(glob);
|
|
86
|
-
}
|
|
87
|
-
test(match) {
|
|
88
|
-
return this.re.test(match);
|
|
89
|
-
}
|
|
90
|
-
star(match) {
|
|
91
|
-
const parts = this.glob.split('*');
|
|
92
|
-
return match.slice(parts[0].length, match.length - parts[1].length);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.Glob = Glob;
|
|
96
|
-
function isWild(glob) {
|
|
97
|
-
return glob.includes('*') || glob.includes('?');
|
|
98
|
-
}
|
|
99
|
-
async function getDirs(dir, glob) {
|
|
100
|
-
const star = dir.indexOf('*');
|
|
101
|
-
if (star >= 0) {
|
|
102
|
-
const startDir = dir.lastIndexOf(path.sep, star);
|
|
103
|
-
const endDir = dir.indexOf(path.sep, star);
|
|
104
|
-
const dirDone = dir.substring(0, startDir);
|
|
105
|
-
const dirWild = dir.substring(startDir + 1, endDir >= 0 ? endDir : undefined);
|
|
106
|
-
const dirRest = endDir >= 0 ? dir.substring(endDir + 1) : '';
|
|
107
|
-
const entries = await fs.promises.readdir(dirDone, { withFileTypes: true });
|
|
108
|
-
if (dirWild === '**') {
|
|
109
|
-
if (dirRest) {
|
|
110
|
-
return (await Promise.all(entries.filter(i => i.isDirectory()).map(async (i) => [
|
|
111
|
-
...await getDirs(path.join(i.parentPath, i.name, '**', dirRest), glob),
|
|
112
|
-
...await getDirs(path.join(i.parentPath, i.name, dirRest), glob)
|
|
113
|
-
]))).flat();
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
/*
|
|
117
|
-
return (await Promise.all(entries.filter(i => i.isDirectory()).map(i =>
|
|
118
|
-
getDirs(path.join(i.parentPath, i.name, '**'), glob)
|
|
119
|
-
))).flat().concat(
|
|
120
|
-
entries.filter(i => !i.isDirectory() && glob.test(i.name))
|
|
121
|
-
.map(i => path.join(i.parentPath, i.name))
|
|
122
|
-
);*/
|
|
123
|
-
return (await Promise.all(entries.map(i => i.isDirectory() ? getDirs(path.join(i.parentPath, i.name, '**'), glob)
|
|
124
|
-
: glob.test(i.name) ? path.join(i.parentPath, i.name)
|
|
125
|
-
: []))).flat();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
const dirGlob = globRe(dirWild);
|
|
130
|
-
return (await Promise.all(entries
|
|
131
|
-
.filter(i => i.isDirectory() && dirGlob.test(i.name))
|
|
132
|
-
.map(i => getDirs(path.join(dirDone, i.name, dirRest), glob)))).flat();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
try {
|
|
137
|
-
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
138
|
-
return entries
|
|
139
|
-
.filter(i => !i.isDirectory() && glob.test(i.name))
|
|
140
|
-
.map(i => path.join(i.parentPath, i.name));
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
console.log(`Warning: Cannot read directory ${dir}: ${error}`);
|
|
144
|
-
return [];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
async function expandGlobs(patterns, cwd) {
|
|
149
|
-
const files = (await Promise.all(patterns.map(async (i) => {
|
|
150
|
-
const pattern = path.resolve(cwd, i);
|
|
151
|
-
return isWild(i)
|
|
152
|
-
? await getDirs(path.dirname(pattern), globRe(path.basename(pattern)))
|
|
153
|
-
: pattern;
|
|
154
|
-
}))).flat();
|
|
155
|
-
return [...new Set(files)]; // Remove duplicates
|
|
156
|
-
}
|