@mll-lab/js-utils 2.33.0 → 2.34.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 +8 -1
- package/dist/index.common.js +16 -1
- package/dist/index.common.js.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9505,7 +9505,7 @@ function sortByArray(subject, recipe) {
|
|
|
9505
9505
|
return lodash.sortBy(subject, (value) => recipe.indexOf(value));
|
|
9506
9506
|
}
|
|
9507
9507
|
/**
|
|
9508
|
-
* Takes a function that maps the values to sort and returns a compare function
|
|
9508
|
+
* Takes a function that maps the values to sort to strings and returns a compare function
|
|
9509
9509
|
* using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
|
|
9510
9510
|
*
|
|
9511
9511
|
* null, undefined and the empty string are not distinguished and first in sort order.
|
|
@@ -9518,6 +9518,20 @@ function makeStringCompareFn(map) {
|
|
|
9518
9518
|
return mappedA.localeCompare(mappedB);
|
|
9519
9519
|
};
|
|
9520
9520
|
}
|
|
9521
|
+
/**
|
|
9522
|
+
* Takes a function that maps the values to sort to numbers and returns a compare function
|
|
9523
|
+
* using subtraction, usable in `Array.toSorted` or similar APIs.
|
|
9524
|
+
*
|
|
9525
|
+
* null and undefined are coalesced to `fallbackValue`, by default 0, and thus not distinguished and first in sort order.
|
|
9526
|
+
*/
|
|
9527
|
+
function makeNumberCompareFn(map, fallbackValue = 0) {
|
|
9528
|
+
return (a, b) => {
|
|
9529
|
+
var _a, _b;
|
|
9530
|
+
const mappedA = (_a = map(a)) !== null && _a !== void 0 ? _a : fallbackValue;
|
|
9531
|
+
const mappedB = (_b = map(b)) !== null && _b !== void 0 ? _b : fallbackValue;
|
|
9532
|
+
return mappedA - mappedB;
|
|
9533
|
+
};
|
|
9534
|
+
}
|
|
9521
9535
|
/**
|
|
9522
9536
|
* Returns a compare function for values that are string, null or undefined,
|
|
9523
9537
|
* using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
|
|
@@ -16223,6 +16237,7 @@ exports.isZeroish = isZeroish;
|
|
|
16223
16237
|
exports.joinNonEmpty = joinNonEmpty;
|
|
16224
16238
|
exports.last = last;
|
|
16225
16239
|
exports.localeCompareStrings = localeCompareStrings;
|
|
16240
|
+
exports.makeNumberCompareFn = makeNumberCompareFn;
|
|
16226
16241
|
exports.makeStringCompareFn = makeStringCompareFn;
|
|
16227
16242
|
exports.mapSequentially = mapSequentially;
|
|
16228
16243
|
exports.parseDate = parseDate;
|