@mll-lab/js-utils 2.6.0 → 2.9.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.common.js +44 -10
- package/dist/index.common.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +44 -10
- package/dist/index.js.map +1 -1
- package/dist/{round.d.ts → number.d.ts} +1 -0
- package/dist/{round.test.d.ts → number.test.d.ts} +0 -0
- package/dist/string.d.ts +1 -0
- package/dist/style.d.ts +6 -0
- package/dist/style.test.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
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));
|
|
@@ -15190,6 +15201,26 @@ function includesIgnoreCase(needle, haystack) {
|
|
|
15190
15201
|
function firstLine(multilineText) {
|
|
15191
15202
|
return multilineText.split('\n', 1)[0];
|
|
15192
15203
|
}
|
|
15204
|
+
function joinNonEmpty(maybeStrings, separator) {
|
|
15205
|
+
return maybeStrings.filter(Boolean).join(separator);
|
|
15206
|
+
}
|
|
15207
|
+
|
|
15208
|
+
/**
|
|
15209
|
+
* Converts pixel value to number.
|
|
15210
|
+
*
|
|
15211
|
+
* @example "4px" to 4
|
|
15212
|
+
*/
|
|
15213
|
+
function pxToNumber(pixels) {
|
|
15214
|
+
const count = (pixels.match(/px/g) || []).length;
|
|
15215
|
+
if (count > 1 || !pixels.endsWith('px')) {
|
|
15216
|
+
throw new Error(`'${pixels}' does not contain a single 'px'`);
|
|
15217
|
+
}
|
|
15218
|
+
const parsedValue = parseFloat(pixels);
|
|
15219
|
+
if (Number.isNaN(parsedValue)) {
|
|
15220
|
+
throw new Error(`'${pixels}' is not a valid single pixel-value`);
|
|
15221
|
+
}
|
|
15222
|
+
return parsedValue;
|
|
15223
|
+
}
|
|
15193
15224
|
|
|
15194
15225
|
exports.DOTLESS_DATE_FORMAT = DOTLESS_DATE_FORMAT;
|
|
15195
15226
|
exports.EMAIL_REGEX = EMAIL_REGEX;
|
|
@@ -15202,6 +15233,7 @@ exports.ISO_DATE_TIME_FORMAT = ISO_DATE_TIME_FORMAT;
|
|
|
15202
15233
|
exports.SECONDLESS_DATE_TIME_FORMAT = SECONDLESS_DATE_TIME_FORMAT;
|
|
15203
15234
|
exports.containSameValues = containSameValues;
|
|
15204
15235
|
exports.errorMessage = errorMessage;
|
|
15236
|
+
exports.firstDecimalDigit = firstDecimalDigit;
|
|
15205
15237
|
exports.firstLine = firstLine;
|
|
15206
15238
|
exports.formatDotlessDate = formatDotlessDate;
|
|
15207
15239
|
exports.formatGerman = formatGerman;
|
|
@@ -15225,6 +15257,7 @@ exports.isString = isString;
|
|
|
15225
15257
|
exports.isToday = isToday;
|
|
15226
15258
|
exports.isURL = isURL;
|
|
15227
15259
|
exports.isWord = isWord;
|
|
15260
|
+
exports.joinNonEmpty = joinNonEmpty;
|
|
15228
15261
|
exports.last = last;
|
|
15229
15262
|
exports.parseDate = parseDate;
|
|
15230
15263
|
exports.parseDotlessDate = parseDotlessDate;
|
|
@@ -15236,6 +15269,7 @@ exports.parseIsoDate = parseIsoDate;
|
|
|
15236
15269
|
exports.parseIsoDateTime = parseIsoDateTime;
|
|
15237
15270
|
exports.parseSecondlessDateTime = parseSecondlessDateTime;
|
|
15238
15271
|
exports.pluralize = pluralize;
|
|
15272
|
+
exports.pxToNumber = pxToNumber;
|
|
15239
15273
|
exports.round = round;
|
|
15240
15274
|
exports.withoutIndex = withoutIndex;
|
|
15241
15275
|
//# sourceMappingURL=index.js.map
|