@mll-lab/js-utils 2.38.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/array.d.ts CHANGED
@@ -61,6 +61,13 @@ export declare function makeNumberCompareFn<TSortable>(map: (sortable: TSortable
61
61
  * Usable in `Array.toSorted` or similar APIs.
62
62
  */
63
63
  export declare function makeBooleanCompareFn<TSortable>(map: (sortable: TSortable) => boolean): (a: TSortable, b: TSortable) => number;
64
+ /**
65
+ * Takes a function that maps the values to sort to Dates and returns a compare function
66
+ * using their timestamps, usable in `Array.toSorted` or similar APIs.
67
+ *
68
+ * null and undefined are coalesced to 0 and thus not distinguished and first in sort order.
69
+ */
70
+ export declare function makeDateCompareFn<TSortable>(map: (sortable: TSortable) => Maybe<Date>): (a: TSortable, b: TSortable) => number;
64
71
  /**
65
72
  * Returns a compare function for values that are string, null or undefined,
66
73
  * using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
@@ -9594,6 +9594,15 @@ 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 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
+ }
9597
9606
  /**
9598
9607
  * Returns a compare function for values that are string, null or undefined,
9599
9608
  * using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
@@ -16342,6 +16351,7 @@ exports.joinNonEmpty = joinNonEmpty;
16342
16351
  exports.last = last;
16343
16352
  exports.localeCompareStrings = localeCompareStrings;
16344
16353
  exports.makeBooleanCompareFn = makeBooleanCompareFn;
16354
+ exports.makeDateCompareFn = makeDateCompareFn;
16345
16355
  exports.makeNumberCompareFn = makeNumberCompareFn;
16346
16356
  exports.makeStringCompareFn = makeStringCompareFn;
16347
16357
  exports.mapSequentially = mapSequentially;