rename precision to decimals, add typeTags, continue refactoring
This commit is contained in:
parent
f41ac14698
commit
a58075c602
54 changed files with 426 additions and 256 deletions
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = {
|
||||
|
||||
deepCopy: function(obj, precision) {
|
||||
deepCopy: function(obj, decimals) {
|
||||
|
||||
var copy = obj
|
||||
|
||||
|
|
@ -11,10 +11,10 @@ module.exports = {
|
|||
if (typeof obj === 'object') {
|
||||
copy = Array.isArray(obj) ? [] : {}
|
||||
for (let key in obj) {
|
||||
copy[key] = module.exports.deepCopy(obj[key], precision)
|
||||
copy[key] = module.exports.deepCopy(obj[key], decimals)
|
||||
}
|
||||
} else if (typeof obj == 'number') {
|
||||
return precision === undefined ? copy : parseFloat(copy.toFixed(precision))
|
||||
return decimals === undefined ? copy : parseFloat(copy.toFixed(decimals))
|
||||
}
|
||||
|
||||
return copy
|
||||
|
|
@ -34,6 +34,15 @@ module.exports = {
|
|||
return a === b
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
isJSON: function(str) {
|
||||
// heuristic to avoid using JSON when unnecessary
|
||||
// if the string doesn't starts with one of these chars
|
||||
// it's going to fail
|
||||
// ref in source: https://github.com/douglascrockford/JSON-js
|
||||
return ' \n+-eE{([0123456789tfn"'.indexOf(str[0]) !== -1
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue