Dito.js is a declarative and modern web framework with a focus on API driven development, based on Objection.js, Koa.js and Vue.js – Developed at Lineto by Jürg Lehni and made available by Lineto in 2018 under the MIT license
function clone(val, iteratee = null) {
let copy
if (isDate(val)) {
copy = new val.constructor(+val)
} else if (isRegExp(val)) {
copy = new RegExp(val)
} else if (isObject(val)) {
copy = new val.constructor()
for (const key in val) {
copy[key] = clone(val[key], iteratee)
}
} else if (isArray(val)) {
copy = new val.constructor(val.length)
for (let i = 0, l = val.length; i < l; i++) {
copy[i] = clone(val[i], iteratee)
}
} else {
copy = val
}
return iteratee?.(copy) ?? copy
}
This should do the trick: