buxlabs/pure-utilities
The issue has been closed
make `deepclone` pure #90
emilos posted onGitHub
Context
In the README, we're stating that the methods are side effect free. Unfortunately it's not true in all of the cases yet.
function deepclone (object) {
return JSON.parse(JSON.stringify(object))
}
deepclone
fn would throw if you'd pass undefined
or when the parsed object has circular references.
Acceptance criteria
- ensure deepclone does not throw
- add more tests
We probably need to add a default:
function deepclone (object = {}) {}
and wrap the fn body with try catch. The simplest thing to do is probably just return an empty object if there's an exception.