@mll-lab/js-utils 2.33.0 → 2.35.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/array.d.ts +8 -1
- package/dist/index.common.js +30 -10
- package/dist/index.common.js.map +1 -1
- package/dist/index.js +30 -10
- package/dist/index.js.map +1 -1
- package/dist/typeGuards.d.ts +5 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9505,7 +9505,7 @@ function sortByArray(subject, recipe) {
|
|
|
9505
9505
|
return lodash.sortBy(subject, (value) => recipe.indexOf(value));
|
|
9506
9506
|
}
|
|
9507
9507
|
/**
|
|
9508
|
-
* Takes a function that maps the values to sort and returns a compare function
|
|
9508
|
+
* Takes a function that maps the values to sort to strings and returns a compare function
|
|
9509
9509
|
* using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
|
|
9510
9510
|
*
|
|
9511
9511
|
* null, undefined and the empty string are not distinguished and first in sort order.
|
|
@@ -9518,6 +9518,20 @@ function makeStringCompareFn(map) {
|
|
|
9518
9518
|
return mappedA.localeCompare(mappedB);
|
|
9519
9519
|
};
|
|
9520
9520
|
}
|
|
9521
|
+
/**
|
|
9522
|
+
* Takes a function that maps the values to sort to numbers and returns a compare function
|
|
9523
|
+
* using subtraction, usable in `Array.toSorted` or similar APIs.
|
|
9524
|
+
*
|
|
9525
|
+
* null and undefined are coalesced to `fallbackValue`, by default 0, and thus not distinguished and first in sort order.
|
|
9526
|
+
*/
|
|
9527
|
+
function makeNumberCompareFn(map, fallbackValue = 0) {
|
|
9528
|
+
return (a, b) => {
|
|
9529
|
+
var _a, _b;
|
|
9530
|
+
const mappedA = (_a = map(a)) !== null && _a !== void 0 ? _a : fallbackValue;
|
|
9531
|
+
const mappedB = (_b = map(b)) !== null && _b !== void 0 ? _b : fallbackValue;
|
|
9532
|
+
return mappedA - mappedB;
|
|
9533
|
+
};
|
|
9534
|
+
}
|
|
9521
9535
|
/**
|
|
9522
9536
|
* Returns a compare function for values that are string, null or undefined,
|
|
9523
9537
|
* using `String.prototype.localeCompare`, usable in `Array.toSorted` or similar APIs.
|
|
@@ -16038,15 +16052,6 @@ function pluralize(amount, singular, plural) {
|
|
|
16038
16052
|
return plural;
|
|
16039
16053
|
}
|
|
16040
16054
|
|
|
16041
|
-
function isString(value) {
|
|
16042
|
-
return typeof value === 'string';
|
|
16043
|
-
}
|
|
16044
|
-
function isNonEmptyString(value) {
|
|
16045
|
-
return isString(value) && value !== '';
|
|
16046
|
-
}
|
|
16047
|
-
function isNotNullish(value) {
|
|
16048
|
-
return value != null;
|
|
16049
|
-
}
|
|
16050
16055
|
function isArrayOfStrings(value) {
|
|
16051
16056
|
return value instanceof Array && value.every(isString);
|
|
16052
16057
|
}
|
|
@@ -16056,6 +16061,19 @@ function isEmptyObject(value) {
|
|
|
16056
16061
|
!(value instanceof Array) &&
|
|
16057
16062
|
Object.keys(value).length === 0);
|
|
16058
16063
|
}
|
|
16064
|
+
function isNonEmptyString(value) {
|
|
16065
|
+
return isString(value) && value !== '';
|
|
16066
|
+
}
|
|
16067
|
+
function isNotNullish(value) {
|
|
16068
|
+
return value != null;
|
|
16069
|
+
}
|
|
16070
|
+
function isString(value) {
|
|
16071
|
+
return typeof value === 'string';
|
|
16072
|
+
}
|
|
16073
|
+
/** https://developer.mozilla.org/en-US/docs/Glossary/Falsy */
|
|
16074
|
+
function isTruthy(value) {
|
|
16075
|
+
return Boolean(value);
|
|
16076
|
+
}
|
|
16059
16077
|
|
|
16060
16078
|
const isAlphanumeric = function isAlphanumeric(value) {
|
|
16061
16079
|
return isString(value) && /^[A-Za-z0-9]+$/.test(value);
|
|
@@ -16216,6 +16234,7 @@ exports.isRackBarcode = isRackBarcode;
|
|
|
16216
16234
|
exports.isString = isString;
|
|
16217
16235
|
exports.isTimeWithHoursAndMinutes = isTimeWithHoursAndMinutes;
|
|
16218
16236
|
exports.isToday = isToday;
|
|
16237
|
+
exports.isTruthy = isTruthy;
|
|
16219
16238
|
exports.isURL = isURL;
|
|
16220
16239
|
exports.isValidGermanDate = isValidGermanDate;
|
|
16221
16240
|
exports.isWord = isWord;
|
|
@@ -16223,6 +16242,7 @@ exports.isZeroish = isZeroish;
|
|
|
16223
16242
|
exports.joinNonEmpty = joinNonEmpty;
|
|
16224
16243
|
exports.last = last;
|
|
16225
16244
|
exports.localeCompareStrings = localeCompareStrings;
|
|
16245
|
+
exports.makeNumberCompareFn = makeNumberCompareFn;
|
|
16226
16246
|
exports.makeStringCompareFn = makeStringCompareFn;
|
|
16227
16247
|
exports.mapSequentially = mapSequentially;
|
|
16228
16248
|
exports.parseDate = parseDate;
|