Skip to main content
Module

x/denodash/src/lang/cloneDeep.ts

A utility library, similar to Underscore and Lodash, but written Typescript-First, designed for use in Deno
Go to Latest
File
const cloneDeep = (value: any): any | never => { const typeofValue = typeof value; // primatives are copied by value. if ( [ "string", "number", "boolean", "string", "bigint", "symbol", "null", "undefined", "function", ].includes(typeofValue) ) { return value; } if (Array.isArray(value)) { return value.map(cloneDeep); } if (typeofValue === "object") { const clone: any = {}; for (let prop in value) { clone[prop] = cloneDeep(value[prop]); } return clone; } throw new Error(`You've tried to clone something that can't be cloned`);};
export default cloneDeep;