@microsoft/fast-html 1.0.0-alpha.35 → 1.0.0-alpha.36
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
|
|
188
|
+
* @returns boolean indicating whether changes were made
|
|
182
189
|
*/
|
|
183
|
-
export declare function deepMerge(target: any, source: any):
|
|
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
|
|
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
|
-
|
|
1117
|
-
if (
|
|
1126
|
+
hasChanges = true;
|
|
1127
|
+
if (Array.isArray(sourceValue)) {
|
|
1118
1128
|
const isTargetArray = Array.isArray(targetValue);
|
|
1119
|
-
const clonedItems = sourceValue.map((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
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
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
|
}
|