@mll-lab/js-utils 2.4.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/error.d.ts +7 -0
- package/dist/{round.test.d.ts → error.test.d.ts} +0 -0
- package/dist/index.common.js +43 -9
- package/dist/index.common.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +43 -9
- package/dist/index.js.map +1 -1
- package/dist/{round.d.ts → number.d.ts} +1 -0
- package/dist/number.test.d.ts +1 -0
- package/dist/predicates.d.ts +1 -0
- package/package.json +1 -1
package/dist/error.d.ts
ADDED
|
File without changes
|
package/dist/index.common.js
CHANGED
|
@@ -15111,6 +15111,44 @@ function formatDotlessDate(date) {
|
|
|
15111
15111
|
return format(date, DOTLESS_DATE_FORMAT, { locale: de$1 });
|
|
15112
15112
|
}
|
|
15113
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
|
+
|
|
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
|
+
|
|
15114
15152
|
function pluralize(amount, singular, plural) {
|
|
15115
15153
|
if (amount === 1) {
|
|
15116
15154
|
return singular;
|
|
@@ -15150,15 +15188,8 @@ const isURL = (value) => {
|
|
|
15150
15188
|
const isWord = (value) => isString(value) && /^[\w-]+$/.test(value);
|
|
15151
15189
|
const isLabId = (value) => isString(value) && /^\d{2}-\d{6}$/.test(value);
|
|
15152
15190
|
const isRackBarcode = (value) => isString(value) && /^[A-Z]{2}\d{8}$/.test(value);
|
|
15153
|
-
|
|
15154
|
-
|
|
15155
|
-
* Round a number to a given number of decimal places.
|
|
15156
|
-
*
|
|
15157
|
-
* https://gist.github.com/djD-REK/2e347f5532bb22310daf450f03ec6ad8
|
|
15158
|
-
*/
|
|
15159
|
-
function round(number, decimalPlaces) {
|
|
15160
|
-
const factorOfTen = Math.pow(10, decimalPlaces);
|
|
15161
|
-
return Math.round(number * factorOfTen) / factorOfTen;
|
|
15191
|
+
function isNotNullish(value) {
|
|
15192
|
+
return value != null;
|
|
15162
15193
|
}
|
|
15163
15194
|
|
|
15164
15195
|
function includesIgnoreCase(needle, haystack) {
|
|
@@ -15181,6 +15212,8 @@ exports.ISO_DATE_FORMAT = ISO_DATE_FORMAT;
|
|
|
15181
15212
|
exports.ISO_DATE_TIME_FORMAT = ISO_DATE_TIME_FORMAT;
|
|
15182
15213
|
exports.SECONDLESS_DATE_TIME_FORMAT = SECONDLESS_DATE_TIME_FORMAT;
|
|
15183
15214
|
exports.containSameValues = containSameValues;
|
|
15215
|
+
exports.errorMessage = errorMessage;
|
|
15216
|
+
exports.firstDecimalDigit = firstDecimalDigit;
|
|
15184
15217
|
exports.firstLine = firstLine;
|
|
15185
15218
|
exports.formatDotlessDate = formatDotlessDate;
|
|
15186
15219
|
exports.formatGerman = formatGerman;
|
|
@@ -15197,6 +15230,7 @@ exports.isEmail = isEmail;
|
|
|
15197
15230
|
exports.isFuture = isFuture;
|
|
15198
15231
|
exports.isLabId = isLabId;
|
|
15199
15232
|
exports.isNonEmptyArray = isNonEmptyArray;
|
|
15233
|
+
exports.isNotNullish = isNotNullish;
|
|
15200
15234
|
exports.isOnlyDigits = isOnlyDigits;
|
|
15201
15235
|
exports.isRackBarcode = isRackBarcode;
|
|
15202
15236
|
exports.isString = isString;
|