@mll-lab/js-utils 2.18.0 → 2.20.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 +9 -0
- package/dist/index.common.js +19 -0
- package/dist/index.common.js.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/array.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { Maybe } from './types';
|
|
1
2
|
export declare type NonEmptyArray<T> = Array<T> & {
|
|
2
3
|
0: T;
|
|
3
4
|
};
|
|
4
5
|
export declare function isNonEmptyArray<T>(value: Array<T>): value is NonEmptyArray<T>;
|
|
6
|
+
export declare function isEmptyArray(value: unknown): value is [];
|
|
5
7
|
/**
|
|
6
8
|
* Return a new array that does not contain the item at the specified index.
|
|
7
9
|
*/
|
|
@@ -40,3 +42,10 @@ export declare function toggleElement<T>(array: Array<T>, element: T): Array<T>;
|
|
|
40
42
|
* returns sorted array [Jan, Mar, Dec]
|
|
41
43
|
*/
|
|
42
44
|
export declare function sortByArray<T extends string | number>(subject: Array<T>, recipe: Array<T>): Array<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Takes a function that maps the values to sort and returns a compare function
|
|
47
|
+
* using `String.prototype.localeCompare`, usable in `Array.sort` or similar APIs.
|
|
48
|
+
*
|
|
49
|
+
* null, undefined and the empty string are not distinguished and first in sort order.
|
|
50
|
+
*/
|
|
51
|
+
export declare function makeStringCompareFn<TSortable>(map: (sortable: TSortable) => Maybe<string>): (a: TSortable, b: TSortable) => number;
|
package/dist/index.common.js
CHANGED
|
@@ -9435,6 +9435,9 @@ root._=_;}}).call(commonjsGlobal);});
|
|
|
9435
9435
|
function isNonEmptyArray(value) {
|
|
9436
9436
|
return value.length > 0;
|
|
9437
9437
|
}
|
|
9438
|
+
function isEmptyArray(value) {
|
|
9439
|
+
return value instanceof Array && value.length === 0;
|
|
9440
|
+
}
|
|
9438
9441
|
/**
|
|
9439
9442
|
* Return a new array that does not contain the item at the specified index.
|
|
9440
9443
|
*/
|
|
@@ -9491,6 +9494,20 @@ function sortByArray(subject, recipe) {
|
|
|
9491
9494
|
}
|
|
9492
9495
|
return lodash.sortBy(subject, (value) => recipe.indexOf(value));
|
|
9493
9496
|
}
|
|
9497
|
+
/**
|
|
9498
|
+
* Takes a function that maps the values to sort and returns a compare function
|
|
9499
|
+
* using `String.prototype.localeCompare`, usable in `Array.sort` or similar APIs.
|
|
9500
|
+
*
|
|
9501
|
+
* null, undefined and the empty string are not distinguished and first in sort order.
|
|
9502
|
+
*/
|
|
9503
|
+
function makeStringCompareFn(map) {
|
|
9504
|
+
return (a, b) => {
|
|
9505
|
+
var _a, _b;
|
|
9506
|
+
const mappedA = (_a = map(a)) !== null && _a !== void 0 ? _a : '';
|
|
9507
|
+
const mappedB = (_b = map(b)) !== null && _b !== void 0 ? _b : '';
|
|
9508
|
+
return mappedA.localeCompare(mappedB);
|
|
9509
|
+
};
|
|
9510
|
+
}
|
|
9494
9511
|
|
|
9495
9512
|
function toInteger(dirtyNumber) {
|
|
9496
9513
|
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
|
@@ -15470,6 +15487,7 @@ exports.insertIf = insertIf;
|
|
|
15470
15487
|
exports.isAlphanumeric = isAlphanumeric;
|
|
15471
15488
|
exports.isBSNR = isBSNR;
|
|
15472
15489
|
exports.isEmail = isEmail;
|
|
15490
|
+
exports.isEmptyArray = isEmptyArray;
|
|
15473
15491
|
exports.isFuture = isFuture;
|
|
15474
15492
|
exports.isLabId = isLabId;
|
|
15475
15493
|
exports.isMobileDevice = isMobileDevice;
|
|
@@ -15484,6 +15502,7 @@ exports.isURL = isURL;
|
|
|
15484
15502
|
exports.isWord = isWord;
|
|
15485
15503
|
exports.joinNonEmpty = joinNonEmpty;
|
|
15486
15504
|
exports.last = last;
|
|
15505
|
+
exports.makeStringCompareFn = makeStringCompareFn;
|
|
15487
15506
|
exports.mapSequentially = mapSequentially;
|
|
15488
15507
|
exports.parseDate = parseDate;
|
|
15489
15508
|
exports.parseDotlessDate = parseDotlessDate;
|