New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-fix

Package Overview
Dependencies
Maintainers
4
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-fix - npm Package Compare versions

Comparing version 0.6.1 to 0.7.0

.prettierrc

38

index.js
#!/usr/bin/env node
var assert = require("assert");
var fs = require("fs");
var sortJson = require("good-sort-json");
var getStdin = require("get-stdin");
var jsonic = require("jsonic");
var program = require("commander");
var sortJson = require("good-sort-json");
var packagejson = require("./package.json");
var getStdin = require("get-stdin")
var inflect = require("inflect-json");
var allowedInflection = ["none", "pascalcase"];
program
.version(packagejson.version)
.option("-s, --spaces [amount]", "Number of spaces for indentation")
.option("-s, --spaces <amount>", "Number of spaces for indentation", parseInt)
.option("-i, --inflection <none|pascalcase>", "Inflection type, defaults to none")
.option("--no-sort", "Don't sort")
.usage("<file>")
.usage("[options] [file ...]")
.parse(process.argv);

@@ -19,6 +24,8 @@

if (spaces === undefined) {
spaces = "4";
spaces = 4;
}
var spaces = parseInt(spaces);
var spaces = spaces;
var sort = program.sort;
var inflection = program.inflection || allowedInflection[0];
assert([allowedInflection].indexOf(inflection), `Inflection ${inflection} not allowed`);

@@ -28,9 +35,11 @@ if (program.args.length) {

} else {
getStdin().then((src) => {
const result = parseString(src);
process.stdout.write(result);
}).catch((err) => {
console.err(err);
process.exit(1);
});
getStdin()
.then((src) => {
const result = parseString(src);
process.stdout.write(result);
})
.catch((err) => {
console.err(err);
process.exit(1);
});
}

@@ -46,2 +55,5 @@

var js = jsonic(str);
if (inflection === "pascalcase") {
js = inflect.pascalcase(js);
}
if (sort) {

@@ -48,0 +60,0 @@ return sortJson(js, { space: spaces }) + "\n";

{
"name": "json-fix",
"version": "0.6.1",
"version": "0.7.0",
"description": "",

@@ -27,5 +27,7 @@ "main": "index.js",

"dependencies": {
"assert": "^1.4.1",
"commander": "^2.12.2",
"get-stdin": "^6.0.0",
"good-sort-json": "^0.1.2",
"inflect-json": "^0.2.0",
"jsonic": "^0.3.0"

@@ -37,4 +39,5 @@ },

"mocha": "^5.0.4",
"node-cmd": "^3.0.0"
"node-cmd": "^3.0.0",
"prettier": "^1.11.1"
}
}

@@ -9,6 +9,16 @@ # json-fix

## Option spaces
## Options
You can specify spaces with `--spaces %number of spaces%`, it uses `4` as default
$ json-fix --help
Usage: index [options] [file ...]
Options:
-V, --version output the version number
-s, --spaces <amount> Number of spaces for indentation
-i, --inflection <none|pascalcase> Inflection type, defaults to none
--no-sort Don't sort
-h, --help output usage information
## Examples

@@ -15,0 +25,0 @@

@@ -9,3 +9,3 @@ const cmd = require("node-cmd");

describe("json-fix", function () {
describe("json-fix", function() {
const indexsrc = path.resolve(__dirname, "../index.js");

@@ -19,4 +19,4 @@ beforeEach(async function() {

it("should work with exapmle", async function() {
const testsrc = path.join(__dirname, "fixture/test.json");
const testjson = "{a:3,b:2}"
const testsrc = path.join(__dirname, "fixture/test.json");
const testjson = "{a:3,b:2}";
const command = `node ${indexsrc} ${testsrc}`;

@@ -34,3 +34,3 @@ const expected = `{

it("should work from stdin", async function() {
const testjson = "{a:3,b:2}"
const testjson = "{a:3,b:2}";
const command = `echo ${testjson} | node ${indexsrc}`;

@@ -43,5 +43,15 @@ const expected = `{

const result = await get(command);
console.log(result);
expect(result.toString()).to.be.eq(expected);
});
it("should work with inflection=pascalcase", async function() {
const testsrc = path.join(__dirname, "fixture/test.json");
await fs.writeFile(testsrc, "{a:3,b:2}");
await get(`node ${indexsrc} ${testsrc} --inflection pascalcase`);
const result = await fs.readFile(testsrc);
expect(result.toString()).to.be.eq(`{
"A": 3,
"B": 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