@mll-lab/js-utils 2.1.0 → 2.5.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.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from './array';
2
2
  export * from './date';
3
+ export * from './error';
3
4
  export * from './pluralize';
4
5
  export * from './predicates';
5
6
  export * from './round';
7
+ export * from './string';
package/dist/index.js CHANGED
@@ -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) {
@@ -15007,6 +15051,9 @@ var de$1 = /*@__PURE__*/getDefaultExportFromCjs(de);
15007
15051
  function isToday(date) {
15008
15052
  return differenceInCalendarDays(new Date(), date) === 0;
15009
15053
  }
15054
+ function isFuture(date) {
15055
+ return isAfter(date, new Date());
15056
+ }
15010
15057
  function parseDate(value, formatString) {
15011
15058
  const parsedDate = parse(value, formatString, new Date());
15012
15059
  return isValid(parsedDate) ? parsedDate : null;
@@ -15064,6 +15111,23 @@ function formatDotlessDate(date) {
15064
15111
  return format(date, DOTLESS_DATE_FORMAT, { locale: de$1 });
15065
15112
  }
15066
15113
 
15114
+ /**
15115
+ * Extract a message from a caught error.
15116
+ *
15117
+ * Since you can throw anything in JavaScript,
15118
+ * the given error could be of any type.
15119
+ */
15120
+ function errorMessage(error) {
15121
+ const message = hasMessage(error) ? error.message : error;
15122
+ if (message === undefined) {
15123
+ return 'undefined';
15124
+ }
15125
+ return typeof message === 'string' ? message : JSON.stringify(error);
15126
+ }
15127
+ function hasMessage(error) {
15128
+ return typeof error === 'object' && error !== null && 'message' in error;
15129
+ }
15130
+
15067
15131
  function pluralize(amount, singular, plural) {
15068
15132
  if (amount === 1) {
15069
15133
  return singular;
@@ -15114,6 +15178,16 @@ function round(number, decimalPlaces) {
15114
15178
  return Math.round(number * factorOfTen) / factorOfTen;
15115
15179
  }
15116
15180
 
15181
+ function includesIgnoreCase(needle, haystack) {
15182
+ if (haystack instanceof Array) {
15183
+ return haystack.some((hay) => includesIgnoreCase(needle, hay));
15184
+ }
15185
+ return haystack.toLowerCase().includes(needle.toLowerCase());
15186
+ }
15187
+ function firstLine(multilineText) {
15188
+ return multilineText.split('\n', 1)[0];
15189
+ }
15190
+
15117
15191
  exports.DOTLESS_DATE_FORMAT = DOTLESS_DATE_FORMAT;
15118
15192
  exports.EMAIL_REGEX = EMAIL_REGEX;
15119
15193
  exports.EMPTY_ARRAY = EMPTY_ARRAY;
@@ -15124,6 +15198,8 @@ exports.ISO_DATE_FORMAT = ISO_DATE_FORMAT;
15124
15198
  exports.ISO_DATE_TIME_FORMAT = ISO_DATE_TIME_FORMAT;
15125
15199
  exports.SECONDLESS_DATE_TIME_FORMAT = SECONDLESS_DATE_TIME_FORMAT;
15126
15200
  exports.containSameValues = containSameValues;
15201
+ exports.errorMessage = errorMessage;
15202
+ exports.firstLine = firstLine;
15127
15203
  exports.formatDotlessDate = formatDotlessDate;
15128
15204
  exports.formatGerman = formatGerman;
15129
15205
  exports.formatGermanDateTime = formatGermanDateTime;
@@ -15131,17 +15207,21 @@ exports.formatGermanDotlessDate = formatGermanDotlessDate;
15131
15207
  exports.formatIsoDate = formatIsoDate;
15132
15208
  exports.formatIsoDateTime = formatIsoDateTime;
15133
15209
  exports.formatSecondlessDateTime = formatSecondlessDateTime;
15210
+ exports.includesIgnoreCase = includesIgnoreCase;
15134
15211
  exports.insertIf = insertIf;
15135
15212
  exports.isAlphanumeric = isAlphanumeric;
15136
15213
  exports.isBSNR = isBSNR;
15137
15214
  exports.isEmail = isEmail;
15215
+ exports.isFuture = isFuture;
15138
15216
  exports.isLabId = isLabId;
15217
+ exports.isNonEmptyArray = isNonEmptyArray;
15139
15218
  exports.isOnlyDigits = isOnlyDigits;
15140
15219
  exports.isRackBarcode = isRackBarcode;
15141
15220
  exports.isString = isString;
15142
15221
  exports.isToday = isToday;
15143
15222
  exports.isURL = isURL;
15144
15223
  exports.isWord = isWord;
15224
+ exports.last = last;
15145
15225
  exports.parseDate = parseDate;
15146
15226
  exports.parseDotlessDate = parseDotlessDate;
15147
15227
  exports.parseGermanDate = parseGermanDate;