@trackunit/shared-utils 0.0.60 → 0.0.61
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 +6 -20
- package/index.esm.js +6 -18
- package/package.json +1 -1
- package/src/arrayUtils.d.ts +6 -8
- package/src/typeUtils.d.ts +3 -0
package/index.cjs.js
CHANGED
|
@@ -306,20 +306,6 @@ const objectValues = (object) =>
|
|
|
306
306
|
// eslint-disable-next-line local-rules/no-typescript-assertion, local-rules/prefer-custom-object-values
|
|
307
307
|
Object.values(object);
|
|
308
308
|
|
|
309
|
-
/** toggle whether a value is in an array or not */
|
|
310
|
-
function toggle(array, value) {
|
|
311
|
-
if (value && (array === null || array === void 0 ? void 0 : array.includes(value))) {
|
|
312
|
-
return array.filter(item => item !== value);
|
|
313
|
-
}
|
|
314
|
-
return [...(array || []), value];
|
|
315
|
-
}
|
|
316
|
-
/** Ensure the argument is an array, if not, create array with that element in it */
|
|
317
|
-
function ensureArray(arrayish) {
|
|
318
|
-
if (!arrayish) {
|
|
319
|
-
return [];
|
|
320
|
-
}
|
|
321
|
-
return Array.isArray(arrayish) ? arrayish : [arrayish];
|
|
322
|
-
}
|
|
323
309
|
/**
|
|
324
310
|
* Returns a new array with the items from the previous array and the new array, but only if the item's key is unique.
|
|
325
311
|
*
|
|
@@ -341,15 +327,17 @@ const unionArraysByKey = (key, previous, newArray) => {
|
|
|
341
327
|
})
|
|
342
328
|
.filter(truthy);
|
|
343
329
|
};
|
|
344
|
-
/**
|
|
345
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Checks if two arrays are equal.
|
|
332
|
+
*/
|
|
333
|
+
const isArrayEqual = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
|
|
346
334
|
/**
|
|
347
335
|
* Checks if an array is not empty.
|
|
348
336
|
*
|
|
349
337
|
* @param array - The array to check.
|
|
350
338
|
* @returns The array if not empty, otherwise undefined.
|
|
351
339
|
*/
|
|
352
|
-
const arrayNotEmpty = (array) =>
|
|
340
|
+
const arrayNotEmpty = (array) => array && array.length > 0 ? array : undefined;
|
|
353
341
|
|
|
354
342
|
const align = {
|
|
355
343
|
LEFT: "left",
|
|
@@ -1095,7 +1083,6 @@ exports.dateCompare = dateCompare;
|
|
|
1095
1083
|
exports.deleteUndefinedKeys = deleteUndefinedKeys;
|
|
1096
1084
|
exports.difference = difference;
|
|
1097
1085
|
exports.doNothing = doNothing;
|
|
1098
|
-
exports.ensureArray = ensureArray;
|
|
1099
1086
|
exports.enumFromValue = enumFromValue;
|
|
1100
1087
|
exports.enumFromValueTypesafe = enumFromValueTypesafe;
|
|
1101
1088
|
exports.enumOrUndefinedFromValue = enumOrUndefinedFromValue;
|
|
@@ -1115,8 +1102,8 @@ exports.groupBy = groupBy;
|
|
|
1115
1102
|
exports.groupTinyDataToOthers = groupTinyDataToOthers;
|
|
1116
1103
|
exports.hourIntervals = hourIntervals;
|
|
1117
1104
|
exports.intersection = intersection;
|
|
1105
|
+
exports.isArrayEqual = isArrayEqual;
|
|
1118
1106
|
exports.isSorted = isSorted;
|
|
1119
|
-
exports.isStringArrayEqual = isStringArrayEqual;
|
|
1120
1107
|
exports.isUUID = isUUID;
|
|
1121
1108
|
exports.isValidImage = isValidImage;
|
|
1122
1109
|
exports.nonNullable = nonNullable;
|
|
@@ -1139,7 +1126,6 @@ exports.titleCase = titleCase;
|
|
|
1139
1126
|
exports.toID = toID;
|
|
1140
1127
|
exports.toIDs = toIDs;
|
|
1141
1128
|
exports.toUUID = toUUID;
|
|
1142
|
-
exports.toggle = toggle;
|
|
1143
1129
|
exports.trimIds = trimIds;
|
|
1144
1130
|
exports.trimPath = trimPath;
|
|
1145
1131
|
exports.truthy = truthy;
|
package/index.esm.js
CHANGED
|
@@ -302,20 +302,6 @@ const objectValues = (object) =>
|
|
|
302
302
|
// eslint-disable-next-line local-rules/no-typescript-assertion, local-rules/prefer-custom-object-values
|
|
303
303
|
Object.values(object);
|
|
304
304
|
|
|
305
|
-
/** toggle whether a value is in an array or not */
|
|
306
|
-
function toggle(array, value) {
|
|
307
|
-
if (value && (array === null || array === void 0 ? void 0 : array.includes(value))) {
|
|
308
|
-
return array.filter(item => item !== value);
|
|
309
|
-
}
|
|
310
|
-
return [...(array || []), value];
|
|
311
|
-
}
|
|
312
|
-
/** Ensure the argument is an array, if not, create array with that element in it */
|
|
313
|
-
function ensureArray(arrayish) {
|
|
314
|
-
if (!arrayish) {
|
|
315
|
-
return [];
|
|
316
|
-
}
|
|
317
|
-
return Array.isArray(arrayish) ? arrayish : [arrayish];
|
|
318
|
-
}
|
|
319
305
|
/**
|
|
320
306
|
* Returns a new array with the items from the previous array and the new array, but only if the item's key is unique.
|
|
321
307
|
*
|
|
@@ -337,15 +323,17 @@ const unionArraysByKey = (key, previous, newArray) => {
|
|
|
337
323
|
})
|
|
338
324
|
.filter(truthy);
|
|
339
325
|
};
|
|
340
|
-
/**
|
|
341
|
-
|
|
326
|
+
/**
|
|
327
|
+
* Checks if two arrays are equal.
|
|
328
|
+
*/
|
|
329
|
+
const isArrayEqual = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
|
|
342
330
|
/**
|
|
343
331
|
* Checks if an array is not empty.
|
|
344
332
|
*
|
|
345
333
|
* @param array - The array to check.
|
|
346
334
|
* @returns The array if not empty, otherwise undefined.
|
|
347
335
|
*/
|
|
348
|
-
const arrayNotEmpty = (array) =>
|
|
336
|
+
const arrayNotEmpty = (array) => array && array.length > 0 ? array : undefined;
|
|
349
337
|
|
|
350
338
|
const align = {
|
|
351
339
|
LEFT: "left",
|
|
@@ -1077,4 +1065,4 @@ const isSorted = (sortInput) => {
|
|
|
1077
1065
|
return originalKeys.every((key, index) => key === sortedKeys[index]);
|
|
1078
1066
|
};
|
|
1079
1067
|
|
|
1080
|
-
export { DateTimeFormat, HoursAndMinutesFormat, align, alphabeticallySort, arrayLengthCompare, arrayNotEmpty, booleanCompare, capitalize, convertBlobToBase64, convertMetersToYards, convertYardsToMeters, dateCompare, deleteUndefinedKeys, difference, doNothing,
|
|
1068
|
+
export { DateTimeFormat, HoursAndMinutesFormat, align, alphabeticallySort, arrayLengthCompare, arrayNotEmpty, booleanCompare, capitalize, convertBlobToBase64, convertMetersToYards, convertYardsToMeters, dateCompare, deleteUndefinedKeys, difference, doNothing, enumFromValue, enumFromValueTypesafe, enumOrUndefinedFromValue, exhaustiveCheck, filterByMultiple, formatAddress, formatCoordinates, fuzzySearch, getDifferenceBetweenDates, getEndOfDay, getISOStringFromDate, getMultipleCoordinatesFromGeoJsonObject, getPointCoordinateFromGeoJsonObject, getResizedDimensions, getStartOfDay, groupBy, groupTinyDataToOthers, hourIntervals, intersection, isArrayEqual, isSorted, isUUID, isValidImage, nonNullable, numberCompare, numberCompareUnknownAfterHighest, objNotEmpty, objectEntries, objectFromEntries, objectKeys, objectValues, pick, removeLeftPadding, resizeBlob, resizeImage, size, stringCompare, stringCompareFromKey, stringNaturalCompare, titleCase, toID, toIDs, toUUID, trimIds, trimPath, truthy, unionArraysByKey };
|
package/package.json
CHANGED
package/src/arrayUtils.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/** toggle whether a value is in an array or not */
|
|
2
|
-
export declare function toggle<T>(array: T[] | null | undefined, value: T | null | undefined): T[];
|
|
3
|
-
/** Ensure the argument is an array, if not, create array with that element in it */
|
|
4
|
-
export declare function ensureArray<T>(arrayish: T | T[]): T[];
|
|
5
1
|
/**
|
|
6
2
|
* Returns a new array with the items from the previous array and the new array, but only if the item's key is unique.
|
|
7
3
|
*
|
|
@@ -10,13 +6,15 @@ export declare function ensureArray<T>(arrayish: T | T[]): T[];
|
|
|
10
6
|
* @param newArray The new array of items to merge with the previous array
|
|
11
7
|
* @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
8
|
*/
|
|
13
|
-
export declare const unionArraysByKey: <
|
|
14
|
-
/**
|
|
15
|
-
|
|
9
|
+
export declare const unionArraysByKey: <TObject extends object>(key: keyof TObject, previous: TObject[] | undefined | null, newArray: TObject[] | undefined | null) => TObject[];
|
|
10
|
+
/**
|
|
11
|
+
* Checks if two arrays are equal.
|
|
12
|
+
*/
|
|
13
|
+
export declare const isArrayEqual: <TItem extends string | number>(a: TItem[], b: TItem[]) => boolean;
|
|
16
14
|
/**
|
|
17
15
|
* Checks if an array is not empty.
|
|
18
16
|
*
|
|
19
17
|
* @param array - The array to check.
|
|
20
18
|
* @returns The array if not empty, otherwise undefined.
|
|
21
19
|
*/
|
|
22
|
-
export declare const arrayNotEmpty: <
|
|
20
|
+
export declare const arrayNotEmpty: <TItem>(array?: TItem[]) => TItem[] | undefined;
|