deepCopy: missing file
This commit is contained in:
parent
6f325b08ee
commit
f2a1104f17
1 changed files with 24 additions and 0 deletions
24
src/browser/js/app/utils.js
Normal file
24
src/browser/js/app/utils.js
Normal 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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue