@mll-lab/js-utils 2.6.0 → 2.7.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,7 +1,7 @@
1
1
  export * from './array';
2
2
  export * from './date';
3
3
  export * from './error';
4
+ export * from './number';
4
5
  export * from './pluralize';
5
6
  export * from './predicates';
6
- export * from './round';
7
7
  export * from './string';
package/dist/index.js CHANGED
@@ -15128,6 +15128,27 @@ function hasMessage(error) {
15128
15128
  return typeof error === 'object' && error !== null && 'message' in error;
15129
15129
  }
15130
15130
 
15131
+ /**
15132
+ * Round a number to a given number of decimal places.
15133
+ *
15134
+ * https://gist.github.com/djD-REK/2e347f5532bb22310daf450f03ec6ad8
15135
+ */
15136
+ function round(number, decimalPlaces) {
15137
+ const factorOfTen = Math.pow(10, decimalPlaces);
15138
+ return Math.round(number * factorOfTen) / factorOfTen;
15139
+ }
15140
+ function firstDecimalDigit(number) {
15141
+ if (number % 1 === 0) {
15142
+ return 0;
15143
+ }
15144
+ const regExp = /\d*\.(\d)/;
15145
+ const regExpMatchArray = number.toString().match(regExp);
15146
+ if (regExpMatchArray === null) {
15147
+ throw new Error(`Invalid number for regex matching: ${number}`);
15148
+ }
15149
+ return Number(regExpMatchArray[1]);
15150
+ }
15151
+
15131
15152
  function pluralize(amount, singular, plural) {
15132
15153
  if (amount === 1) {
15133
15154
  return singular;
@@ -15171,16 +15192,6 @@ function isNotNullish(value) {
15171
15192
  return value != null;
15172
15193
  }
15173
15194
 
15174
- /**
15175
- * Round a number to a given number of decimal places.
15176
- *
15177
- * https://gist.github.com/djD-REK/2e347f5532bb22310daf450f03ec6ad8
15178
- */
15179
- function round(number, decimalPlaces) {
15180
- const factorOfTen = Math.pow(10, decimalPlaces);
15181
- return Math.round(number * factorOfTen) / factorOfTen;
15182
- }
15183
-
15184
15195
  function includesIgnoreCase(needle, haystack) {
15185
15196
  if (haystack instanceof Array) {
15186
15197
  return haystack.some((hay) => includesIgnoreCase(needle, hay));
@@ -15202,6 +15213,7 @@ exports.ISO_DATE_TIME_FORMAT = ISO_DATE_TIME_FORMAT;
15202
15213
  exports.SECONDLESS_DATE_TIME_FORMAT = SECONDLESS_DATE_TIME_FORMAT;
15203
15214
  exports.containSameValues = containSameValues;
15204
15215
  exports.errorMessage = errorMessage;
15216
+ exports.firstDecimalDigit = firstDecimalDigit;
15205
15217
  exports.firstLine = firstLine;
15206
15218
  exports.formatDotlessDate = formatDotlessDate;
15207
15219
  exports.formatGerman = formatGerman;