@naturalcycles/js-lib 14.254.0 → 14.255.0
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/array/array.util.d.ts +5 -1
- package/dist/array/array.util.js +7 -6
- package/dist/error/tryCatch.js +1 -1
- package/dist/types.d.ts +15 -0
- package/dist-esm/array/array.util.js +7 -6
- package/dist-esm/error/tryCatch.js +1 -1
- package/package.json +1 -1
- package/src/array/array.util.ts +7 -6
- package/src/error/tryCatch.ts +1 -1
- package/src/types.ts +17 -0
|
@@ -161,11 +161,15 @@ export declare function _intersection<T>(a1: T[], a2: T[] | Set<T>): T[];
|
|
|
161
161
|
*/
|
|
162
162
|
export declare function _intersectsWith<T>(a1: T[], a2: T[] | Set<T>): boolean;
|
|
163
163
|
/**
|
|
164
|
+
* Returns array1 minus array2.
|
|
165
|
+
*
|
|
164
166
|
* @example
|
|
165
167
|
* _difference([2, 1], [2, 3])
|
|
166
168
|
* // [1]
|
|
169
|
+
*
|
|
170
|
+
* Passing second array as Set is more performant (it'll skip turning the array into Set in-place).
|
|
167
171
|
*/
|
|
168
|
-
export declare function _difference<T>(
|
|
172
|
+
export declare function _difference<T>(a1: T[], a2: T[] | Set<T>): T[];
|
|
169
173
|
/**
|
|
170
174
|
* Returns the sum of items, or 0 for empty array.
|
|
171
175
|
*/
|
package/dist/array/array.util.js
CHANGED
|
@@ -318,16 +318,17 @@ function _intersectsWith(a1, a2) {
|
|
|
318
318
|
return a1.some(v => a2set.has(v));
|
|
319
319
|
}
|
|
320
320
|
/**
|
|
321
|
+
* Returns array1 minus array2.
|
|
322
|
+
*
|
|
321
323
|
* @example
|
|
322
324
|
* _difference([2, 1], [2, 3])
|
|
323
325
|
* // [1]
|
|
326
|
+
*
|
|
327
|
+
* Passing second array as Set is more performant (it'll skip turning the array into Set in-place).
|
|
324
328
|
*/
|
|
325
|
-
function _difference(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
a = a.filter(c => !b.includes(c));
|
|
329
|
-
}
|
|
330
|
-
return a;
|
|
329
|
+
function _difference(a1, a2) {
|
|
330
|
+
const a2set = a2 instanceof Set ? a2 : new Set(a2);
|
|
331
|
+
return a1.filter(v => !a2set.has(v));
|
|
331
332
|
}
|
|
332
333
|
/**
|
|
333
334
|
* Returns the sum of items, or 0 for empty array.
|
package/dist/error/tryCatch.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import type { Promisable } from './typeFest';
|
|
2
|
+
declare const __brand: unique symbol;
|
|
3
|
+
interface Brand<B> {
|
|
4
|
+
[__brand]: B;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Helper to create "Branded" types.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
* export type MyId = Branded<string, 'MyId'>
|
|
11
|
+
*
|
|
12
|
+
* MyId can be assigned to a string,
|
|
13
|
+
* but string cannot be assigned to MyId without casting it (`as MyId`).
|
|
14
|
+
*/
|
|
15
|
+
export type Branded<T, B> = T & Brand<B>;
|
|
2
16
|
/**
|
|
3
17
|
* Map from String to String (or <T>).
|
|
4
18
|
*
|
|
@@ -292,3 +306,4 @@ export interface CommonClient extends AsyncDisposable {
|
|
|
292
306
|
disconnect: () => Promise<void>;
|
|
293
307
|
ping: () => Promise<void>;
|
|
294
308
|
}
|
|
309
|
+
export {};
|
|
@@ -277,16 +277,17 @@ export function _intersectsWith(a1, a2) {
|
|
|
277
277
|
return a1.some(v => a2set.has(v));
|
|
278
278
|
}
|
|
279
279
|
/**
|
|
280
|
+
* Returns array1 minus array2.
|
|
281
|
+
*
|
|
280
282
|
* @example
|
|
281
283
|
* _difference([2, 1], [2, 3])
|
|
282
284
|
* // [1]
|
|
285
|
+
*
|
|
286
|
+
* Passing second array as Set is more performant (it'll skip turning the array into Set in-place).
|
|
283
287
|
*/
|
|
284
|
-
export function _difference(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
a = a.filter(c => !b.includes(c));
|
|
288
|
-
}
|
|
289
|
-
return a;
|
|
288
|
+
export function _difference(a1, a2) {
|
|
289
|
+
const a2set = a2 instanceof Set ? a2 : new Set(a2);
|
|
290
|
+
return a1.filter(v => !a2set.has(v));
|
|
290
291
|
}
|
|
291
292
|
/**
|
|
292
293
|
* Returns the sum of items, or 0 for empty array.
|
package/package.json
CHANGED
package/src/array/array.util.ts
CHANGED
|
@@ -331,16 +331,17 @@ export function _intersectsWith<T>(a1: T[], a2: T[] | Set<T>): boolean {
|
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
/**
|
|
334
|
+
* Returns array1 minus array2.
|
|
335
|
+
*
|
|
334
336
|
* @example
|
|
335
337
|
* _difference([2, 1], [2, 3])
|
|
336
338
|
* // [1]
|
|
339
|
+
*
|
|
340
|
+
* Passing second array as Set is more performant (it'll skip turning the array into Set in-place).
|
|
337
341
|
*/
|
|
338
|
-
export function _difference<T>(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
a = a.filter(c => !b.includes(c))
|
|
342
|
-
}
|
|
343
|
-
return a
|
|
342
|
+
export function _difference<T>(a1: T[], a2: T[] | Set<T>): T[] {
|
|
343
|
+
const a2set = a2 instanceof Set ? a2 : new Set(a2)
|
|
344
|
+
return a1.filter(v => !a2set.has(v))
|
|
344
345
|
}
|
|
345
346
|
|
|
346
347
|
/**
|
package/src/error/tryCatch.ts
CHANGED
|
@@ -56,7 +56,7 @@ export function _tryCatch<T extends AnyFunction>(fn: T, opt: TryCatchOptions = {
|
|
|
56
56
|
|
|
57
57
|
if (onError) {
|
|
58
58
|
try {
|
|
59
|
-
return await onError(_anyToError(err))
|
|
59
|
+
return await onError(_anyToError(err))
|
|
60
60
|
} catch {}
|
|
61
61
|
}
|
|
62
62
|
// returns undefined, but doesn't rethrow
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { Promisable } from './typeFest'
|
|
2
2
|
|
|
3
|
+
declare const __brand: unique symbol
|
|
4
|
+
|
|
5
|
+
interface Brand<B> {
|
|
6
|
+
[__brand]: B
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Helper to create "Branded" types.
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
* export type MyId = Branded<string, 'MyId'>
|
|
14
|
+
*
|
|
15
|
+
* MyId can be assigned to a string,
|
|
16
|
+
* but string cannot be assigned to MyId without casting it (`as MyId`).
|
|
17
|
+
*/
|
|
18
|
+
export type Branded<T, B> = T & Brand<B>
|
|
19
|
+
|
|
3
20
|
/**
|
|
4
21
|
* Map from String to String (or <T>).
|
|
5
22
|
*
|