Created
January 11, 2021 10:16
-
-
Save karthikax/d8e84b16c88dab2bfaf0dfca765c5c65 to your computer and use it in GitHub Desktop.
JSON file minify
This file contains 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
const fs = require('fs'); | |
const data = fs.readFileSync( process.argv[2], { encoding: 'utf8', flag: 'r' } ); | |
const min = JSON.parse(data, (key, value) => | |
typeof value === "number" ? Math.round(value * 100) / 100 : value | |
) | |
const minString = JSON.stringify( min ) | |
const name = process.argv[2].split( '.' ) | |
name.splice( -1, 0, 'min' ) | |
fs.writeFileSync( name.join( '.' ), minString ); | |
console.log( '\njson file with numbers minified successfully\n' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment