@mll-lab/js-utils 2.38.0 → 2.40.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 +7 -0
- package/dist/index.common.js +13 -0
- package/dist/index.common.js.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9594,6 +9594,18 @@ function makeBooleanCompareFn(map) {
|
|
|
9594
9594
|
return Number(mappedA) - Number(mappedB);
|
|
9595
9595
|
};
|
|
9596
9596
|
}
|
|
9597
|
+
/**
|
|
9598
|
+
* Takes a function that maps the values to sort to Dates and returns a compare function
|
|
9599
|
+
* using their timestamps, usable in `Array.toSorted` or similar APIs.
|
|
9600
|
+
*
|
|
9601
|
+
* null and undefined are coalesced to the oldest possible date and thus not distinguished and first in sort order.
|
|
9602
|
+
*/
|
|
9603
|
+
function makeDateCompareFn(map,
|
|
9604
|
+
// See https://stackoverflow.com/a/11526569 for an explanation of this value.
|
|
9605
|
+
fallbackValue = new Date(-8640000000000000)) {
|
|
9606
|
+
const fallbackTime = fallbackValue.getTime();
|
|
9607
|
+
return makeNumberCompareFn((sortable) => { var _a, _b; return (_b = (_a = map(sortable)) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : fallbackTime; });
|
|
9608
|
+
}
|
|
9597
9609
|
/**
|
|
9598
9610
|
* Returns a compare function for values that are string, null or undefined,
|
|
9599
9611
|
* using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
|
|
@@ -16342,6 +16354,7 @@ exports.joinNonEmpty = joinNonEmpty;
|
|
|
16342
16354
|
exports.last = last;
|
|
16343
16355
|
exports.localeCompareStrings = localeCompareStrings;
|
|
16344
16356
|
exports.makeBooleanCompareFn = makeBooleanCompareFn;
|
|
16357
|
+
exports.makeDateCompareFn = makeDateCompareFn;
|
|
16345
16358
|
exports.makeNumberCompareFn = makeNumberCompareFn;
|
|
16346
16359
|
exports.makeStringCompareFn = makeStringCompareFn;
|
|
16347
16360
|
exports.mapSequentially = mapSequentially;
|