@rimbu/common 1.1.0 → 2.0.1
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/bun/async-optlazy.mts +18 -5
- package/dist/bun/internal.mts +0 -2
- package/dist/bun/optlazy.mts +12 -3
- package/dist/cjs/async-optlazy.cjs +60 -42
- package/dist/cjs/async-optlazy.cjs.map +1 -0
- package/dist/cjs/async-optlazy.d.cts +46 -0
- package/dist/cjs/collect.cjs +9 -31
- package/dist/cjs/collect.cjs.map +1 -0
- package/dist/cjs/collect.d.cts +29 -0
- package/dist/cjs/comp.cjs +519 -1598
- package/dist/cjs/comp.cjs.map +1 -0
- package/dist/cjs/comp.d.cts +239 -0
- package/dist/cjs/eq.cjs +375 -203
- package/dist/cjs/eq.cjs.map +1 -0
- package/dist/cjs/err.cjs +57 -50
- package/dist/cjs/err.cjs.map +1 -0
- package/dist/cjs/index-range.cjs +105 -109
- package/dist/cjs/index-range.cjs.map +1 -0
- package/dist/cjs/index-range.d.cts +42 -0
- package/dist/cjs/index.cjs +9 -1684
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +6 -0
- package/dist/cjs/internal.cjs +14 -1684
- package/dist/cjs/internal.cjs.map +1 -0
- package/dist/cjs/internal.d.cts +11 -0
- package/dist/cjs/optlazy.cjs +43 -36
- package/dist/cjs/optlazy.cjs.map +1 -0
- package/dist/cjs/optlazy.d.cts +42 -0
- package/dist/cjs/range.cjs +35 -49
- package/dist/cjs/range.cjs.map +1 -0
- package/dist/cjs/traverse-state.cjs +30 -46
- package/dist/cjs/traverse-state.cjs.map +1 -0
- package/dist/cjs/types.cjs +2 -17
- package/dist/cjs/types.cjs.map +1 -0
- package/dist/cjs/update.cjs +21 -32
- package/dist/cjs/update.cjs.map +1 -0
- package/dist/{types → esm}/async-optlazy.d.mts +10 -3
- package/dist/esm/async-optlazy.mjs +10 -4
- package/dist/esm/async-optlazy.mjs.map +1 -1
- package/dist/esm/comp.mjs.map +1 -1
- package/dist/esm/eq.d.mts +196 -0
- package/dist/esm/eq.mjs.map +1 -1
- package/dist/esm/err.d.mts +33 -0
- package/dist/esm/index-range.mjs.map +1 -1
- package/dist/{types → esm}/internal.d.mts +0 -2
- package/dist/esm/internal.mjs +0 -2
- package/dist/esm/internal.mjs.map +1 -1
- package/dist/{types → esm}/optlazy.d.mts +8 -2
- package/dist/esm/optlazy.mjs +7 -2
- package/dist/esm/optlazy.mjs.map +1 -1
- package/dist/esm/range.d.mts +35 -0
- package/dist/esm/range.mjs.map +1 -1
- package/dist/esm/traverse-state.d.mts +33 -0
- package/dist/esm/types.d.mts +31 -0
- package/dist/esm/update.d.mts +18 -0
- package/dist/esm/update.mjs.map +1 -1
- package/package.json +21 -14
- package/src/async-optlazy.mts +18 -5
- package/src/internal.mts +0 -2
- package/src/optlazy.mts +12 -3
- package/dist/bun/async-reducer.mts +0 -1157
- package/dist/bun/reducer.mts +0 -1025
- package/dist/cjs/async-reducer.cjs +0 -1621
- package/dist/cjs/reducer.cjs +0 -1621
- package/dist/esm/async-reducer.mjs +0 -638
- package/dist/esm/async-reducer.mjs.map +0 -1
- package/dist/esm/reducer.mjs +0 -669
- package/dist/esm/reducer.mjs.map +0 -1
- package/dist/types/async-reducer.d.mts +0 -542
- package/dist/types/reducer.d.mts +0 -542
- package/src/async-reducer.mts +0 -1157
- package/src/reducer.mts +0 -1025
- /package/dist/{types/eq.d.mts → cjs/eq.d.cts} +0 -0
- /package/dist/{types/err.d.mts → cjs/err.d.cts} +0 -0
- /package/dist/{types/range.d.mts → cjs/range.d.cts} +0 -0
- /package/dist/{types/traverse-state.d.mts → cjs/traverse-state.d.cts} +0 -0
- /package/dist/{types/types.d.mts → cjs/types.d.cts} +0 -0
- /package/dist/{types/update.d.mts → cjs/update.d.cts} +0 -0
- /package/dist/{types → esm}/collect.d.mts +0 -0
- /package/dist/{types → esm}/comp.d.mts +0 -0
- /package/dist/{types → esm}/index-range.d.mts +0 -0
- /package/dist/{types → esm}/index.d.mts +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function returning true if given `v1` and `v2` should be considered equal.
|
|
3
|
+
*/
|
|
4
|
+
export type Eq<T> = (v1: T, v2: T) => boolean;
|
|
5
|
+
export declare namespace Eq {
|
|
6
|
+
function convertAnyToString(value: any): string;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the default Eq instance, which is the Eq.anyDeepEq() instance.
|
|
9
|
+
*/
|
|
10
|
+
function defaultEq(): Eq<any>;
|
|
11
|
+
/**
|
|
12
|
+
* An Eq instance that uses `Object.is` to determine if two objects are equal.
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const eq = Eq.objectIs
|
|
16
|
+
* console.log(eq(5, 5))
|
|
17
|
+
* // => true
|
|
18
|
+
* console.log(eq(5, 'a'))
|
|
19
|
+
* // => false
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
const objectIs: Eq<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns an Eq instance for objects that have a `valueOf` method. It returns true if the `.valueOf` values of both given objects are equal.
|
|
25
|
+
* @typeparam T - the object type containing a valueOf function of type V
|
|
26
|
+
* @typeparam V - the valueOf result type
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const eq = Eq.valueOfEq()
|
|
30
|
+
* console.log(eq(new Number(5), new Number(5)))
|
|
31
|
+
* // => true
|
|
32
|
+
* console.log(eq(new Number(5), new Number(3)))
|
|
33
|
+
* // => false
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function valueOfEq<T extends {
|
|
37
|
+
valueOf(): V;
|
|
38
|
+
}, V>(): Eq<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns an Eq instance that compares Date objects according to their `valueOf` value.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const eq = Eq.dateEq()
|
|
44
|
+
* console.log(eq(new Date(2020, 1, 1), new Date(2020, 1, 1))
|
|
45
|
+
* // => true
|
|
46
|
+
* console.log(eq(new Date(2020, 1, 1), new Date(2020, 2, 1))
|
|
47
|
+
* // => false
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
function dateEq(): Eq<Date>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns an Eq instance that compares Iterables by comparing their elements with the given `itemEq` Eq instance.
|
|
53
|
+
* @typeparam T - the Iterable element type
|
|
54
|
+
* @param itemEq - (optional) the Eq instance to use to compare the Iterable's elements
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const eq = Eq.iterableEq();
|
|
58
|
+
* console.log(eq([1, 2, 3], [1, 2, 3])
|
|
59
|
+
* // => true
|
|
60
|
+
* console.log(eq([1, 2, 3], [1, 3, 2])
|
|
61
|
+
* // => false
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function iterableEq<T>(itemEq?: Eq<T>): Eq<Iterable<T>>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns an Eq instance that checks equality of objects containing property values of type V by iteratively
|
|
67
|
+
* applying given `valueEq` to each of the object's property values.
|
|
68
|
+
* @typeparam - the object property value type
|
|
69
|
+
* @param valueEq - (optional) the Eq instance to use to compare property values
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const eq = Eq.objectEq()
|
|
73
|
+
* console.log(eq({ a: 1, b: { c: 2 }}, { b: { c: 2 }, a: 1 }))
|
|
74
|
+
* // => true
|
|
75
|
+
* console.log(eq({ a: 1, b: { c: 2 }}, { a: 1, b: { c: 3 }}))
|
|
76
|
+
* // => false
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
function objectEq<V = any>(valueEq?: Eq<V>): Eq<Record<any, V>>;
|
|
80
|
+
/**
|
|
81
|
+
* Returns an Eq instance that checks equality of any values. For composed values (objects and iterables)
|
|
82
|
+
* it will compare with Object.is.
|
|
83
|
+
* @typeparam T - the value type
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const eq = anyFlatEq()
|
|
87
|
+
* console.log(eq(1, 'a'))
|
|
88
|
+
* // => false
|
|
89
|
+
* console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
|
|
90
|
+
* // => false
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
function anyFlatEq<T = any>(): Eq<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Returns an Eq instance that checks equality of any values. For composed values (objects and iterables)
|
|
96
|
+
* it will enter 1 level, and if again compound values are found, they are compared
|
|
97
|
+
* with Object.is.
|
|
98
|
+
* @typeparam T - the value type
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const eq = anyFlatEq()
|
|
102
|
+
* console.log(eq(1, 'a'))
|
|
103
|
+
* // => false
|
|
104
|
+
* console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
|
|
105
|
+
* // => true
|
|
106
|
+
* console.log(eq([{ a: 1, b: 2 }], [{ b: 2, a: 1 }]))
|
|
107
|
+
* // => false
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
function anyShallowEq<T = any>(): Eq<T>;
|
|
111
|
+
/**
|
|
112
|
+
* Returns an Eq instance that checks equality of any values. For composed values (objects and iterables)
|
|
113
|
+
* it will recursively compare the contained values.
|
|
114
|
+
* @note may have poor performance for deeply nested types and large arrays, and objects with circular structures
|
|
115
|
+
* may cause infinite loops
|
|
116
|
+
* @typeparam T - the value type
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const eq = anyFlatEq()
|
|
120
|
+
* console.log(eq(1, 'a'))
|
|
121
|
+
* // => false
|
|
122
|
+
* console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
|
|
123
|
+
* // => true
|
|
124
|
+
* console.log(eq([{ a: 1, b: 2 }], [{ b: 2, a: 1 }]))
|
|
125
|
+
* // => false
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
function anyDeepEq<T = any>(): Eq<T>;
|
|
129
|
+
/**
|
|
130
|
+
* Returns an Eq instance that considers strings equal taking the given or default locale into account.
|
|
131
|
+
* @param locales - (optional) a locale or list of locales
|
|
132
|
+
* @param options - (optional) see String.localeCompare for details
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const eq = Eq.createStringCollatorEq()
|
|
136
|
+
* console.log(eq('a', 'a'))
|
|
137
|
+
* // => true
|
|
138
|
+
* console.log(eq('abc', 'aBc'))
|
|
139
|
+
* // => false
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
function createStringCollatorEq(...args: ConstructorParameters<typeof Intl.Collator>): Eq<string>;
|
|
143
|
+
/**
|
|
144
|
+
* Returns an Eq instance that considers strings equal regardless of their case.
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const eq = Eq.stringCaseInsentitiveEq()
|
|
148
|
+
* console.log(eq('aB', 'Ab'))
|
|
149
|
+
* // => true
|
|
150
|
+
* console.log(eq('aBc', 'abB'))
|
|
151
|
+
* // => false
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function stringCaseInsentitiveEq(): Eq<string>;
|
|
155
|
+
/**
|
|
156
|
+
* Returns an Eq instance that considers strings equal when all their charcodes are equal.
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* const eq = Eq.stringCharCodeEq()
|
|
160
|
+
* console.log(eq('a', 'a'))
|
|
161
|
+
* // => true
|
|
162
|
+
* console.log(eq('abc', 'aBc'))
|
|
163
|
+
* // => false
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
function stringCharCodeEq(): Eq<string>;
|
|
167
|
+
function anyToStringEq(): Eq<any>;
|
|
168
|
+
/**
|
|
169
|
+
* Returns an Eq instance that considers values equal their JSON.stringify values are equal.
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const eq = Eq.anyJsonEq()
|
|
173
|
+
* console.log(eq({ a: 1, b: 2 }, { a: 1, b: 2 }))
|
|
174
|
+
* // => true
|
|
175
|
+
* console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
|
|
176
|
+
* // => false
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
function anyJsonEq(): Eq<any>;
|
|
180
|
+
/**
|
|
181
|
+
* Returns an `Eq` instance for tuples that considers two tuples [A, B] and [C, D] equal if [A, B] equals [C, D],
|
|
182
|
+
* or if [A, B] equals [D, C]
|
|
183
|
+
* @param eq - (optional) an alternative `Eq` instance to use for the values in the tuple
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* const eq = Eq.tupleSymmetric()
|
|
187
|
+
* console.log(eq([1, 2], [1, 2]))
|
|
188
|
+
* // => true
|
|
189
|
+
* console.log(eq([1, 2], [2, 1]))
|
|
190
|
+
* // => true
|
|
191
|
+
* console.log(eq([1, 3], [2, 1]))
|
|
192
|
+
* // => false
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
function tupleSymmetric<T>(eq?: Eq<T>): Eq<readonly [T, T]>;
|
|
196
|
+
}
|
package/dist/esm/eq.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eq.mjs","sourceRoot":"","sources":["../../src/eq.mts"],"names":[],"mappings":"AAKA,MAAM,KAAW,EAAE,CAgZlB;AAhZD,WAAiB,EAAE;IACjB,SAAgB,kBAAkB,CAAC,KAAU;QAC3C,IACE,OAAO,KAAK,KAAK,QAAQ;YACzB,IAAI,KAAK,KAAK;YACd,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC;YACtB,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU;YACpC,KAAK,CAAC,QAAQ,KAAK,MAAM,CAAC,SAAS,CAAC,QAAQ,EAC5C;
|
|
1
|
+
{"version":3,"file":"eq.mjs","sourceRoot":"","sources":["../../src/eq.mts"],"names":[],"mappings":"AAKA,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E,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;IANe,iBAAc,iBAM7B,CAAA;AACH,CAAC,EAhZgB,EAAE,KAAF,EAAE,QAgZlB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws an `Err.ForcedError` error when called.
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* const emptyMap = HashMap.empty<number, string>()
|
|
6
|
+
* emptyMap.get(5, Err);
|
|
7
|
+
* // throws: Err.CustomError(message: 'Err: forced to throw error')
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function Err(): never;
|
|
11
|
+
export declare namespace ErrBase {
|
|
12
|
+
/**
|
|
13
|
+
* A custom error instance.
|
|
14
|
+
*/
|
|
15
|
+
abstract class CustomError {
|
|
16
|
+
readonly message: string;
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
get name(): string;
|
|
19
|
+
}
|
|
20
|
+
class ForcedError extends CustomError {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns a function that, when called, throws an `Err.ForcedError` with the given `message` string.
|
|
24
|
+
* @param message - the message to put in the `Err.ForcedError` instance.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const emptyMap = HashMap.empty<number, string>()
|
|
28
|
+
* emptyMap.get(5, ErrBase.msg('not found'));
|
|
29
|
+
* // throws: Err.CustomError(message: 'not found')
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function msg(message: string): () => never;
|
|
33
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-range.mjs","sourceRoot":"","sources":["../../src/index-range.mts"],"names":[],"mappings":"AAwBA,MAAM,KAAW,UAAU,CA+F1B;AA/FD,WAAiB,UAAU;IACzB;;;;OAIG;IACH,SAAgB,oBAAoB,CAClC,KAAiB;QAEjB,IAAI,SAAS,KAAK,KAAK,CAAC,MAAM,EA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CAAC;IA7Ce,wBAAa,gBA6C5B,CAAA;AACH,CAAC,EA/FgB,UAAU,KAAV,UAAU,QA+F1B"}
|
|
@@ -5,9 +5,7 @@ export * from './err.mjs';
|
|
|
5
5
|
export * from './index-range.mjs';
|
|
6
6
|
export * from './optlazy.mjs';
|
|
7
7
|
export * from './range.mjs';
|
|
8
|
-
export * from './reducer.mjs';
|
|
9
8
|
export * from './traverse-state.mjs';
|
|
10
9
|
export * from './types.mjs';
|
|
11
10
|
export * from './update.mjs';
|
|
12
11
|
export * from './async-optlazy.mjs';
|
|
13
|
-
export * from './async-reducer.mjs';
|
package/dist/esm/internal.mjs
CHANGED
|
@@ -5,10 +5,8 @@ export * from './err.mjs';
|
|
|
5
5
|
export * from './index-range.mjs';
|
|
6
6
|
export * from './optlazy.mjs';
|
|
7
7
|
export * from './range.mjs';
|
|
8
|
-
export * from './reducer.mjs';
|
|
9
8
|
export * from './traverse-state.mjs';
|
|
10
9
|
export * from './types.mjs';
|
|
11
10
|
export * from './update.mjs';
|
|
12
11
|
export * from './async-optlazy.mjs';
|
|
13
|
-
export * from './async-reducer.mjs';
|
|
14
12
|
//# sourceMappingURL=internal.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.mjs","sourceRoot":"","sources":["../../src/internal.mts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"internal.mjs","sourceRoot":"","sources":["../../src/internal.mts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A potentially lazy value of type T.
|
|
3
3
|
* @typeparam T - the value type
|
|
4
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
4
5
|
*/
|
|
5
|
-
export type OptLazy<T> = T | (() => T);
|
|
6
|
+
export type OptLazy<T, A extends any[] = []> = T | ((...args: A) => T);
|
|
6
7
|
/**
|
|
7
8
|
* Returns the value contained in an `OptLazy` instance of type T.
|
|
8
9
|
* @param optLazy - the `OptLazy` value of type T
|
|
10
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
11
|
+
* @typeparam T - the value type
|
|
12
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
9
13
|
* @example
|
|
10
14
|
* ```ts
|
|
11
15
|
* OptLazy(1) // => 1
|
|
@@ -13,7 +17,7 @@ export type OptLazy<T> = T | (() => T);
|
|
|
13
17
|
* OptLazy(() => () => 1) // => () => 1
|
|
14
18
|
* ```
|
|
15
19
|
*/
|
|
16
|
-
export declare function OptLazy<T>(optLazy: OptLazy<T
|
|
20
|
+
export declare function OptLazy<T, A extends any[] = []>(optLazy: OptLazy<T, A>, ...args: A): T;
|
|
17
21
|
/**
|
|
18
22
|
* A potentially lazy value that, in case of a lazy function, received a default value
|
|
19
23
|
* that it can return.
|
|
@@ -26,6 +30,8 @@ export type OptLazyOr<T, O> = T | ((none: O) => T | O);
|
|
|
26
30
|
* `otherValue` if the lazy function returns it.
|
|
27
31
|
* @param optLazyOr - a value or a function returning a value or otherwise the received value
|
|
28
32
|
* @param otherValue - the value to return if the optLazyOr does not return its own value
|
|
33
|
+
* @typeparam T - the value type
|
|
34
|
+
* @typeparam O - the default value type
|
|
29
35
|
* @example
|
|
30
36
|
* ```ts
|
|
31
37
|
* OptLazyOr(1, 'a') // => 1
|
package/dist/esm/optlazy.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns the value contained in an `OptLazy` instance of type T.
|
|
3
3
|
* @param optLazy - the `OptLazy` value of type T
|
|
4
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
5
|
+
* @typeparam T - the value type
|
|
6
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
4
7
|
* @example
|
|
5
8
|
* ```ts
|
|
6
9
|
* OptLazy(1) // => 1
|
|
@@ -8,9 +11,9 @@
|
|
|
8
11
|
* OptLazy(() => () => 1) // => () => 1
|
|
9
12
|
* ```
|
|
10
13
|
*/
|
|
11
|
-
export function OptLazy(optLazy) {
|
|
14
|
+
export function OptLazy(optLazy, ...args) {
|
|
12
15
|
if (optLazy instanceof Function)
|
|
13
|
-
return optLazy();
|
|
16
|
+
return optLazy(...args);
|
|
14
17
|
return optLazy;
|
|
15
18
|
}
|
|
16
19
|
/**
|
|
@@ -18,6 +21,8 @@ export function OptLazy(optLazy) {
|
|
|
18
21
|
* `otherValue` if the lazy function returns it.
|
|
19
22
|
* @param optLazyOr - a value or a function returning a value or otherwise the received value
|
|
20
23
|
* @param otherValue - the value to return if the optLazyOr does not return its own value
|
|
24
|
+
* @typeparam T - the value type
|
|
25
|
+
* @typeparam O - the default value type
|
|
21
26
|
* @example
|
|
22
27
|
* ```ts
|
|
23
28
|
* OptLazyOr(1, 'a') // => 1
|
package/dist/esm/optlazy.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optlazy.mjs","sourceRoot":"","sources":["../../src/optlazy.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"optlazy.mjs","sourceRoot":"","sources":["../../src/optlazy.mts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,OAAO,CACrB,OAAsB,EACtB,GAAG,IAAO;IAEV,IAAI,OAAO,YAAY,QAAQ;QAAE,OAAO,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACzD,OAAO,OAAO,CAAC;AACjB,CAAC;AAUD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CACvB,SAA0B,EAC1B,UAAa;IAEb,IAAI,SAAS,YAAY,QAAQ;QAAE,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC;IAChE,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A range definition for any type of (orderable) value.
|
|
3
|
+
* If a start or end is defined, a tuple can be used where the second item is a boolean
|
|
4
|
+
* indicating whether that end is inclusive (true) or exclusive (false).<br/>
|
|
5
|
+
* A Range of type T can have one of the following forms:<br/>
|
|
6
|
+
* <br/>
|
|
7
|
+
* - { end: T }<br/>
|
|
8
|
+
* - { end: [T, boolean] }<br/>
|
|
9
|
+
* - { start: T }<br/>
|
|
10
|
+
* - { start: T, end: T }<br/>
|
|
11
|
+
* - { start: T, end: [T, boolean] }<br/>
|
|
12
|
+
* - { start: [T, boolean] }<br/>
|
|
13
|
+
* - { start: [T, boolean], end: T }<br/>
|
|
14
|
+
* - { start: [T, boolean], end: [T, boolean] }<br/>
|
|
15
|
+
*/
|
|
16
|
+
export type Range<T> = {
|
|
17
|
+
start: T | [T, boolean];
|
|
18
|
+
end?: T | [T, boolean];
|
|
19
|
+
amount?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
start?: T | [T, boolean];
|
|
22
|
+
end: T | [T, boolean];
|
|
23
|
+
amount?: undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare namespace Range {
|
|
26
|
+
/**
|
|
27
|
+
* Simplifies a given `range` `Range` input for easier processing, by returning optional
|
|
28
|
+
* start and end ranges including whether they are inclusive or exclusive
|
|
29
|
+
* @param range - the `Range` to use
|
|
30
|
+
*/
|
|
31
|
+
function getNormalizedRange<T>(range: Range<T>): {
|
|
32
|
+
start?: [T, boolean] | undefined;
|
|
33
|
+
end?: [T, boolean] | undefined;
|
|
34
|
+
};
|
|
35
|
+
}
|
package/dist/esm/range.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.mjs","sourceRoot":"","sources":["../../src/range.mts"],"names":[],"mappings":"AAmBA,MAAM,KAAW,KAAK,CAsCrB;AAtCD,WAAiB,KAAK;IACpB;;;;OAIG;IACH,SAAgB,kBAAkB,CAAI,KAAe;QAInD,IAAI,KAAK,GAA6B,SAAS,CAAC;QAChD,IAAI,GAAG,GAA6B,SAAS,CAAC;QAE9C,IAAI,OAAO,IAAI,KAAK,IAAI,SAAS,KAAK,KAAK,CAAC,KAAK,EAAE;
|
|
1
|
+
{"version":3,"file":"range.mjs","sourceRoot":"","sources":["../../src/range.mts"],"names":[],"mappings":"AAmBA,MAAM,KAAW,KAAK,CAsCrB;AAtCD,WAAiB,KAAK;IACpB;;;;OAIG;IACH,SAAgB,kBAAkB,CAAI,KAAe;QAInD,IAAI,KAAK,GAA6B,SAAS,CAAC;QAChD,IAAI,GAAG,GAA6B,SAAS,CAAC;QAE9C,IAAI,OAAO,IAAI,KAAK,IAAI,SAAS,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;YAClD,IACE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC1B,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;gBACxB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,EACnC,CAAC;gBACD,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,KAAK,GAAG,CAAC,KAAK,CAAC,KAAU,EAAE,IAAI,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QACD,IAAI,KAAK,IAAI,KAAK,IAAI,SAAS,KAAK,KAAK,CAAC,GAAG,EAAE,CAAC;YAC9C,IACE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;gBACxB,KAAK,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC;gBACtB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,EACjC,CAAC;gBACD,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAClB,CAAC;iBAAM,CAAC;gBACN,GAAG,GAAG,CAAC,KAAK,CAAC,GAAQ,EAAE,IAAI,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IACxB,CAAC;IA/Be,wBAAkB,qBA+BjC,CAAA;AACH,CAAC,EAtCgB,KAAK,KAAL,KAAK,QAsCrB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object used to track the state of a traversal, e.g. a `forEach`.
|
|
3
|
+
*/
|
|
4
|
+
export interface TraverseState {
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if the traversal has been halted by the user.
|
|
7
|
+
*/
|
|
8
|
+
readonly halted: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the current index of the traversal.
|
|
11
|
+
*/
|
|
12
|
+
readonly currentIndex: number;
|
|
13
|
+
/**
|
|
14
|
+
* Increases the `currentIndex` of this traversal
|
|
15
|
+
* @returns the next index that the traversal should use
|
|
16
|
+
*/
|
|
17
|
+
nextIndex(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the `halted` value to true.
|
|
20
|
+
*/
|
|
21
|
+
halt(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the `halted` value to false, and resets the `currentIndex`
|
|
24
|
+
* value to its start value.
|
|
25
|
+
*/
|
|
26
|
+
reset(): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns a new `TraverseState` instance, using optionally given `startIndex` as a start
|
|
30
|
+
* index value.
|
|
31
|
+
* @param startIndex - (default: 0) the start index to use
|
|
32
|
+
*/
|
|
33
|
+
export declare function TraverseState(startIndex?: number): TraverseState;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accepts all types of T and U where T extends U,
|
|
3
|
+
* and result in the upper bound U.
|
|
4
|
+
*/
|
|
5
|
+
export type SuperOf<U, T> = T extends U ? U : never;
|
|
6
|
+
/**
|
|
7
|
+
* Accepts all types of T and S where S extends T,
|
|
8
|
+
* and results in the lower bound S.
|
|
9
|
+
*/
|
|
10
|
+
export type SubOf<S, T> = S extends T ? S : never;
|
|
11
|
+
/**
|
|
12
|
+
* Accepts all types of T and U where T extends U or U extends T.
|
|
13
|
+
*/
|
|
14
|
+
export type RelatedTo<T, U> = T | SuperOf<U, T>;
|
|
15
|
+
/**
|
|
16
|
+
* Accepts all arrays with at least one element.
|
|
17
|
+
*/
|
|
18
|
+
export type ArrayNonEmpty<T> = [T, ...T[]];
|
|
19
|
+
/**
|
|
20
|
+
* Accepts all strings with at least one character.
|
|
21
|
+
*/
|
|
22
|
+
export type StringNonEmpty<T> = T extends string ? '' extends T ? never : T : never;
|
|
23
|
+
/**
|
|
24
|
+
* Utility type to convert some object to a JSON serializable format.
|
|
25
|
+
* @typeparam V - the `value` type
|
|
26
|
+
* @typeparam D - the `dataType` tag string type
|
|
27
|
+
*/
|
|
28
|
+
export interface ToJSON<V, D extends string = string> {
|
|
29
|
+
readonly dataType: D;
|
|
30
|
+
readonly value: V;
|
|
31
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value of type T, or a function taking a value of type T and returning a new value of type T.
|
|
3
|
+
*/
|
|
4
|
+
export type Update<T> = T | ((value: T) => T);
|
|
5
|
+
/**
|
|
6
|
+
* Returns the result of given `update` parameter, where it can either directly give a new value,
|
|
7
|
+
* or it is a function receiving the given `value`, and returns a new value.
|
|
8
|
+
* @param value - the current value
|
|
9
|
+
* @param update - an `Update` value, either a new value or a function receiving the old value
|
|
10
|
+
* and returning a new one.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* Update(1, 2) // => 2
|
|
14
|
+
* Update(1, () => 10) // => 10
|
|
15
|
+
* Update(1, v => v + 1) // => 2
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function Update<T>(value: T, update: Update<T>): T;
|
package/dist/esm/update.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.mjs","sourceRoot":"","sources":["../../src/update.mts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,MAAM,CAAI,KAAQ,EAAE,MAAiB;IACnD,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"update.mjs","sourceRoot":"","sources":["../../src/update.mts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,MAAM,CAAI,KAAQ,EAAE,MAAiB;IACnD,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,OAAQ,MAA0B,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimbu/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Common types and objects used in many other Rimbu packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"common",
|
|
@@ -31,14 +31,18 @@
|
|
|
31
31
|
"type": "module",
|
|
32
32
|
"main": "./dist/cjs/index.cjs",
|
|
33
33
|
"module": "./dist/esm/index.mjs",
|
|
34
|
-
"types": "./dist/
|
|
34
|
+
"types": "./dist/cjs/index.d.cts",
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./dist/esm/index.d.mts",
|
|
39
|
+
"default": "./dist/esm/index.mjs"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/cjs/index.d.cts",
|
|
43
|
+
"default": "./dist/cjs/index.cjs"
|
|
44
|
+
},
|
|
45
|
+
"bun": "./dist/bun/index.mts"
|
|
42
46
|
}
|
|
43
47
|
},
|
|
44
48
|
"files": [
|
|
@@ -46,19 +50,22 @@
|
|
|
46
50
|
"src"
|
|
47
51
|
],
|
|
48
52
|
"scripts": {
|
|
53
|
+
"b": "duel",
|
|
49
54
|
"build": "yarn clean && yarn bundle",
|
|
50
55
|
"build:deno": "yarn bundle:deno-prepare && yarn bundle:deno-convert && yarn bundle:deno-move && yarn bundle:deno-clean",
|
|
51
|
-
"bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:
|
|
52
|
-
"bundle:bun": "node ../../config/bunnify.mjs",
|
|
53
|
-
"bundle:cjs": "
|
|
56
|
+
"bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:bun",
|
|
57
|
+
"bundle:bun": "node ../../config/bunnify.mjs -mode bun",
|
|
58
|
+
"bundle:cjs": "yarn bundle:cjs-prepare && yarn bundle:cjs-build && yarn bundle:cjs-clean",
|
|
59
|
+
"bundle:cjs-prepare": "node ../../config/bunnify.mjs -mode cjs",
|
|
60
|
+
"bundle:cjs-build": "tsc -p tsconfig.cjs.json",
|
|
61
|
+
"bundle:cjs-clean": "rimraf _cjs_prepare",
|
|
54
62
|
"bundle:deno-prepare": "node ../../config/prepare-denoify.mjs",
|
|
55
63
|
"bundle:deno-convert": "denoify --src _deno_prepare/src",
|
|
56
64
|
"bundle:deno-move": "rimraf ../../deno_dist/common && mv deno_dist ../../deno_dist/common",
|
|
57
65
|
"bundle:deno-clean": "rimraf _deno_prepare",
|
|
58
66
|
"bundle:esm": "tsc --p tsconfig.esm.json",
|
|
59
|
-
"bundle:types": "tsc --p tsconfig.types.json",
|
|
60
67
|
"clean": "rimraf dist",
|
|
61
|
-
"extract-api": "ts-node ../../config/api-extractor.ts
|
|
68
|
+
"extract-api": "ts-node ../../config/api-extractor.ts config/api-extractor.main.json",
|
|
62
69
|
"format": "yarn format:base --write",
|
|
63
70
|
"format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,mts,mjs,json,md}\"",
|
|
64
71
|
"format:check": "yarn format:base --check",
|
|
@@ -73,7 +80,7 @@
|
|
|
73
80
|
"access": "public"
|
|
74
81
|
},
|
|
75
82
|
"dependencies": {
|
|
76
|
-
"tslib": "^2.6.
|
|
83
|
+
"tslib": "^2.6.2"
|
|
77
84
|
},
|
|
78
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "b7ed656d2c55d1a715d6a3f52e364e68cb98c759"
|
|
79
86
|
}
|
package/src/async-optlazy.mts
CHANGED
|
@@ -9,13 +9,17 @@ export type MaybePromise<T> = T | Promise<T>;
|
|
|
9
9
|
/**
|
|
10
10
|
* A potentially lazy and/or asynchronous value of type T.
|
|
11
11
|
* @typeparam T - the value type
|
|
12
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
12
13
|
*/
|
|
13
|
-
export type AsyncOptLazy<T> = OptLazy<MaybePromise<T
|
|
14
|
+
export type AsyncOptLazy<T, A extends any[] = []> = OptLazy<MaybePromise<T>, A>;
|
|
14
15
|
|
|
15
16
|
export namespace AsyncOptLazy {
|
|
16
17
|
/**
|
|
17
18
|
* Returns the value or promised value contained in an `AsyncOptLazy` instance of type T.
|
|
18
19
|
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
20
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
21
|
+
* @typeparam T - the value type
|
|
22
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
19
23
|
* @example
|
|
20
24
|
* ```ts
|
|
21
25
|
* AsyncOptLazy.toMaybePromise(1) // => 1
|
|
@@ -25,14 +29,20 @@ export namespace AsyncOptLazy {
|
|
|
25
29
|
* AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)
|
|
26
30
|
* ```
|
|
27
31
|
*/
|
|
28
|
-
export function toMaybePromise<T
|
|
29
|
-
|
|
32
|
+
export function toMaybePromise<T, A extends any[] = []>(
|
|
33
|
+
optLazy: AsyncOptLazy<T, A>,
|
|
34
|
+
...args: A
|
|
35
|
+
): MaybePromise<T> {
|
|
36
|
+
if (optLazy instanceof Function) return optLazy(...args);
|
|
30
37
|
return optLazy;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
/**
|
|
34
41
|
* Returns the value contained in an `AsyncOptLazy` instance of type T as a promise.
|
|
35
42
|
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
43
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
44
|
+
* @typeparam T - the value type
|
|
45
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
36
46
|
* @example
|
|
37
47
|
* ```ts
|
|
38
48
|
* AsyncOptLazy.toPromise(1) // => Promise(1)
|
|
@@ -42,8 +52,11 @@ export namespace AsyncOptLazy {
|
|
|
42
52
|
* AsyncOptLazy.toPromise(Promise.resolve(1)) // => Promise(1)
|
|
43
53
|
* ```
|
|
44
54
|
*/
|
|
45
|
-
export async function toPromise<T
|
|
46
|
-
|
|
55
|
+
export async function toPromise<T, A extends any[] = []>(
|
|
56
|
+
optLazy: AsyncOptLazy<T, A>,
|
|
57
|
+
...args: A
|
|
58
|
+
): Promise<T> {
|
|
59
|
+
if (optLazy instanceof Function) return optLazy(...args);
|
|
47
60
|
return optLazy;
|
|
48
61
|
}
|
|
49
62
|
}
|
package/src/internal.mts
CHANGED
|
@@ -5,9 +5,7 @@ export * from './err.mjs';
|
|
|
5
5
|
export * from './index-range.mjs';
|
|
6
6
|
export * from './optlazy.mjs';
|
|
7
7
|
export * from './range.mjs';
|
|
8
|
-
export * from './reducer.mjs';
|
|
9
8
|
export * from './traverse-state.mjs';
|
|
10
9
|
export * from './types.mjs';
|
|
11
10
|
export * from './update.mjs';
|
|
12
11
|
export * from './async-optlazy.mjs';
|
|
13
|
-
export * from './async-reducer.mjs';
|