jason-formatter
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "jason-formatter", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "A Command Line tool to format JSON", | ||
@@ -30,6 +30,5 @@ "main": "src/index.js", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin": "^1.0.1", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"prettier": "^2.3.2", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"prettier-eslint": "^12.0.0", | ||
@@ -36,0 +35,0 @@ "prettier-plugin-jsdoc": "^0.3.23" |
# Jason | ||
A Command Line tformatter for JSON files, zero dependencies. | ||
A Command Line formatter for JSON files, zero dependencies. | ||
@@ -21,2 +21,8 @@ ![Cover](./assets/cover.png) | ||
By default 2 tabs are used, but you can also specify how many tabs you want: | ||
```bash | ||
jason config.json 4 | ||
``` | ||
You can also import it in your code: | ||
@@ -30,4 +36,6 @@ | ||
import { format } from 'jason-formatter'; | ||
console.log(format(rawData, { tabs: 2 })); | ||
``` | ||
You can see an example of use in [test/formatter.js](./tests/formater.js). |
@@ -7,12 +7,17 @@ const fs = require('fs').promises; | ||
*/ | ||
function format(text) { | ||
return JSON.stringify(JSON.parse(text), null, 4); | ||
function format(text, { tabs = 2 }) { | ||
return JSON.stringify(JSON.parse(text), null, tabs); | ||
} | ||
/** @param {string} file */ | ||
async function writeFile(file) { | ||
/** | ||
* @param {string} file | ||
* @param {Object} config Configuration options | ||
*/ | ||
async function writeFile(file, config) { | ||
if (!file) throw new Error('You have to pass a file!'); | ||
const raw = await fs.readFile(file, 'utf-8'); | ||
fs.writeFile(file, format(raw)).then(() => console.log('JSON Formated :)')); | ||
fs.writeFile(file, format(raw, config)).then(() => | ||
console.log('JSON Formated :)') | ||
); | ||
} | ||
@@ -22,3 +27,6 @@ | ||
function init() { | ||
writeFile(process.argv[2]); | ||
const config = { | ||
tabs: parseInt(process.argv[3], 10) || 2 | ||
}; | ||
writeFile(process.argv[2], config); | ||
} | ||
@@ -25,0 +33,0 @@ |
@@ -12,1 +12,2 @@ { | ||
} | ||
@@ -33,2 +33,2 @@ const { format } = require('../src/index'); | ||
// Nice :D | ||
console.log(format(rawData)); | ||
console.log(format(rawData, { tabs: 2 })); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29681
8
87
40