@isopodlabs/utilities 1.5.1 → 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/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 {
|