(defaults: object, incoming: object)
| 51 | * @param incoming loaded config |
| 52 | */ |
| 53 | export const mergeConfig = (defaults: object, incoming: object) => { |
| 54 | const overwrite: object = mapValues(defaults, (value, key) => { |
| 55 | if (isPlainObject(value)) { |
| 56 | return mergeConfig(value, get(incoming, key)) |
| 57 | } |
| 58 | |
| 59 | const incomingValue = get(incoming, key) |
| 60 | |
| 61 | return [isNumber, isArray, isString, isBoolean].some( |
| 62 | (test) => test(value) !== test(incomingValue), |
| 63 | ) |
| 64 | ? value |
| 65 | : incomingValue |
| 66 | }) |
| 67 | |
| 68 | return isPlainObject(incoming) ? { ...incoming, ...overwrite } : overwrite |
| 69 | } |
no test coverage detected