@mll-lab/js-utils 1.3.3 → 2.1.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
@@ -2,3 +2,4 @@ export * from './array';
2
2
  export * from './date';
3
3
  export * from './pluralize';
4
4
  export * from './predicates';
5
+ export * from './round';
package/dist/index.js CHANGED
@@ -15004,56 +15004,64 @@ var de = createCommonjsModule(function (module, exports) {
15004
15004
  });
15005
15005
  var de$1 = /*@__PURE__*/getDefaultExportFromCjs(de);
15006
15006
 
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);
15007
+ function isToday(date) {
15008
+ return differenceInCalendarDays(new Date(), date) === 0;
15009
+ }
15018
15010
  function parseDate(value, formatString) {
15019
15011
  const parsedDate = parse(value, formatString, new Date());
15020
15012
  return isValid(parsedDate) ? parsedDate : null;
15021
15013
  }
15014
+ function parseGermanDateFlexible(value) {
15015
+ return parseGermanDotlessDate(value) || parseGermanDate(value);
15016
+ }
15017
+ const GERMAN_DATE_FORMAT = 'dd.MM.y';
15022
15018
  function parseGermanDate(value) {
15023
15019
  return parseDate(value, GERMAN_DATE_FORMAT);
15024
15020
  }
15021
+ function formatGerman(date) {
15022
+ return format(date, GERMAN_DATE_FORMAT, { locale: de$1 });
15023
+ }
15024
+ const ISO_DATE_FORMAT = 'y-MM-dd';
15025
15025
  function parseIsoDate(value) {
15026
15026
  return parseDate(value, ISO_DATE_FORMAT);
15027
15027
  }
