diff options
author | Sam Potts <sam@potts.es> | 2018-11-11 11:05:09 +1100 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2018-11-11 11:05:09 +1100 |
commit | b7b2e3c0aa0749eed53ae91230082cb0482e1f28 (patch) | |
tree | f073bde14df6459419323dd6570b2549b8d26c41 /src/js/utils/objects.js | |
parent | 3e0a91141822758094b2cbd5f0ecdd8ce4142b5f (diff) | |
parent | 2c8a337f265f3f84133bc674f3836802588c0c13 (diff) | |
download | plyr-b7b2e3c0aa0749eed53ae91230082cb0482e1f28.tar.lz plyr-b7b2e3c0aa0749eed53ae91230082cb0482e1f28.tar.xz plyr-b7b2e3c0aa0749eed53ae91230082cb0482e1f28.zip |
Merge branch 'develop' into css-variables
# Conflicts:
# demo/dist/demo.css
# demo/dist/demo.js
# demo/dist/demo.js.map
# demo/dist/demo.min.js
# demo/dist/demo.min.js.map
# dist/plyr.css
# dist/plyr.js
# dist/plyr.js.map
# dist/plyr.min.js
# dist/plyr.min.js.map
# dist/plyr.polyfilled.js
# dist/plyr.polyfilled.js.map
# dist/plyr.polyfilled.min.js
# dist/plyr.polyfilled.min.js.map
# gulpfile.js
# src/sass/components/captions.scss
# src/sass/components/control.scss
Diffstat (limited to 'src/js/utils/objects.js')
-rw-r--r-- | src/js/utils/objects.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/js/utils/objects.js b/src/js/utils/objects.js new file mode 100644 index 00000000..225bb459 --- /dev/null +++ b/src/js/utils/objects.js @@ -0,0 +1,42 @@ +// ========================================================================== +// Object utils +// ========================================================================== + +import is from './is'; + +// Clone nested objects +export function cloneDeep(object) { + return JSON.parse(JSON.stringify(object)); +} + +// Get a nested value in an object +export function getDeep(object, path) { + return path.split('.').reduce((obj, key) => obj && obj[key], object); +} + +// Deep extend destination object with N more objects +export function extend(target = {}, ...sources) { + if (!sources.length) { + return target; + } + + const source = sources.shift(); + + if (!is.object(source)) { + return target; + } + + Object.keys(source).forEach(key => { + if (is.object(source[key])) { + if (!Object.keys(target).includes(key)) { + Object.assign(target, { [key]: {} }); + } + + extend(target[key], source[key]); + } else { + Object.assign(target, { [key]: source[key] }); + } + }); + + return extend(target, ...sources); +} |