hd-utils
Version:
A handy utils for modern JS developers
24 lines (23 loc) • 613 B
TypeScript
/**
* @description will produce a new copy of the passed parameter, you can use it as a polyfill for structuredClone but mind the options.
* @author https://github.com/ungap/structured-clone
* @example `const cloned = deepClone(
{
method() {
// ignored, won't be cloned
},
special: Symbol('also ignored')
},
{
// avoid throwing
lossy: true,
// avoid throwing *and* looks for toJSON
json: true
}
);`
* @example deepClone({a:1}) => {a:1} //as new copy
*/
export default function deepClone<T = any>(value: T, options?: {
lossy?: boolean;
json?: boolean;
}): T;