-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
35 lines (30 loc) · 977 Bytes
/
utils.js
File metadata and controls
35 lines (30 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const isObject = (item) => item && typeof item === 'object' && !Array.isArray(item);
const deepMerge = (target, source) => {
let output = { ...target };
if (isObject(target) && isObject(source)) {
Object.keys(source).forEach(key => {
if (isObject(source[key])) {
if (!(key in target)) {
output[key] = source[key];
} else {
output[key] = deepMerge(target[key], source[key]);
}
} else {
output[key] = source[key];
}
});
}
return output;
};
// This function takes the collected results and applies the override data to produce the final data structure
const mergeResultsWithOverride = (results, override) => {
return results.map(spec => {
// Find the matching override by 'shortname'
const patch = override.find(o => o.shortname === spec.shortname);
if (patch) {
return deepMerge(spec, patch);
}
return spec;
});
}
export { mergeResultsWithOverride };