Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jason-formatter

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jason-formatter - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

5

package.json
{
"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"

10

README.md
# 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 }));
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc