@mll-lab/js-utils 1.4.1 → 2.3.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
@@ -1,3 +1,7 @@
1
+ export declare type NonEmptyArray<T> = Array<T> & {
2
+ 0: T;
3
+ };
4
+ export declare function isNonEmptyArray<T>(value: Array<T>): value is NonEmptyArray<T>;
1
5
  /**
2
6
  * Return a new array that does not contain the item at the specified index.
3
7
  */
@@ -18,3 +22,4 @@ export declare const EMPTY_ARRAY: never[];
18
22
  * @example const arr = ['x', ...insertIf(foo === 42, 'y', 'z')]
19
23
  */
20
24
  export declare function insertIf<T>(condition: boolean, ...elements: Array<T>): Array<T>;
25
+ export declare function last<T, A extends Array<T>>(array: A): A extends NonEmptyArray<T> ? T : T | undefined;
package/dist/date.d.ts CHANGED
@@ -1,24 +1,25 @@
1
- export declare const GERMAN_DOTLESS_DATE_FORMAT: string;
2
- export declare const GERMAN_DATE_FORMAT: string;
3
- /**
4
- * Reverse order of standard german format to sort correctly.
5
- */
6
- export declare const ISO_GERMAN_DATE_FORMAT: string;
7
- export declare const GERMAN_DATE_TIME_FORMAT: string;
8
- export declare const ISO_DATE_FORMAT: string;
9
- export declare const ISO_DATE_TIME_FORMAT: string;
10
- export declare const SECONDLESS_DATE_TIME_FORMAT: string;
11
- export declare const MINIMAL_VALID_DATE: Date;
1
+ export declare function isToday(date: Date | string | number): boolean;
2
+ export declare function isFuture(date: Date | string | number): boolean;
12
3
  export declare function parseDate(value: string, formatString: string): Date | null;
4
+ export declare function parseGermanDateFlexible(value: string): Date | null;
5
+ export declare const GERMAN_DATE_FORMAT: string;
13
6
  export declare function parseGermanDate(value: string): Date | null;
7
+ export declare function formatGerman(date: Date | string | number): string;
8
+ export declare const ISO_DATE_FORMAT: string;
14
9
  export declare function parseIsoDate(value: string): Date | null;
15
- export declare function parseSecondlessDateTime(value: string): Date | null;
10
+ export declare function formatIsoDate(date: Date | string | number): string;
11
+ export declare const GERMAN_DOTLESS_DATE_FORMAT: string;
16
12
  export declare function parseGermanDotlessDate(value: string): Date | null;
17
- export declare function parseGermanDateFlexible(value: string): Date | null;
18
- export declare function formatGerman(date: Date): string;
19
- export declare function formatIsoGerman(date: Date): string;
20
- export declare function formatGermanDateTime(date: Date): string;
21
- export declare function formatIsoDate(date: number | Date): string;
22
- export declare function formatSecondlessDateTime(dateTime: number | Date): string;
23
- export declare function formatIsoDateTime(dateTime: number | Date): string;
24
- export declare function isToday(date: Date | number): boolean;
13
+ export declare function formatGermanDotlessDate(date: Date | string | number): string;
14
+ export declare const SECONDLESS_DATE_TIME_FORMAT: string;
15
+ export declare function parseSecondlessDateTime(value: string): Date | null;
16
+ export declare function formatSecondlessDateTime(date: Date | string | number): string;
17
+ export declare const GERMAN_DATE_TIME_FORMAT: string;
18
+ export declare function parseGermanDateTime(value: string): Date | null;
19
+ export declare function formatGermanDateTime(date: Date | string | number): string;
20
+ export declare const ISO_DATE_TIME_FORMAT: string;
21
+ export declare function parseIsoDateTime(value: string): Date | null;
22
+ export declare function formatIsoDateTime(date: Date | string | number): string;
23
+ export declare const DOTLESS_DATE_FORMAT: string;
24
+ export declare function parseDotlessDate(value: string): Date | null;
25
+ export declare function formatDotlessDate(date: Date | string | number): string;
@@ -9432,6 +9432,9 @@ if(freeModule){// Export for Node.js.
9432
9432
  freeExports._=_;}else {// Export to the global object.
9433
9433
  root._=_;}}).call(commonjsGlobal);});
9434
9434
 
9435
+ function isNonEmptyArray(value) {
9436
+ return value.length > 0;
9437
+ }
9435
9438
  /**
9436
9439
  * Return a new array that does not contain the item at the specified index.
9437
9440
  */
@@ -9459,6 +9462,10 @@ Object.freeze(EMPTY_ARRAY);
9459
9462
  function insertIf(condition, ...elements) {
9460
9463
  return condition ? elements : [];
9461
9464
  }
9465
+ function last(array) {
9466
+ // @ts-expect-error too magical
9467
+ return array[array.length - 1];
9468
+ }
9462
9469
 
9463
9470
  function toInteger(dirtyNumber) {
9464
9471
  if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
@@ -12339,6 +12346,43 @@ function cleanEscapedString$1(input) {
12339
12346
  return input.match(escapedStringRegExp$1)[1].replace(doubleQuoteRegExp$1, "'");
12340
12347
  }
12341
12348
 
12349
+ /**
12350
+ * @name isAfter
12351
+ * @category Common Helpers
12352
+ * @summary Is the first date after the second one?
12353
+ *
12354
+ * @description
12355
+ * Is the first date after the second one?
12356
+ *
12357
+ *
12358
+ * ### v2.0.0 breaking changes:
12359
+ *
12360
+ * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
12361
+ *
12362
+ * @param {Date|String|Number} date - the date that should be after the other one to return true
12363
+ * @param {Date|String|Number} dateToCompare - the date to compare with
12364
+ * @param {Options} [options] - the object with options. See [Options]{@link https://date-fns.org/docs/Options}
12365
+ * @param {0|1|2} [options.additionalDigits=2] - passed to `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
12366
+ * @returns {Boolean} the first date is after the second date
12367
+ * @throws {TypeError} 2 arguments required
12368
+ * @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2
12369
+ *
12370
+ * @example
12371
+ * // Is 10 July 1989 after 11 February 1987?
12372
+ * var result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
12373
+ * //=> true
12374
+ */
12375
+
12376
+ function isAfter(dirtyDate, dirtyDateToCompare, dirtyOptions) {
12377
+ if (arguments.length < 2) {
12378
+ throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
12379
+ }
12380
+
12381
+ var date = toDate(dirtyDate, dirtyOptions);
12382
+ var dateToCompare = toDate(dirtyDateToCompare, dirtyOptions);
12383
+ return date.getTime() > dateToCompare.getTime();
12384
+ }
12385
+
12342
12386
  // See issue: https://github.com/date-fns/date-fns/issues/376
12343
12387
 
12344
12388
  function setUTCDay(dirtyDate, dirtyDay, dirtyOptions) {
@@ -15004,56 +15048,67 @@ var de = createCommonjsModule(function (module, exports) {
15004
15048
  });
15005
15049
  var de$1 = /*@__PURE__*/getDefaultExportFromCjs(de);
15006
15050
 
15007
- const GERMAN_DOTLESS_DATE_FORMAT = 'ddMMy';
15008
- const GERMAN_DATE_FORMAT = 'dd.MM.y';
15009
- /**
15010
- * Reverse order of standard german format to sort correctly.
15011
- */
15012
- const ISO_GERMAN_DATE_FORMAT = 'y.MM.dd';
15013
- const GERMAN_DATE_TIME_FORMAT = 'dd.MM.y HH:mm';
15014
- const ISO_DATE_FORMAT = 'y-MM-dd';
15015
- const ISO_DATE_TIME_FORMAT = 'y-MM-dd HH:mm:ss';
15016
- const SECONDLESS_DATE_TIME_FORMAT = 'y-MM-dd HH:mm';
15017
- const MINIMAL_VALID_DATE = new Date(1900, 0, 1);
15051
+ function isToday(date) {
15052
+ return differenceInCalendarDays(new Date(), date) === 0;
15053
+ }
15054
+ function isFuture(date) {
15055
+ return isAfter(date, new Date());
15056
+ }
15018
15057
  function parseDate(value, formatString) {
15019
15058
  const parsedDate = parse(value, formatString, new Date());
15020
15059
  return isValid(parsedDate) ? parsedDate : null;
15021
15060
  }
15061
+ function parseGermanDateFlexible(value) {
15062
+ return parseGermanDotlessDate(value) || parseGermanDate(value);
15063
+ }
15064
+ const GERMAN_DATE_FORMAT = 'dd.MM.y';
15022
15065
  function parseGermanDate(value) {
15023
15066
  return parseDate(value, GERMAN_DATE_FORMAT);
15024
15067
  }
15068
+ function formatGerman(date) {
15069
+ return format(date, GERMAN_DATE_FORMAT, { locale: de$1 });
15070
+ }
15071
+ const ISO_DATE_FORMAT = 'y-MM-dd';
15025
15072
  function parseIsoDate(value) {
15026
15073
  return parseDate(value, ISO_DATE_FORMAT);
15027
15074
  }
15028
- function parseSecondlessDateTime(value) {
15029
- return parseDate(value, SECONDLESS_DATE_TIME_FORMAT);
15075
+ function formatIsoDate(date) {
15076
+ return format(date, ISO_DATE_FORMAT, { locale: de$1 });
15030
15077
  }
15078
+ const GERMAN_DOTLESS_DATE_FORMAT = 'ddMMy';
15031
15079
  function parseGermanDotlessDate(value) {
15032
15080
  return parseDate(value, GERMAN_DOTLESS_DATE_FORMAT);
15033
15081
  }
15034
- function parseGermanDateFlexible(value) {
15035
- return parseGermanDotlessDate(value) || parseGermanDate(value);
15082
+ function formatGermanDotlessDate(date) {
15083
+ return format(date, GERMAN_DOTLESS_DATE_FORMAT, { locale: de$1 });
15036
15084
  }
15037
- function formatGerman(date) {
15038
- return format(date, GERMAN_DATE_FORMAT, { locale: de$1 });
15085
+ const SECONDLESS_DATE_TIME_FORMAT = 'y-MM-dd HH:mm';
15086
+ function parseSecondlessDateTime(value) {
15087
+ return parseDate(value, SECONDLESS_DATE_TIME_FORMAT);
15088
+ }
15089
+ function formatSecondlessDateTime(date) {
15090
+ return format(date, SECONDLESS_DATE_TIME_FORMAT, { locale: de$1 });
15039
15091
  }
15040
- function formatIsoGerman(date) {
15041
- return format(date, ISO_GERMAN_DATE_FORMAT, { locale: de$1 });
15092
+ const GERMAN_DATE_TIME_FORMAT = 'dd.MM.y HH:mm';
15093
+ function parseGermanDateTime(value) {
15094
+ return parseDate(value, GERMAN_DATE_TIME_FORMAT);
15042
15095
  }
15043
15096
  function formatGermanDateTime(date) {
15044
15097
  return format(date, GERMAN_DATE_TIME_FORMAT, { locale: de$1 });
15045
15098
  }
15046
- function formatIsoDate(date) {
15047
- return format(date, ISO_DATE_FORMAT, { locale: de$1 });
15099
+ const ISO_DATE_TIME_FORMAT = 'y-MM-dd HH:mm:ss';
15100
+ function parseIsoDateTime(value) {
15101
+ return parseDate(value, ISO_DATE_TIME_FORMAT);
15048
15102
  }
15049
- function formatSecondlessDateTime(dateTime) {
15050
- return format(dateTime, SECONDLESS_DATE_TIME_FORMAT, { locale: de$1 });
15103
+ function formatIsoDateTime(date) {
15104
+ return format(date, ISO_DATE_TIME_FORMAT, { locale: de$1 });
15051
15105
  }
15052
- function formatIsoDateTime(dateTime) {
15053
- return format(dateTime, ISO_DATE_TIME_FORMAT, { locale: de$1 });
15106
+ const DOTLESS_DATE_FORMAT = 'yMMdd';
15107
+ function parseDotlessDate(value) {
15108
+ return parseDate(value, DOTLESS_DATE_FORMAT);
15054
15109
  }
15055
- function isToday(date) {
15056
- return differenceInCalendarDays(new Date(), date) === 0;
15110
+ function formatDotlessDate(date) {
15111
+ return format(date, DOTLESS_DATE_FORMAT, { locale: de$1 });
15057
15112
  }
15058
15113
 
15059
15114
  function pluralize(amount, singular, plural) {
@@ -15106,6 +15161,7 @@ function round(number, decimalPlaces) {
15106
15161
  return Math.round(number * factorOfTen) / factorOfTen;
15107
15162
  }
15108
15163
 
15164
+ exports.DOTLESS_DATE_FORMAT = DOTLESS_DATE_FORMAT;
15109
15165
  exports.EMAIL_REGEX = EMAIL_REGEX;
15110
15166
  exports.EMPTY_ARRAY = EMPTY_ARRAY;
15111
15167
  exports.GERMAN_DATE_FORMAT = GERMAN_DATE_FORMAT;
@@ -15113,32 +15169,37 @@ exports.GERMAN_DATE_TIME_FORMAT = GERMAN_DATE_TIME_FORMAT;
15113
15169
  exports.GERMAN_DOTLESS_DATE_FORMAT = GERMAN_DOTLESS_DATE_FORMAT;
15114
15170
  exports.ISO_DATE_FORMAT = ISO_DATE_FORMAT;
15115
15171
  exports.ISO_DATE_TIME_FORMAT = ISO_DATE_TIME_FORMAT;
15116
- exports.ISO_GERMAN_DATE_FORMAT = ISO_GERMAN_DATE_FORMAT;
15117
- exports.MINIMAL_VALID_DATE = MINIMAL_VALID_DATE;
15118
15172
  exports.SECONDLESS_DATE_TIME_FORMAT = SECONDLESS_DATE_TIME_FORMAT;
15119
15173
  exports.containSameValues = containSameValues;
15174
+ exports.formatDotlessDate = formatDotlessDate;
15120
15175
  exports.formatGerman = formatGerman;
15121
15176
  exports.formatGermanDateTime = formatGermanDateTime;
15177
+ exports.formatGermanDotlessDate = formatGermanDotlessDate;
15122
15178
  exports.formatIsoDate = formatIsoDate;
15123
15179
  exports.formatIsoDateTime = formatIsoDateTime;
15124
- exports.formatIsoGerman = formatIsoGerman;
15125
15180
  exports.formatSecondlessDateTime = formatSecondlessDateTime;
15126
15181
  exports.insertIf = insertIf;
15127
15182
  exports.isAlphanumeric = isAlphanumeric;
15128
15183
  exports.isBSNR = isBSNR;
15129
15184
  exports.isEmail = isEmail;
15185
+ exports.isFuture = isFuture;
15130
15186
  exports.isLabId = isLabId;
15187
+ exports.isNonEmptyArray = isNonEmptyArray;
15131
15188
  exports.isOnlyDigits = isOnlyDigits;
15132
15189
  exports.isRackBarcode = isRackBarcode;
15133
15190
  exports.isString = isString;
15134
15191
  exports.isToday = isToday;
15135
15192
  exports.isURL = isURL;
15136
15193
  exports.isWord = isWord;
15194
+ exports.last = last;
15137
15195
  exports.parseDate = parseDate;
15196
+ exports.parseDotlessDate = parseDotlessDate;
15138
15197
  exports.parseGermanDate = parseGermanDate;
15139
15198
  exports.parseGermanDateFlexible = parseGermanDateFlexible;
15199
+ exports.parseGermanDateTime = parseGermanDateTime;
15140
15200
  exports.parseGermanDotlessDate = parseGermanDotlessDate;
15141
15201
  exports.parseIsoDate = parseIsoDate;
15202
+ exports.parseIsoDateTime = parseIsoDateTime;
15142
15203
  exports.parseSecondlessDateTime = parseSecondlessDateTime;
15143
15204
  exports.pluralize = pluralize;
15144
15205
  exports.round = round;