main: use deepCopy instead of JSON trick

This commit is contained in:
jean-emmanuel 2018-08-26 18:57:46 +02:00
parent 769b332436
commit 9eae6e3c91
2 changed files with 28 additions and 3 deletions

24
app/main/utils.js Normal file
View file

@ -0,0 +1,24 @@
module.exports = {
deepCopy: function(obj, precision) {
var copy = obj
if (obj === null) {
return obj
}
if (typeof obj === 'object') {
copy = Array.isArray(obj) ? [] : {}
for (let key in obj) {
copy[key] = module.exports.deepCopy(obj[key], precision)
}
} else if (typeof obj == 'number') {
return precision === undefined ? copy : parseFloat(copy.toFixed(precision))
}
return copy
}
}