Created
January 29, 2018 20:21
-
-
Save ayamflow/944230a1fcffeb5b8850b96867f3257e to your computer and use it in GitHub Desktop.
Trim decimals for 3D JSON models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var argv = require('minimist')(process.argv.slice(2)); | |
let data = JSON.parse(fs.readFileSync('./' + argv.input, 'utf8')); | |
Object.keys(data).forEach(function(key) { | |
if (data[key] instanceof Array) { | |
data[key].forEach(function(value, i) { | |
data[key][i] = parseFloat(parseFloat(value).toFixed(3 || argv.cs)); | |
}); | |
} | |
}); | |
fs.writeFileSync('./' + argv.output, JSON.stringify(data), 'utf8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment