Merge branch 'master' into v1
This commit is contained in:
commit
6c9220d0ab
103 changed files with 94 additions and 59 deletions
39
src/client/utils.js
Normal file
39
src/client/utils.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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
|
||||
|
||||
},
|
||||
|
||||
deepEqual: function(a, b) {
|
||||
|
||||
var ta = typeof a,
|
||||
tb = typeof b
|
||||
|
||||
if (ta !== tb) {
|
||||
return false
|
||||
} else if (ta === 'object') {
|
||||
return JSON.stringify(a) === JSON.stringify(b)
|
||||
} else {
|
||||
return a === b
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue