diff options
| author | Raphael Kabo <raphaelkabo@hey.com> | 2024-02-26 12:09:46 +0000 | 
|---|---|---|
| committer | Raphael Kabo <raphaelkabo@hey.com> | 2024-02-26 12:09:46 +0000 | 
| commit | c93fd6e2d455ea4208f9e5ca6bfbd1c0e9fd1ad9 (patch) | |
| tree | 8baed2c232b629a98b21006adf440f6f83d5da57 /src/util | |
| parent | 363cfbae076f4494ddd5fddcf03de622f6247051 (diff) | |
refactor: allow Cypress to override config
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/object.ts | 30 | 
1 files changed, 30 insertions, 0 deletions
diff --git a/src/util/object.ts b/src/util/object.ts new file mode 100644 index 0000000..1ecc89b --- /dev/null +++ b/src/util/object.ts @@ -0,0 +1,30 @@ +/** + * Simple object check. + */ +export function isObject(item: any) { +    return item && typeof item === "object" && !Array.isArray(item); +} + +/** + * Deep merge two objects. + */ +export function deepMerge<T>( +    target: Record<any, any>, +    ...sources: Record<any, any>[] +): T { +    if (!sources.length) return target; +    const source = sources.shift(); + +    if (isObject(target) && isObject(source)) { +        for (const key in source) { +            if (isObject(source[key])) { +                if (!target[key]) Object.assign(target, { [key]: {} }); +                deepMerge(target[key], source[key]); +            } else { +                Object.assign(target, { [key]: source[key] }); +            } +        } +    } + +    return deepMerge(target, ...sources) as T; +}  | 
