/** * WARNING: This function has some issues: * * 1. If you pass anything with `undefined` or `Infinity` or `NaN` then the * return value will probably be something you are not expecting * * 2. If you use this function with TypeScript then typing information will be * lost * * You should probably use structuredClone() instead because it does not have * the above issues. * * @example * const original = { a: 1, b: "foo", c: true, d: null, h: [1, "foo", true, null], i: { number: 1, string: "foo", boolean: true, null: null, array: [1, "foo", true, null] } }; * const clone = copy(original); */ export default function copy(a: any) { return JSON.parse(JSON.stringify(a)); }