15028
- function parseSecondlessDateTime(value) {
15029
- return parseDate(value, SECONDLESS_DATE_TIME_FORMAT);
15028
+ function formatIsoDate(date) {
15029
+ return format(date, ISO_DATE_FORMAT, { locale: de$1 });
15030
15030
  }
15031
+ const GERMAN_DOTLESS_DATE_FORMAT = 'ddMMy';
15031
15032
  function parseGermanDotlessDate(value) {
15032
15033
  return parseDate(value, GERMAN_DOTLESS_DATE_FORMAT);
15033
15034
  }
15034
- function parseGermanDateFlexible(value) {
15035
- return parseGermanDotlessDate(value) || parseGermanDate(value);
15035
+ function formatGermanDotlessDate(date) {
15036
+ return format(date, GERMAN_DOTLESS_DATE_FORMAT, { locale: de$1 });
15036
15037
  }
15037
- function formatGerman(date) {
15038
- return format(date, GERMAN_DATE_FORMAT, { locale: de$1 });
15038
+ const SECONDLESS_DATE_TIME_FORMAT = 'y-MM-dd HH:mm';
15039
+ function parseSecondlessDateTime(value) {
15040
+ return parseDate(value, SECONDLESS_DATE_TIME_FORMAT);
15039
15041
  }
15040
- function formatIsoGerman(date) {
15041
- return format(date, ISO_GERMAN_DATE_FORMAT, { locale: de$1 });
15042
+ function formatSecondlessDateTime(date) {
15043
+ return format(date, SECONDLESS_DATE_TIME_FORMAT, { locale: de$1 });
15044
+ }
15045
+ const GERMAN_DATE_TIME_FORMAT = 'dd.MM.y HH:mm';
15046
+ function parseGermanDateTime(value) {
15047
+ return parseDate(value, GERMAN_DATE_TIME_FORMAT);
15042
15048
  }
15043
15049
  function formatGermanDateTime(date) {
15044
15050
  return format(date, GERMAN_DATE_TIME_FORMAT, { locale: de$1 });
15045
15051
  }
15046
- function formatIsoDate(date) {
15047
- return format(date, ISO_DATE_FORMAT, { locale: de$1 });
15052
+ const ISO_DATE_TIME_FORMAT = 'y-MM-dd HH:mm:ss';
15053
+ function parseIsoDateTime(value) {
15054
+ return parseDate(value, ISO_DATE_TIME_FORMAT);
15048
15055
  }
15049
- function formatSecondlessDateTime(dateTime) {
15050
- return format(dateTime, SECONDLESS_DATE_TIME_FORMAT, { locale: de$1 });
15056
+ function formatIsoDateTime(date) {
15057
+ return format(date, ISO_DATE_TIME_FORMAT, { locale: de$1 });
15051
15058
  }
15052
- function formatIsoDateTime(dateTime) {
15053
- return format(dateTime, ISO_DATE_TIME_FORMAT, { locale: de$1 });
15059
+ const DOTLESS_DATE_FORMAT = 'yMMdd';
15060
+ function parseDotlessDate(value) {
15061
+ return parseDate(value, DOTLESS_DATE_FORMAT);
15054
15062
  }
15055
- function isToday(date) {
15056
- return differenceInCalendarDays(new Date(), date) === 0;
15063
+ function formatDotlessDate(date) {
15064
+ return format(date, DOTLESS_DATE_FORMAT, { locale: de$1 });
15057
15065
  }
15058
15066
 
15059
15067
  function pluralize(amount, singular, plural) {
@@ -15096,6 +15104,17 @@ const isWord = (value) => isString(value) && /^[\w-]+$/.test(value);
15096
15104
  const isLabId = (value) => isString(value) && /^\d{2}-\d{6}$/.test(value);
15097
15105
  const isRackBarcode = (value) => isString(value) && /^[A-Z]{2}\d{8}$/.test(value);
15098
15106
 
15107
+ /**
15108
+ * Round a number to a given number of decimal places.
15109
+ *
15110
+ * https://gist.github.com/djD-REK/2e347f5532bb22310daf450f03ec6ad8
15111
+ */
15112
+ function round(number, decimalPlaces) {
15113
+ const factorOfTen = Math.pow(10, decimalPlaces);
15114
+ return Math.round(number * factorOfTen) / factorOfTen;
15115
+ }
15116
+
15117
+ exports.DOTLESS_DATE_FORMAT = DOTLESS_DATE_FORMAT;
15099
15118
  exports.EMAIL_REGEX = EMAIL_REGEX;
15100
15119
  exports.EMPTY_ARRAY = EMPTY_ARRAY;
15101
15120
  exports.GERMAN_DATE_FORMAT = GERMAN_DATE_FORMAT;
@@ -15103,15 +15122,14 @@ exports.GERMAN_DATE_TIME_FORMAT = GERMAN_DATE_TIME_FORMAT;
15103
15122
  exports.GERMAN_DOTLESS_DATE_FORMAT = GERMAN_DOTLESS_DATE_FORMAT;
15104
15123
  exports.ISO_DATE_FORMAT = ISO_DATE_FORMAT;
15105
15124
  exports.ISO_DATE_TIME_FORMAT = ISO_DATE_TIME_FORMAT;
15106
- exports.ISO_GERMAN_DATE_FORMAT = ISO_GERMAN_DATE_FORMAT;
15107
- exports.MINIMAL_VALID_DATE = MINIMAL_VALID_DATE;
15108
15125
  exports.SECONDLESS_DATE_TIME_FORMAT = SECONDLESS_DATE_TIME_FORMAT;
15109
15126
  exports.containSameValues = containSameValues;
15127
+ exports.formatDotlessDate = formatDotlessDate;
15110
15128
  exports.formatGerman = formatGerman;
15111
15129
  exports.formatGermanDateTime = formatGermanDateTime;
15130
+ exports.formatGermanDotlessDate = formatGermanDotlessDate;
15112
15131
  exports.formatIsoDate = formatIsoDate;
15113
15132
  exports.formatIsoDateTime = formatIsoDateTime;
15114
- exports.formatIsoGerman = formatIsoGerman;
15115
15133
  exports.formatSecondlessDateTime = formatSecondlessDateTime;
15116
15134
  exports.insertIf = insertIf;
15117
15135
  exports.isAlphanumeric = isAlphanumeric;
@@ -15125,11 +15143,15 @@ exports.isToday = isToday;
15125
15143
  exports.isURL = isURL;
15126
15144
  exports.isWord = isWord;
15127
15145
  exports.parseDate = parseDate;
15146
+ exports.parseDotlessDate = parseDotlessDate;
15128
15147
  exports.parseGermanDate = parseGermanDate;
15129
15148
  exports.parseGermanDateFlexible = parseGermanDateFlexible;
15149
+ exports.parseGermanDateTime = parseGermanDateTime;
15130
15150
  exports.parseGermanDotlessDate = parseGermanDotlessDate;
15131
15151
  exports.parseIsoDate = parseIsoDate;
15152
+ exports.parseIsoDateTime = parseIsoDateTime;
15132
15153
  exports.parseSecondlessDateTime = parseSecondlessDateTime;
15133
15154
  exports.pluralize = pluralize;
15155
+ exports.round = round;
15134
15156
  exports.withoutIndex = withoutIndex;
15135
15157
  //# sourceMappingURL=index.js.map