@trackunit/shared-utils 0.0.55 → 0.0.57
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/index.cjs.js +30 -1
- package/index.esm.d.ts +1 -0
- package/index.esm.js +29 -2
- package/package.json +1 -1
- package/src/DateTimeFormat.d.ts +4 -4
- package/src/arrayUtils.d.ts +2 -2
- package/src/index.d.ts +1 -0
- package/src/objectUtils.d.ts +1 -1
- package/src/translationUtils.d.ts +18 -0
package/index.cjs.js
CHANGED
|
@@ -697,7 +697,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
697
697
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
698
698
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
699
699
|
});
|
|
700
|
-
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
703
|
+
var e = new Error(message);
|
|
704
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
705
|
+
};
|
|
701
706
|
|
|
702
707
|
const dataURItoBlob = (dataURI) => {
|
|
703
708
|
var _a, _b, _c, _d, _e;
|
|
@@ -1037,7 +1042,30 @@ const titleCase = (s) => {
|
|
|
1037
1042
|
*/
|
|
1038
1043
|
const removeLeftPadding = (id) => Number(id === null || id === void 0 ? void 0 : id.replace(/-/g, "").replace(/^0+/, ""));
|
|
1039
1044
|
|
|
1045
|
+
/* eslint-disable local-rules/prefer-custom-object-keys */
|
|
1046
|
+
/* eslint-disable local-rules/prefer-custom-object-from-entries */
|
|
1047
|
+
/**
|
|
1048
|
+
* Sorts the given object alphabetically, caseFirst: "lower".
|
|
1049
|
+
*/
|
|
1050
|
+
const alphabeticallySort = (sortInput) => {
|
|
1051
|
+
const sortedObject = Object.fromEntries(Object.keys(sortInput)
|
|
1052
|
+
.sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }))
|
|
1053
|
+
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
1054
|
+
.map(key => [key, sortInput[key]]));
|
|
1055
|
+
return sortedObject;
|
|
1056
|
+
};
|
|
1057
|
+
/**
|
|
1058
|
+
* Checks if the given object is sorted alphabetically, caseFirst: "lower".
|
|
1059
|
+
*/
|
|
1060
|
+
const isSorted = (sortInput) => {
|
|
1061
|
+
const originalKeys = Object.keys(sortInput);
|
|
1062
|
+
const sortedKeys = [...originalKeys].sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }));
|
|
1063
|
+
// Compare the original keys with the sorted keys
|
|
1064
|
+
return originalKeys.every((key, index) => key === sortedKeys[index]);
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1040
1067
|
exports.align = align;
|
|
1068
|
+
exports.alphabeticallySort = alphabeticallySort;
|
|
1041
1069
|
exports.arrayLengthCompare = arrayLengthCompare;
|
|
1042
1070
|
exports.arrayNotEmpty = arrayNotEmpty;
|
|
1043
1071
|
exports.booleanCompare = booleanCompare;
|
|
@@ -1069,6 +1097,7 @@ exports.groupBy = groupBy;
|
|
|
1069
1097
|
exports.groupTinyDataToOthers = groupTinyDataToOthers;
|
|
1070
1098
|
exports.hourIntervals = hourIntervals;
|
|
1071
1099
|
exports.intersection = intersection;
|
|
1100
|
+
exports.isSorted = isSorted;
|
|
1072
1101
|
exports.isStringArrayEqual = isStringArrayEqual;
|
|
1073
1102
|
exports.isUUID = isUUID;
|
|
1074
1103
|
exports.isValidImage = isValidImage;
|
package/index.esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.esm.js
CHANGED
|
@@ -693,7 +693,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
693
693
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
694
694
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
695
695
|
});
|
|
696
|
-
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
699
|
+
var e = new Error(message);
|
|
700
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
701
|
+
};
|
|
697
702
|
|
|
698
703
|
const dataURItoBlob = (dataURI) => {
|
|
699
704
|
var _a, _b, _c, _d, _e;
|
|
@@ -1033,4 +1038,26 @@ const titleCase = (s) => {
|
|
|
1033
1038
|
*/
|
|
1034
1039
|
const removeLeftPadding = (id) => Number(id === null || id === void 0 ? void 0 : id.replace(/-/g, "").replace(/^0+/, ""));
|
|
1035
1040
|
|
|
1036
|
-
|
|
1041
|
+
/* eslint-disable local-rules/prefer-custom-object-keys */
|
|
1042
|
+
/* eslint-disable local-rules/prefer-custom-object-from-entries */
|
|
1043
|
+
/**
|
|
1044
|
+
* Sorts the given object alphabetically, caseFirst: "lower".
|
|
1045
|
+
*/
|
|
1046
|
+
const alphabeticallySort = (sortInput) => {
|
|
1047
|
+
const sortedObject = Object.fromEntries(Object.keys(sortInput)
|
|
1048
|
+
.sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }))
|
|
1049
|
+
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
1050
|
+
.map(key => [key, sortInput[key]]));
|
|
1051
|
+
return sortedObject;
|
|
1052
|
+
};
|
|
1053
|
+
/**
|
|
1054
|
+
* Checks if the given object is sorted alphabetically, caseFirst: "lower".
|
|
1055
|
+
*/
|
|
1056
|
+
const isSorted = (sortInput) => {
|
|
1057
|
+
const originalKeys = Object.keys(sortInput);
|
|
1058
|
+
const sortedKeys = [...originalKeys].sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }));
|
|
1059
|
+
// Compare the original keys with the sorted keys
|
|
1060
|
+
return originalKeys.every((key, index) => key === sortedKeys[index]);
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
export { DateTimeFormat, HoursAndMinutesFormat, align, alphabeticallySort, arrayLengthCompare, arrayNotEmpty, booleanCompare, capitalize, convertBlobToBase64, convertMetersToYards, convertYardsToMeters, dateCompare, deleteUndefinedKeys, difference, doNothing, ensureArray, enumFromValue, enumFromValueTypesafe, enumOrUndefinedFromValue, exhaustiveCheck, filterByMultiple, formatAddress, formatCoordinates, fuzzySearch, getDifferenceBetweenDates, getEndOfDay, getISOStringFromDate, getMultipleCoordinatesFromGeoJsonObject, getPointCoordinateFromGeoJsonObject, getResizedDimensions, getStartOfDay, groupBy, groupTinyDataToOthers, hourIntervals, intersection, isSorted, isStringArrayEqual, isUUID, isValidImage, nonNullable, numberCompare, numberCompareUnknownAfterHighest, objNotEmpty, objectEntries, objectFromEntries, objectKeys, objectValues, pick, removeLeftPadding, resizeBlob, resizeImage, size, stringCompare, stringCompareFromKey, stringNaturalCompare, titleCase, toID, toIDs, toUUID, toggle, trimIds, trimPath, truthy, unionArraysByKey };
|
package/package.json
CHANGED
package/src/DateTimeFormat.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare enum HoursAndMinutesFormat {
|
|
2
|
-
HOURS_MIN_SEC_LONG = "HOURS_MIN_SEC_LONG"
|
|
3
|
-
HOURS_MIN_SEC = "HOURS_MIN_SEC"
|
|
4
|
-
HOURS_MIN_LONG = "HOURS_MIN_LONG"
|
|
5
|
-
HOURS_MIN = "HOURS_MIN"
|
|
2
|
+
HOURS_MIN_SEC_LONG = "HOURS_MIN_SEC_LONG",// h [h] mm [min] ss [sec]
|
|
3
|
+
HOURS_MIN_SEC = "HOURS_MIN_SEC",// h[h] m[m] s[s]
|
|
4
|
+
HOURS_MIN_LONG = "HOURS_MIN_LONG",// h [hrs] mm [min]
|
|
5
|
+
HOURS_MIN = "HOURS_MIN",// h[h] m[m]
|
|
6
6
|
HOURS_LONG = "HOURS_LONG"
|
|
7
7
|
}
|
|
8
8
|
export type HoursAndMinutesFormatType = `${HoursAndMinutesFormat}`;
|
package/src/arrayUtils.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare function ensureArray<T>(arrayish: T | T[]): T[];
|
|
|
10
10
|
* @param newArray The new array of items to merge with the previous array
|
|
11
11
|
* @returns A new array with the items from the previous array and the new array, but only if the item's key is unique.
|
|
12
12
|
*/
|
|
13
|
-
export declare const unionArraysByKey: <T extends object>(key: keyof T, previous: T[] |
|
|
13
|
+
export declare const unionArraysByKey: <T extends object>(key: keyof T, previous: T[] | undefined | null, newArray: T[] | undefined | null) => T[];
|
|
14
14
|
/** Ensures if an array is equal to another array */
|
|
15
15
|
export declare const isStringArrayEqual: (first?: string[], second?: string[]) => boolean;
|
|
16
16
|
/**
|
|
@@ -19,4 +19,4 @@ export declare const isStringArrayEqual: (first?: string[], second?: string[]) =
|
|
|
19
19
|
* @param array - The array to check.
|
|
20
20
|
* @returns The array if not empty, otherwise undefined.
|
|
21
21
|
*/
|
|
22
|
-
export declare const arrayNotEmpty: <T>(array?: T[]
|
|
22
|
+
export declare const arrayNotEmpty: <T>(array?: T[]) => T[] | undefined;
|
package/src/index.d.ts
CHANGED
package/src/objectUtils.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const deleteUndefinedKeys: <T extends Record<string, unknown>>(ob
|
|
|
12
12
|
* @param obj - The object to check.
|
|
13
13
|
* @returns The object if not empty, otherwise undefined.
|
|
14
14
|
*/
|
|
15
|
-
export declare const objNotEmpty: <T extends object>(obj?: T
|
|
15
|
+
export declare const objNotEmpty: <T extends object>(obj?: T) => T | undefined;
|
|
16
16
|
/**
|
|
17
17
|
* Picks the given keys from an object, typesafe.
|
|
18
18
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A translation object.
|
|
3
|
+
*/
|
|
4
|
+
export interface TranslationObject {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Sorts the given object alphabetically, caseFirst: "lower".
|
|
9
|
+
*/
|
|
10
|
+
export type SortInput = TranslationObject;
|
|
11
|
+
/**
|
|
12
|
+
* Sorts the given object alphabetically, caseFirst: "lower".
|
|
13
|
+
*/
|
|
14
|
+
export declare const alphabeticallySort: (sortInput: SortInput) => TranslationObject;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the given object is sorted alphabetically, caseFirst: "lower".
|
|
17
|
+
*/
|
|
18
|
+
export declare const isSorted: (sortInput: SortInput) => boolean;
|