UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

28 lines (27 loc) 800 B
export const cloneDeep = (obj) => { if (typeof obj !== 'object' || obj === null) { return obj; } if (obj instanceof Date) { return new Date(obj.getTime()); } if (obj instanceof Array) { return obj.map(cloneDeep); } if (obj instanceof Set) { return new Set([...obj.values()].map(cloneDeep)); } if (obj instanceof Uint8Array) { return Uint8Array.from(obj); } if (obj instanceof Object) { return Object.fromEntries([ ...Object.entries(obj).map(([key, value]) => [key, cloneDeep(value)]), ...Object.getOwnPropertySymbols(obj).map(symbol => [ symbol, cloneDeep(obj[symbol]) ]) ]); } throw new Error('Unable to clone object'); };