@mll-lab/js-utils 2.37.0 → 2.39.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/index.js CHANGED
@@ -9583,6 +9583,26 @@ function makeNumberCompareFn(map, fallbackValue = 0) {
9583
9583
  return mappedA - mappedB;
9584
9584
  };
9585
9585
  }
9586
+ /**
9587
+ * Takes a function that maps the values to sort to booleans and returns a compare function that puts `false` before `true`.
9588
+ * Usable in `Array.toSorted` or similar APIs.
9589
+ */
9590
+ function makeBooleanCompareFn(map) {
9591
+ return (a, b) => {
9592
+ const mappedA = map(a);
9593
+ const mappedB = map(b);
9594
+ return Number(mappedA) - Number(mappedB);
9595
+ };
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 0 and thus not distinguished and first in sort order.
9602
+ */
9603
+ function makeDateCompareFn(map) {
9604
+ return makeNumberCompareFn((sortable) => { var _a; return (_a = map(sortable)) === null || _a === void 0 ? void 0 : _a.getTime(); });
9605
+ }
9586
9606
  /**
9587
9607
  * Returns a compare function for values that are string, null or undefined,
9588
9608
  * using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
@@ -16330,6 +16350,8 @@ exports.isZeroish = isZeroish;
16330
16350
  exports.joinNonEmpty = joinNonEmpty;
16331
16351
  exports.last = last;
16332
16352
  exports.localeCompareStrings = localeCompareStrings;
16353
+ exports.makeBooleanCompareFn = makeBooleanCompareFn;
16354
+ exports.makeDateCompareFn = makeDateCompareFn;
16333
16355
  exports.makeNumberCompareFn = makeNumberCompareFn;
16334
16356
  exports.makeStringCompareFn = makeStringCompareFn;
16335
16357
  exports.mapSequentially = mapSequentially;