@trackunit/shared-utils 0.0.65 → 0.0.67

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
@@ -639,6 +639,24 @@ const pick = (obj, ...keys) => {
639
639
  // eslint-disable-next-line local-rules/no-typescript-assertion
640
640
  {});
641
641
  };
642
+ /**
643
+ * Returns an object with only the differences between two input objects.
644
+ * Not recursive, only compares first level properties.
645
+ */
646
+ const getFirstLevelObjectPropertyDifferences = (obj1, obj2) => {
647
+ return objectEntries(obj1).reduce((diff, [key, value]) => {
648
+ // Check if the property exists in obj2.
649
+ if (key in obj2) {
650
+ const val = obj2[key];
651
+ // Check if obj1's property's value is different from obj2's.
652
+ if (val !== value) {
653
+ return Object.assign(Object.assign({}, diff), { [key]: val });
654
+ }
655
+ }
656
+ // Otherwise, just return the previous diff object.
657
+ return diff;
658
+ }, {});
659
+ };
642
660
 
643
661
  /**
644
662
  * @param path the path to manipulate
@@ -1107,6 +1125,7 @@ exports.formatCoordinates = formatCoordinates;
1107
1125
  exports.fuzzySearch = fuzzySearch;
1108
1126
  exports.getDifferenceBetweenDates = getDifferenceBetweenDates;
1109
1127
  exports.getEndOfDay = getEndOfDay;
1128
+ exports.getFirstLevelObjectPropertyDifferences = getFirstLevelObjectPropertyDifferences;
1110
1129
  exports.getISOStringFromDate = getISOStringFromDate;
1111
1130
  exports.getMultipleCoordinatesFromGeoJsonObject = getMultipleCoordinatesFromGeoJsonObject;
1112
1131
  exports.getPointCoordinateFromGeoJsonObject = getPointCoordinateFromGeoJsonObject;
package/index.esm.js CHANGED
@@ -635,6 +635,24 @@ const pick = (obj, ...keys) => {
635
635
  // eslint-disable-next-line local-rules/no-typescript-assertion
636
636
  {});
637
637
  };
638
+ /**
639
+ * Returns an object with only the differences between two input objects.
640
+ * Not recursive, only compares first level properties.
641
+ */
642
+ const getFirstLevelObjectPropertyDifferences = (obj1, obj2) => {
643
+ return objectEntries(obj1).reduce((diff, [key, value]) => {
644
+ // Check if the property exists in obj2.
645
+ if (key in obj2) {
646
+ const val = obj2[key];
647
+ // Check if obj1's property's value is different from obj2's.
648
+ if (val !== value) {
649
+ return Object.assign(Object.assign({}, diff), { [key]: val });
650
+ }
651
+ }
652
+ // Otherwise, just return the previous diff object.
653
+ return diff;
654
+ }, {});
655
+ };
638
656
 
639
657
  /**
640
658
  * @param path the path to manipulate
@@ -1079,4 +1097,4 @@ const isSorted = (sortInput) => {
1079
1097
  return originalKeys.every((key, index) => key === sortedKeys[index]);
1080
1098
  };
1081
1099
 
1082
- 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, stripHiddenCharacters, titleCase, toID, toIDs, toUUID, trimIds, trimPath, truthy, unionArraysByKey };
1100
+ 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, getFirstLevelObjectPropertyDifferences, 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, stripHiddenCharacters, titleCase, toID, toIDs, toUUID, trimIds, trimPath, truthy, unionArraysByKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/shared-utils",
3
- "version": "0.0.65",
3
+ "version": "0.0.67",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -17,3 +17,8 @@ export declare const objNotEmpty: <T extends object>(obj?: T) => T | undefined;
17
17
  * Picks the given keys from an object, typesafe.
18
18
  */
19
19
  export declare const pick: <T, K extends keyof T>(obj: T, ...keys: K[]) => Pick<T, K>;
20
+ /**
21
+ * Returns an object with only the differences between two input objects.
22
+ * Not recursive, only compares first level properties.
23
+ */
24
+ export declare const getFirstLevelObjectPropertyDifferences: <TObject extends Record<PropertyKey, unknown>>(obj1: TObject, obj2: TObject) => Partial<TObject>;