UNPKG

@playkit-js/playkit-js-ui

Version:

[![Build Status](https://github.com/kaltura/playkit-js-ui/actions/workflows/run_canary_full_flow.yaml/badge.svg)](https://github.com/kaltura/playkit-js-ui/actions/workflows/run_canary_full_flow.yaml) [![code style: prettier](https://img.shields.io/badge/c

28 lines (26 loc) 700 B
/** * @param {any} data - The data to copy. * @returns {any} - The copied data. */ function copyDeep(data: any): any { let node; if (Array.isArray(data)) { node = data.length > 0 ? data.slice(0) : []; node.forEach((e, i) => { if (typeof e === 'object' || (Array.isArray(e) && e.length > 0)) { node[i] = copyDeep(e); } }); } else if (typeof data === 'object') { node = Object.assign({}, data); Object.keys(node).forEach(key => { if (typeof node[key] === 'object' || (Array.isArray(node[key]) && node[key].length > 0)) { node[key] = copyDeep(node[key]); } }); } else { node = data; } return node; } export {copyDeep};