@naturalcycles/js-lib 15.104.0 → 15.106.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 +8 -6
- package/dist/array/array.util.js +2 -0
- package/dist/datetime/dateInterval.js +2 -3
- package/dist/datetime/timeInterval.js +2 -3
- package/dist/enum.util.js +1 -0
- package/package.json +2 -2
- package/src/array/array.util.ts +8 -6
- package/src/datetime/dateInterval.ts +2 -3
- package/src/datetime/timeInterval.ts +2 -3
- package/src/enum.util.ts +2 -0
- package/src/qr/qr.ts +1 -0
|
@@ -195,26 +195,28 @@ export declare function _mapToObject<T, V>(array: Iterable<T>, mapper: (item: T)
|
|
|
195
195
|
* Based on: https://stackoverflow.com/a/12646864/4919972
|
|
196
196
|
*/
|
|
197
197
|
export declare function _shuffle<T>(array: T[], opt?: MutateOptions): T[];
|
|
198
|
-
export declare function _firstLast<T>(array:
|
|
199
|
-
export declare function _firstLastOrUndefined<T>(array:
|
|
198
|
+
export declare function _firstLast<T>(array: ArrayLike<T>): [first: T, last: T];
|
|
199
|
+
export declare function _firstLastOrUndefined<T>(array: ArrayLike<T>): [first: T, last: T] | undefined;
|
|
200
200
|
/**
|
|
201
201
|
* Returns last item of non-empty array.
|
|
202
202
|
* Throws if array is empty.
|
|
203
|
+
* Accepts any array-like value, e.g. a Uint8Array, a NodeList or a string.
|
|
203
204
|
*/
|
|
204
|
-
export declare function _last<T>(array:
|
|
205
|
+
export declare function _last<T>(array: ArrayLike<T>): T;
|
|
205
206
|
/**
|
|
206
207
|
* Returns last item of the array (or undefined if array is empty).
|
|
207
208
|
*/
|
|
208
|
-
export declare function _lastOrUndefined<T>(array:
|
|
209
|
+
export declare function _lastOrUndefined<T>(array: ArrayLike<T>): T | undefined;
|
|
209
210
|
/**
|
|
210
211
|
* Returns the first item of non-empty array.
|
|
211
212
|
* Throws if array is empty.
|
|
213
|
+
* Accepts any array-like value, e.g. a Uint8Array, a NodeList or a string.
|
|
212
214
|
*/
|
|
213
|
-
export declare function _first<T>(array:
|
|
215
|
+
export declare function _first<T>(array: ArrayLike<T>): T;
|
|
214
216
|
/**
|
|
215
217
|
* Returns first item of the array (or undefined if array is empty).
|
|
216
218
|
*/
|
|
217
|
-
export declare function _firstOrUndefined<T>(array:
|
|
219
|
+
export declare function _firstOrUndefined<T>(array: ArrayLike<T>): T | undefined;
|
|
218
220
|
/**
|
|
219
221
|
* Type guard that narrows an array to NonEmptyArray (array with at least one element).
|
|
220
222
|
* Readonly arrays are narrowed to `Readonly<NonEmptyArray<T>>`.
|
package/dist/array/array.util.js
CHANGED
|
@@ -378,6 +378,7 @@ export function _firstLastOrUndefined(array) {
|
|
|
378
378
|
/**
|
|
379
379
|
* Returns last item of non-empty array.
|
|
380
380
|
* Throws if array is empty.
|
|
381
|
+
* Accepts any array-like value, e.g. a Uint8Array, a NodeList or a string.
|
|
381
382
|
*/
|
|
382
383
|
export function _last(array) {
|
|
383
384
|
_assert(array.length, '_last called on empty array');
|
|
@@ -392,6 +393,7 @@ export function _lastOrUndefined(array) {
|
|
|
392
393
|
/**
|
|
393
394
|
* Returns the first item of non-empty array.
|
|
394
395
|
* Throws if array is empty.
|
|
396
|
+
* Accepts any array-like value, e.g. a Uint8Array, a NodeList or a string.
|
|
395
397
|
*/
|
|
396
398
|
export function _first(array) {
|
|
397
399
|
_assert(array.length, '_first called on empty array');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _assert } from '../error/assert.js';
|
|
1
2
|
import { localDate } from './localDate.js';
|
|
2
3
|
/**
|
|
3
4
|
* Class that supports ISO8601 "Time interval" standard that looks like `2022-02-24/2022-03-30`.
|
|
@@ -21,9 +22,7 @@ export class DateInterval {
|
|
|
21
22
|
if (d instanceof DateInterval)
|
|
22
23
|
return d;
|
|
23
24
|
const [start, end] = d.split('/');
|
|
24
|
-
|
|
25
|
-
throw new Error(`Cannot parse "${d}" into DateInterval`);
|
|
26
|
-
}
|
|
25
|
+
_assert(end && start, `Cannot parse "${d}" into DateInterval`);
|
|
27
26
|
return new DateInterval(localDate(start), localDate(end));
|
|
28
27
|
}
|
|
29
28
|
isSame(d) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _assert } from '../error/assert.js';
|
|
1
2
|
import { localTime } from './localTime.js';
|
|
2
3
|
/**
|
|
3
4
|
* Class that supports an "interval of time" between 2 timestamps - start and end.
|
|
@@ -34,9 +35,7 @@ export class TimeInterval {
|
|
|
34
35
|
if (d instanceof TimeInterval)
|
|
35
36
|
return d;
|
|
36
37
|
const [start, end] = d.split('/').map(Number);
|
|
37
|
-
|
|
38
|
-
throw new Error(`Cannot parse "${d}" into TimeInterval`);
|
|
39
|
-
}
|
|
38
|
+
_assert(end && start, `Cannot parse "${d}" into TimeInterval`);
|
|
40
39
|
return new TimeInterval(start, end);
|
|
41
40
|
}
|
|
42
41
|
isSame(d) {
|
package/dist/enum.util.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// oxlint-disable nc/prefer-assert -- no runtime imports here, and the lookups run in hot paths: the message is only built on failure
|
|
1
2
|
/**
|
|
2
3
|
* Creates a runtime Enum object. A replacement for a native TypeScript enum,
|
|
3
4
|
* which is not supported by type-stripping runtimes (e.g `node --experimental-strip-types`).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.106.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2"
|
|
7
7
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@naturalcycles/dev-lib": "
|
|
17
|
+
"@naturalcycles/dev-lib": "20.78.0",
|
|
18
18
|
"@types/node": "^26",
|
|
19
19
|
"@types/semver": "^7",
|
|
20
20
|
"rolldown": "^1",
|
package/src/array/array.util.ts
CHANGED
|
@@ -432,12 +432,12 @@ export function _shuffle<T>(array: T[], opt: MutateOptions = {}): T[] {
|
|
|
432
432
|
return a
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
export function _firstLast<T>(array:
|
|
435
|
+
export function _firstLast<T>(array: ArrayLike<T>): [first: T, last: T] {
|
|
436
436
|
_assert(array.length, '_firstLast called on empty array')
|
|
437
437
|
return [array[0]!, array[array.length - 1]!]
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
-
export function _firstLastOrUndefined<T>(array:
|
|
440
|
+
export function _firstLastOrUndefined<T>(array: ArrayLike<T>): [first: T, last: T] | undefined {
|
|
441
441
|
if (!array.length) return
|
|
442
442
|
return [array[0]!, array[array.length - 1]!]
|
|
443
443
|
}
|
|
@@ -445,8 +445,9 @@ export function _firstLastOrUndefined<T>(array: readonly T[]): [first: T, last:
|
|
|
445
445
|
/**
|
|
446
446
|
* Returns last item of non-empty array.
|
|
447
447
|
* Throws if array is empty.
|
|
448
|
+
* Accepts any array-like value, e.g. a Uint8Array, a NodeList or a string.
|
|
448
449
|
*/
|
|
449
|
-
export function _last<T>(array:
|
|
450
|
+
export function _last<T>(array: ArrayLike<T>): T {
|
|
450
451
|
_assert(array.length, '_last called on empty array')
|
|
451
452
|
return array[array.length - 1]!
|
|
452
453
|
}
|
|
@@ -454,15 +455,16 @@ export function _last<T>(array: readonly T[]): T {
|
|
|
454
455
|
/**
|
|
455
456
|
* Returns last item of the array (or undefined if array is empty).
|
|
456
457
|
*/
|
|
457
|
-
export function _lastOrUndefined<T>(array:
|
|
458
|
+
export function _lastOrUndefined<T>(array: ArrayLike<T>): T | undefined {
|
|
458
459
|
return array[array.length - 1]
|
|
459
460
|
}
|
|
460
461
|
|
|
461
462
|
/**
|
|
462
463
|
* Returns the first item of non-empty array.
|
|
463
464
|
* Throws if array is empty.
|
|
465
|
+
* Accepts any array-like value, e.g. a Uint8Array, a NodeList or a string.
|
|
464
466
|
*/
|
|
465
|
-
export function _first<T>(array:
|
|
467
|
+
export function _first<T>(array: ArrayLike<T>): T {
|
|
466
468
|
_assert(array.length, '_first called on empty array')
|
|
467
469
|
return array[0]!
|
|
468
470
|
}
|
|
@@ -470,7 +472,7 @@ export function _first<T>(array: readonly T[]): T {
|
|
|
470
472
|
/**
|
|
471
473
|
* Returns first item of the array (or undefined if array is empty).
|
|
472
474
|
*/
|
|
473
|
-
export function _firstOrUndefined<T>(array:
|
|
475
|
+
export function _firstOrUndefined<T>(array: ArrayLike<T>): T | undefined {
|
|
474
476
|
return array[0]
|
|
475
477
|
}
|
|
476
478
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _assert } from '../error/assert.js'
|
|
1
2
|
import type { IsoDate } from '../types.js'
|
|
2
3
|
import type { LocalDate, LocalDateInput, LocalDateUnit } from './localDate.js'
|
|
3
4
|
import { localDate } from './localDate.js'
|
|
@@ -28,9 +29,7 @@ export class DateInterval {
|
|
|
28
29
|
|
|
29
30
|
const [start, end] = d.split('/') as IsoDate[]
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
throw new Error(`Cannot parse "${d}" into DateInterval`)
|
|
33
|
-
}
|
|
32
|
+
_assert(end && start, `Cannot parse "${d}" into DateInterval`)
|
|
34
33
|
|
|
35
34
|
return new DateInterval(localDate(start), localDate(end))
|
|
36
35
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _assert } from '../error/assert.js'
|
|
1
2
|
import type { UnixTimestamp } from '../types.js'
|
|
2
3
|
import type { LocalTime, LocalTimeInput } from './localTime.js'
|
|
3
4
|
import { localTime } from './localTime.js'
|
|
@@ -45,9 +46,7 @@ export class TimeInterval {
|
|
|
45
46
|
|
|
46
47
|
const [start, end] = d.split('/').map(Number) as UnixTimestamp[]
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
throw new Error(`Cannot parse "${d}" into TimeInterval`)
|
|
50
|
-
}
|
|
49
|
+
_assert(end && start, `Cannot parse "${d}" into TimeInterval`)
|
|
51
50
|
|
|
52
51
|
return new TimeInterval(start, end)
|
|
53
52
|
}
|
package/src/enum.util.ts
CHANGED
package/src/qr/qr.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
// oxlint-disable no-bitwise, prefer-math-trunc -- QR encoding (Galois field, BCH, bit packing) is
|
|
17
17
|
// inherently bitwise; `(1 << 0)` terms mirror the spec's generator polynomials
|
|
18
|
+
// oxlint-disable nc/prefer-assert -- this module has no imports, to stay small when bundled on its own
|
|
18
19
|
|
|
19
20
|
/// <reference lib="dom" preserve="true" />
|
|
20
21
|
|