@naturalcycles/js-lib 15.67.0 → 15.68.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.
|
@@ -197,6 +197,8 @@ export declare function _mapToObject<T, V>(array: Iterable<T>, mapper: (item: T)
|
|
|
197
197
|
* Based on: https://stackoverflow.com/a/12646864/4919972
|
|
198
198
|
*/
|
|
199
199
|
export declare function _shuffle<T>(array: T[], opt?: MutateOptions): T[];
|
|
200
|
+
export declare function _firstLast<T>(array: readonly T[]): [first: T, last: T];
|
|
201
|
+
export declare function _firstLastOrUndefined<T>(array: readonly T[]): [first: T, last: T] | undefined;
|
|
200
202
|
/**
|
|
201
203
|
* Returns last item of non-empty array.
|
|
202
204
|
* Throws if array is empty.
|
package/dist/array/array.util.js
CHANGED
|
@@ -363,6 +363,16 @@ export function _shuffle(array, opt = {}) {
|
|
|
363
363
|
}
|
|
364
364
|
return a;
|
|
365
365
|
}
|
|
366
|
+
export function _firstLast(array) {
|
|
367
|
+
if (!array.length)
|
|
368
|
+
throw new Error('_firstLast called on empty array');
|
|
369
|
+
return [array[0], array[array.length - 1]];
|
|
370
|
+
}
|
|
371
|
+
export function _firstLastOrUndefined(array) {
|
|
372
|
+
if (!array.length)
|
|
373
|
+
return;
|
|
374
|
+
return [array[0], array[array.length - 1]];
|
|
375
|
+
}
|
|
366
376
|
/**
|
|
367
377
|
* Returns last item of non-empty array.
|
|
368
378
|
* Throws if array is empty.
|
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.68.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2"
|
|
7
7
|
},
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@typescript/native-preview": "7.0.0-dev.20260201.1",
|
|
25
25
|
"crypto-js": "^4",
|
|
26
26
|
"dayjs": "^1",
|
|
27
|
-
"@naturalcycles/dev-lib": "
|
|
27
|
+
"@naturalcycles/dev-lib": "18.4.2"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
30
|
".": "./dist/index.js",
|
package/src/array/array.util.ts
CHANGED
|
@@ -426,6 +426,16 @@ export function _shuffle<T>(array: T[], opt: MutateOptions = {}): T[] {
|
|
|
426
426
|
return a
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
+
export function _firstLast<T>(array: readonly T[]): [first: T, last: T] {
|
|
430
|
+
if (!array.length) throw new Error('_firstLast called on empty array')
|
|
431
|
+
return [array[0]!, array[array.length - 1]!]
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export function _firstLastOrUndefined<T>(array: readonly T[]): [first: T, last: T] | undefined {
|
|
435
|
+
if (!array.length) return
|
|
436
|
+
return [array[0]!, array[array.length - 1]!]
|
|
437
|
+
}
|
|
438
|
+
|
|
429
439
|
/**
|
|
430
440
|
* Returns last item of non-empty array.
|
|
431
441
|
* Throws if array is empty.
|