@trackunit/shared-utils 0.0.54 → 0.0.56

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 CHANGED
@@ -1037,7 +1037,30 @@ const titleCase = (s) => {
1037
1037
  */
1038
1038
  const removeLeftPadding = (id) => Number(id === null || id === void 0 ? void 0 : id.replace(/-/g, "").replace(/^0+/, ""));
1039
1039
 
1040
+ /* eslint-disable local-rules/prefer-custom-object-keys */
1041
+ /* eslint-disable local-rules/prefer-custom-object-from-entries */
1042
+ /**
1043
+ * Sorts the given object alphabetically, caseFirst: "lower".
1044
+ */
1045
+ const alphabeticallySort = (sortInput) => {
1046
+ const sortedObject = Object.fromEntries(Object.keys(sortInput)
1047
+ .sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }))
1048
+ // eslint-disable-next-line local-rules/no-typescript-assertion
1049
+ .map(key => [key, sortInput[key]]));
1050
+ return sortedObject;
1051
+ };
1052
+ /**
1053
+ * Checks if the given object is sorted alphabetically, caseFirst: "lower".
1054
+ */
1055
+ const isSorted = (sortInput) => {
1056
+ const originalKeys = Object.keys(sortInput);
1057
+ const sortedKeys = [...originalKeys].sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }));
1058
+ // Compare the original keys with the sorted keys
1059
+ return originalKeys.every((key, index) => key === sortedKeys[index]);
1060
+ };
1061
+
1040
1062
  exports.align = align;
1063
+ exports.alphabeticallySort = alphabeticallySort;
1041
1064
  exports.arrayLengthCompare = arrayLengthCompare;
1042
1065
  exports.arrayNotEmpty = arrayNotEmpty;
1043
1066
  exports.booleanCompare = booleanCompare;
@@ -1069,6 +1092,7 @@ exports.groupBy = groupBy;
1069
1092
  exports.groupTinyDataToOthers = groupTinyDataToOthers;
1070
1093
  exports.hourIntervals = hourIntervals;
1071
1094
  exports.intersection = intersection;
1095
+ exports.isSorted = isSorted;
1072
1096
  exports.isStringArrayEqual = isStringArrayEqual;
1073
1097
  exports.isUUID = isUUID;
1074
1098
  exports.isValidImage = isValidImage;
package/index.esm.js CHANGED
@@ -1033,4 +1033,26 @@ const titleCase = (s) => {
1033
1033
  */
1034
1034
  const removeLeftPadding = (id) => Number(id === null || id === void 0 ? void 0 : id.replace(/-/g, "").replace(/^0+/, ""));
1035
1035
 
1036
- export { DateTimeFormat, HoursAndMinutesFormat, align, 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, 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 };
1036
+ /* eslint-disable local-rules/prefer-custom-object-keys */
1037
+ /* eslint-disable local-rules/prefer-custom-object-from-entries */
1038
+ /**
1039
+ * Sorts the given object alphabetically, caseFirst: "lower".
1040
+ */
1041
+ const alphabeticallySort = (sortInput) => {
1042
+ const sortedObject = Object.fromEntries(Object.keys(sortInput)
1043
+ .sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }))
1044
+ // eslint-disable-next-line local-rules/no-typescript-assertion
1045
+ .map(key => [key, sortInput[key]]));
1046
+ return sortedObject;
1047
+ };
1048
+ /**
1049
+ * Checks if the given object is sorted alphabetically, caseFirst: "lower".
1050
+ */
1051
+ const isSorted = (sortInput) => {
1052
+ const originalKeys = Object.keys(sortInput);
1053
+ const sortedKeys = [...originalKeys].sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }));
1054
+ // Compare the original keys with the sorted keys
1055
+ return originalKeys.every((key, index) => key === sortedKeys[index]);
1056
+ };
1057
+
1058
+ 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/shared-utils",
3
- "version": "0.0.54",
3
+ "version": "0.0.56",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
package/src/index.d.ts CHANGED
@@ -20,4 +20,5 @@ export * from "./pathUtils";
20
20
  export * from "./pictureUtils/pictureUtils";
21
21
  export * from "./sorting/sorting";
22
22
  export * from "./stringUtils";
23
+ export * from "./translationUtils";
23
24
  export * from "./typeUtils";
@@ -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;