@microsoft/fast-html 1.0.0-alpha.35 → 1.0.0-alpha.37

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.
@@ -173,12 +173,19 @@ export declare function getChildrenMap(previousString: string | null): ChildrenM
173
173
  * @returns True if the objects are deeply equal, false otherwise
174
174
  */
175
175
  export declare function deepEqual(obj1: any, obj2: any): boolean;
176
+ /**
177
+ * Checks if a value is a plain object (not an array, null, or other type).
178
+ *
179
+ * @param value - The value to check
180
+ * @returns True if the value is a plain object, false otherwise
181
+ */
182
+ export declare function isPlainObject(value: any): value is Record<string, any>;
176
183
  /**
177
184
  * Deeply merges the source object into the target object.
178
185
  *
179
186
  * @param target - The target object to merge into
180
187
  * @param source - The source object to merge from
181
- * @returns void
188
+ * @returns boolean indicating whether changes were made
182
189
  */
183
- export declare function deepMerge(target: any, source: any): void;
190
+ export declare function deepMerge(target: any, source: any): boolean;
184
191
  export {};
@@ -1092,15 +1092,25 @@ export function deepEqual(obj1, obj2) {
1092
1092
  }
1093
1093
  return true;
1094
1094
  }
1095
+ /**
1096
+ * Checks if a value is a plain object (not an array, null, or other type).
1097
+ *
1098
+ * @param value - The value to check
1099
+ * @returns True if the value is a plain object, false otherwise
1100
+ */
1101
+ export function isPlainObject(value) {
1102
+ return !!value && typeof value === "object" && !Array.isArray(value);
1103
+ }
1095
1104
  /**
1096
1105
  * Deeply merges the source object into the target object.
1097
1106
  *
1098
1107
  * @param target - The target object to merge into
1099
1108
  * @param source - The source object to merge from
1100
- * @returns void
1109
+ * @returns boolean indicating whether changes were made
1101
1110
  */
1102
1111
  export function deepMerge(target, source) {
1103
1112
  const hasOwn = Object.prototype.hasOwnProperty;
1113
+ let hasChanges = false;
1104
1114
  for (const key in source) {
1105
1115
  if (!hasOwn.call(source, key)) {
1106
1116
  continue;
@@ -1113,10 +1123,10 @@ export function deepMerge(target, source) {
1113
1123
  if (deepEqual(targetValue, sourceValue)) {
1114
1124
  continue;
1115
1125
  }
1116
- const isSourceArray = Array.isArray(sourceValue);
1117
- if (isSourceArray) {
1126
+ hasChanges = true;
1127
+ if (Array.isArray(sourceValue)) {
1118
1128
  const isTargetArray = Array.isArray(targetValue);
1119
- const clonedItems = sourceValue.map((item) => item && typeof item === "object" ? { ...item } : item);
1129
+ const clonedItems = sourceValue.map((item) => isPlainObject(item) ? { ...item } : item);
1120
1130
  if (isTargetArray) {
1121
1131
  // Use splice to maintain observable array tracking
1122
1132
  targetValue.splice(0, targetValue.length, ...clonedItems);
@@ -1127,15 +1137,20 @@ export function deepMerge(target, source) {
1127
1137
  }
1128
1138
  continue;
1129
1139
  }
1130
- if (sourceValue && typeof sourceValue === "object") {
1131
- if (!targetValue ||
1132
- typeof targetValue !== "object" ||
1133
- Array.isArray(targetValue)) {
1134
- target[key] = {};
1140
+ if (isPlainObject(sourceValue)) {
1141
+ const targetIsObject = isPlainObject(targetValue);
1142
+ const nextTarget = targetIsObject ? { ...targetValue } : {};
1143
+ const nestedChanged = deepMerge(nextTarget, sourceValue);
1144
+ if (!targetIsObject) {
1145
+ target[key] = nextTarget;
1146
+ continue;
1147
+ }
1148
+ if (nestedChanged) {
1149
+ target[key] = nextTarget;
1135
1150
  }
1136
- deepMerge(target[key], sourceValue);
1137
1151
  continue;
1138
1152
  }
1139
1153
  target[key] = sourceValue;
1140
1154
  }
1155
+ return hasChanges;
1141
1156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/fast-html",
3
- "version": "1.0.0-alpha.35",
3
+ "version": "1.0.0-alpha.37",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Microsoft",
@@ -58,15 +58,10 @@
58
58
  "./dist/esm/index.js"
59
59
  ],
60
60
  "peerDependencies": {
61
- "@microsoft/fast-element": "^2.8.5"
61
+ "@microsoft/fast-element": "^2.9.2"
62
62
  },
63
63
  "devDependencies": {
64
- "@ast-grep/cli": "^0.37.0",
65
- "@microsoft/api-extractor": "^7.47.0",
66
- "@microsoft/fast-element": "^2.8.5",
67
- "@types/express": "^4.17.21",
68
- "@types/node": "^17.0.17",
69
- "typescript": "~5.3.0"
64
+ "@microsoft/fast-element": "^2.9.2"
70
65
  },
71
66
  "beachball": {
72
67
  "disallowedChangeTypes": [