@trackunit/shared-utils 1.8.25 → 1.8.27
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 +9 -17
- package/index.esm.js +9 -17
- package/package.json +2 -2
package/index.cjs.js
CHANGED
|
@@ -59,9 +59,7 @@ const truthy = (value) => {
|
|
|
59
59
|
* @param {TObject} object - The object to convert.
|
|
60
60
|
* @template TObject - The type of the object.
|
|
61
61
|
*/
|
|
62
|
-
const objectEntries = (object) =>
|
|
63
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
64
|
-
Object.entries(object);
|
|
62
|
+
const objectEntries = (object) => Object.entries(object);
|
|
65
63
|
/**
|
|
66
64
|
* Converts an array of key-value pairs into an object.
|
|
67
65
|
* This is a type-faithful alternative to Object.fromEntries().
|
|
@@ -70,7 +68,6 @@ Object.entries(object);
|
|
|
70
68
|
* @template TEntries - The type of the entries array.
|
|
71
69
|
*/
|
|
72
70
|
const objectFromEntries = (entries) => {
|
|
73
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
74
71
|
return Object.fromEntries(entries);
|
|
75
72
|
};
|
|
76
73
|
/**
|
|
@@ -87,7 +84,6 @@ const objectFromEntries = (entries) => {
|
|
|
87
84
|
* @returns {(keyof TObject)[]} An array of the keys of the object.
|
|
88
85
|
*/
|
|
89
86
|
const objectKeys = (object) => {
|
|
90
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
91
87
|
return Object.keys(object).map(key => key);
|
|
92
88
|
};
|
|
93
89
|
/**
|
|
@@ -101,9 +97,7 @@ const objectKeys = (object) => {
|
|
|
101
97
|
* @param {TObject} object - The object to get the values from.
|
|
102
98
|
* @returns {TObject[keyof TObject][]} An array of the values of the object.
|
|
103
99
|
*/
|
|
104
|
-
const objectValues = (object) =>
|
|
105
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
106
|
-
Object.values(object);
|
|
100
|
+
const objectValues = (object) => Object.values(object);
|
|
107
101
|
|
|
108
102
|
/**
|
|
109
103
|
* Returns a new array with the items from the previous array and the new array, but only if the item's key is unique.
|
|
@@ -218,7 +212,7 @@ const getISOStringFromDate = (date) => {
|
|
|
218
212
|
}
|
|
219
213
|
return new Date(date).toISOString();
|
|
220
214
|
}
|
|
221
|
-
catch
|
|
215
|
+
catch {
|
|
222
216
|
return null;
|
|
223
217
|
}
|
|
224
218
|
};
|
|
@@ -682,9 +676,7 @@ const pick = (obj, ...keys) => {
|
|
|
682
676
|
return keys.reduce((acc, key) => {
|
|
683
677
|
acc[key] = obj[key];
|
|
684
678
|
return acc;
|
|
685
|
-
},
|
|
686
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
687
|
-
{});
|
|
679
|
+
}, {});
|
|
688
680
|
};
|
|
689
681
|
/**
|
|
690
682
|
* Returns an object with only the differences between two input objects.
|
|
@@ -715,7 +707,7 @@ const getFirstLevelObjectPropertyDifferences = (obj1, obj2) => {
|
|
|
715
707
|
* @example replaceNullableNumbersWithZero({ a: 1, b: null, c: undefined }) // { a: 1, b: 0, c: 0 }
|
|
716
708
|
*/
|
|
717
709
|
const replaceNullableNumbersWithZero = (record) => {
|
|
718
|
-
// eslint-disable-next-line local-rules/
|
|
710
|
+
// eslint-disable-next-line local-rules/prefer-custom-object-from-entries
|
|
719
711
|
return Object.fromEntries(objectEntries(record).map(([key, value]) => [key, value ?? 0]));
|
|
720
712
|
};
|
|
721
713
|
/**
|
|
@@ -729,7 +721,6 @@ const replaceNullableNumbersWithZero = (record) => {
|
|
|
729
721
|
const removeProperty = (obj, key) => {
|
|
730
722
|
const { [key]: _, ...rest } = obj;
|
|
731
723
|
// should be safe because we remove the key from the object, just no way to type it properly
|
|
732
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
733
724
|
return rest;
|
|
734
725
|
};
|
|
735
726
|
/**
|
|
@@ -746,7 +737,6 @@ const removeProperties = (obj, keys) => {
|
|
|
746
737
|
delete result[key];
|
|
747
738
|
}
|
|
748
739
|
// should be safe because we remove the keys from the object, just no way to type it properly
|
|
749
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
750
740
|
return result;
|
|
751
741
|
};
|
|
752
742
|
|
|
@@ -850,6 +840,9 @@ const resizeImageElement = (image, maxWidth, maxHeight) => {
|
|
|
850
840
|
canvas.width = newDim.width;
|
|
851
841
|
canvas.height = newDim.height;
|
|
852
842
|
const context = canvas.getContext("2d");
|
|
843
|
+
if (!context) {
|
|
844
|
+
throw new Error("Failed to get canvas context");
|
|
845
|
+
}
|
|
853
846
|
context.fillStyle = "white";
|
|
854
847
|
context.fillRect(0, 0, newDim.width, newDim.height);
|
|
855
848
|
context.drawImage(image, 0, 0, newDim.width, newDim.height);
|
|
@@ -1279,8 +1272,7 @@ const svgToPNG = async ({ base64EncodedSVG, maxWidth, maxHeight, idealArea, }) =
|
|
|
1279
1272
|
const alphabeticallySort = (sortInput) => {
|
|
1280
1273
|
const sortedObject = Object.fromEntries(Object.keys(sortInput)
|
|
1281
1274
|
.sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }))
|
|
1282
|
-
|
|
1283
|
-
.map(key => [key, sortInput[key]]));
|
|
1275
|
+
.map(key => [key, sortInput[key] ?? ""]));
|
|
1284
1276
|
return sortedObject;
|
|
1285
1277
|
};
|
|
1286
1278
|
/**
|
package/index.esm.js
CHANGED
|
@@ -57,9 +57,7 @@ const truthy = (value) => {
|
|
|
57
57
|
* @param {TObject} object - The object to convert.
|
|
58
58
|
* @template TObject - The type of the object.
|
|
59
59
|
*/
|
|
60
|
-
const objectEntries = (object) =>
|
|
61
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
62
|
-
Object.entries(object);
|
|
60
|
+
const objectEntries = (object) => Object.entries(object);
|
|
63
61
|
/**
|
|
64
62
|
* Converts an array of key-value pairs into an object.
|
|
65
63
|
* This is a type-faithful alternative to Object.fromEntries().
|
|
@@ -68,7 +66,6 @@ Object.entries(object);
|
|
|
68
66
|
* @template TEntries - The type of the entries array.
|
|
69
67
|
*/
|
|
70
68
|
const objectFromEntries = (entries) => {
|
|
71
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
72
69
|
return Object.fromEntries(entries);
|
|
73
70
|
};
|
|
74
71
|
/**
|
|
@@ -85,7 +82,6 @@ const objectFromEntries = (entries) => {
|
|
|
85
82
|
* @returns {(keyof TObject)[]} An array of the keys of the object.
|
|
86
83
|
*/
|
|
87
84
|
const objectKeys = (object) => {
|
|
88
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
89
85
|
return Object.keys(object).map(key => key);
|
|
90
86
|
};
|
|
91
87
|
/**
|
|
@@ -99,9 +95,7 @@ const objectKeys = (object) => {
|
|
|
99
95
|
* @param {TObject} object - The object to get the values from.
|
|
100
96
|
* @returns {TObject[keyof TObject][]} An array of the values of the object.
|
|
101
97
|
*/
|
|
102
|
-
const objectValues = (object) =>
|
|
103
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
104
|
-
Object.values(object);
|
|
98
|
+
const objectValues = (object) => Object.values(object);
|
|
105
99
|
|
|
106
100
|
/**
|
|
107
101
|
* Returns a new array with the items from the previous array and the new array, but only if the item's key is unique.
|
|
@@ -216,7 +210,7 @@ const getISOStringFromDate = (date) => {
|
|
|
216
210
|
}
|
|
217
211
|
return new Date(date).toISOString();
|
|
218
212
|
}
|
|
219
|
-
catch
|
|
213
|
+
catch {
|
|
220
214
|
return null;
|
|
221
215
|
}
|
|
222
216
|
};
|
|
@@ -680,9 +674,7 @@ const pick = (obj, ...keys) => {
|
|
|
680
674
|
return keys.reduce((acc, key) => {
|
|
681
675
|
acc[key] = obj[key];
|
|
682
676
|
return acc;
|
|
683
|
-
},
|
|
684
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
685
|
-
{});
|
|
677
|
+
}, {});
|
|
686
678
|
};
|
|
687
679
|
/**
|
|
688
680
|
* Returns an object with only the differences between two input objects.
|
|
@@ -713,7 +705,7 @@ const getFirstLevelObjectPropertyDifferences = (obj1, obj2) => {
|
|
|
713
705
|
* @example replaceNullableNumbersWithZero({ a: 1, b: null, c: undefined }) // { a: 1, b: 0, c: 0 }
|
|
714
706
|
*/
|
|
715
707
|
const replaceNullableNumbersWithZero = (record) => {
|
|
716
|
-
// eslint-disable-next-line local-rules/
|
|
708
|
+
// eslint-disable-next-line local-rules/prefer-custom-object-from-entries
|
|
717
709
|
return Object.fromEntries(objectEntries(record).map(([key, value]) => [key, value ?? 0]));
|
|
718
710
|
};
|
|
719
711
|
/**
|
|
@@ -727,7 +719,6 @@ const replaceNullableNumbersWithZero = (record) => {
|
|
|
727
719
|
const removeProperty = (obj, key) => {
|
|
728
720
|
const { [key]: _, ...rest } = obj;
|
|
729
721
|
// should be safe because we remove the key from the object, just no way to type it properly
|
|
730
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
731
722
|
return rest;
|
|
732
723
|
};
|
|
733
724
|
/**
|
|
@@ -744,7 +735,6 @@ const removeProperties = (obj, keys) => {
|
|
|
744
735
|
delete result[key];
|
|
745
736
|
}
|
|
746
737
|
// should be safe because we remove the keys from the object, just no way to type it properly
|
|
747
|
-
// eslint-disable-next-line local-rules/no-typescript-assertion
|
|
748
738
|
return result;
|
|
749
739
|
};
|
|
750
740
|
|
|
@@ -848,6 +838,9 @@ const resizeImageElement = (image, maxWidth, maxHeight) => {
|
|
|
848
838
|
canvas.width = newDim.width;
|
|
849
839
|
canvas.height = newDim.height;
|
|
850
840
|
const context = canvas.getContext("2d");
|
|
841
|
+
if (!context) {
|
|
842
|
+
throw new Error("Failed to get canvas context");
|
|
843
|
+
}
|
|
851
844
|
context.fillStyle = "white";
|
|
852
845
|
context.fillRect(0, 0, newDim.width, newDim.height);
|
|
853
846
|
context.drawImage(image, 0, 0, newDim.width, newDim.height);
|
|
@@ -1277,8 +1270,7 @@ const svgToPNG = async ({ base64EncodedSVG, maxWidth, maxHeight, idealArea, }) =
|
|
|
1277
1270
|
const alphabeticallySort = (sortInput) => {
|
|
1278
1271
|
const sortedObject = Object.fromEntries(Object.keys(sortInput)
|
|
1279
1272
|
.sort((a, b) => a.localeCompare(b, undefined, { caseFirst: "lower" }))
|
|
1280
|
-
|
|
1281
|
-
.map(key => [key, sortInput[key]]));
|
|
1273
|
+
.map(key => [key, sortInput[key] ?? ""]));
|
|
1282
1274
|
return sortedObject;
|
|
1283
1275
|
};
|
|
1284
1276
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/shared-utils",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.27",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.x"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"uuid": "^11.1.0",
|
|
11
|
-
"@trackunit/react-test-setup": "1.3.
|
|
11
|
+
"@trackunit/react-test-setup": "1.3.27"
|
|
12
12
|
},
|
|
13
13
|
"module": "./index.esm.js",
|
|
14
14
|
"main": "./index.cjs.js",
|