@mll-lab/js-utils 2.2.0 → 2.3.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.d.ts +5 -0
- package/dist/index.common.js +9 -0
- package/dist/index.common.js.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/array.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export declare type NonEmptyArray<T> = Array<T> & {
|
|
2
|
+
0: T;
|
|
3
|
+
};
|
|
4
|
+
export declare function isNonEmptyArray<T>(value: Array<T>): value is NonEmptyArray<T>;
|
|
1
5
|
/**
|
|
2
6
|
* Return a new array that does not contain the item at the specified index.
|
|
3
7
|
*/
|
|
@@ -18,3 +22,4 @@ export declare const EMPTY_ARRAY: never[];
|
|
|
18
22
|
* @example const arr = ['x', ...insertIf(foo === 42, 'y', 'z')]
|
|
19
23
|
*/
|
|
20
24
|
export declare function insertIf<T>(condition: boolean, ...elements: Array<T>): Array<T>;
|
|
25
|
+
export declare function last<T, A extends Array<T>>(array: A): A extends NonEmptyArray<T> ? T : T | undefined;
|
package/dist/index.common.js
CHANGED
|
@@ -9432,6 +9432,9 @@ if(freeModule){// Export for Node.js.
|
|
|
9432
9432
|
freeExports._=_;}else {// Export to the global object.
|
|
9433
9433
|
root._=_;}}).call(commonjsGlobal);});
|
|
9434
9434
|
|
|
9435
|
+
function isNonEmptyArray(value) {
|
|
9436
|
+
return value.length > 0;
|
|
9437
|
+
}
|
|
9435
9438
|
/**
|
|
9436
9439
|
* Return a new array that does not contain the item at the specified index.
|
|
9437
9440
|
*/
|
|
@@ -9459,6 +9462,10 @@ Object.freeze(EMPTY_ARRAY);
|
|
|
9459
9462
|
function insertIf(condition, ...elements) {
|
|
9460
9463
|
return condition ? elements : [];
|
|
9461
9464
|
}
|
|
9465
|
+
function last(array) {
|
|
9466
|
+
// @ts-expect-error too magical
|
|
9467
|
+
return array[array.length - 1];
|
|
9468
|
+
}
|
|
9462
9469
|
|
|
9463
9470
|
function toInteger(dirtyNumber) {
|
|
9464
9471
|
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
|
@@ -15177,12 +15184,14 @@ exports.isBSNR = isBSNR;
|
|
|
15177
15184
|
exports.isEmail = isEmail;
|
|
15178
15185
|
exports.isFuture = isFuture;
|
|
15179
15186
|
exports.isLabId = isLabId;
|
|
15187
|
+
exports.isNonEmptyArray = isNonEmptyArray;
|
|
15180
15188
|
exports.isOnlyDigits = isOnlyDigits;
|
|
15181
15189
|
exports.isRackBarcode = isRackBarcode;
|
|
15182
15190
|
exports.isString = isString;
|
|
15183
15191
|
exports.isToday = isToday;
|
|
15184
15192
|
exports.isURL = isURL;
|
|
15185
15193
|
exports.isWord = isWord;
|
|
15194
|
+
exports.last = last;
|
|
15186
15195
|
exports.parseDate = parseDate;
|
|
15187
15196
|
exports.parseDotlessDate = parseDotlessDate;
|
|
15188
15197
|
exports.parseGermanDate = parseGermanDate;
|