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

ask-json

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ask-json - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

52

dist/cli.js

@@ -14,3 +14,3 @@ #!/usr/bin/env node

var name = "ask-json";
var version = "0.1.0";
var version = "0.1.1";

@@ -24,4 +24,18 @@ var ensureFile = (filePath) => {

var readJSON = filePath => JSON.parse(fs.readFileSync(filePath));
class InvalidJSONError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);
}
}
var readJSON = filePath => {
try {
return JSON.parse(fs.readFileSync(filePath));
} catch (e) {
throw new InvalidJSONError(e.toString());
}
};
var writeJSON = (filePath, data) => fs.writeFileSync(filePath, JSON.stringify(data, null, 2));

@@ -55,26 +69,28 @@

.version();
}, async function(args) {
await runCLI(args);
})
.argv;
if (!fs.existsSync(argv.schema)) {
console.error(`\n⛔ Unable to read JSON schema file: ${chalk.green(argv.schema)}\n`);
process.exit(1);
}
const runCLI = async(args) => {
if (!fs.existsSync(args.schema)) {
console.error(`\n⛔ Unable to read JSON schema file: ${chalk.green(args.schema)}\n`);
process.exit(1);
}
const SCHEMA = readJSON(argv.schema);
let VALID_DATA;
const SCHEMA = readJSON(args.schema);
let VALID_DATA;
const run = async() => {
if (!argv.file) {
if (!args.file) {
VALID_DATA = await askJSON(SCHEMA, {});
} else {
ensureFile(argv.file);
const RAW_DATA = readJSON(argv.RAW_DATA);
ensureFile(args.file);
const RAW_DATA = readJSON(args.RAW_DATA);
VALID_DATA = await askJSON(SCHEMA, RAW_DATA);
}
if (argv.output) {
ensureFile(argv.output);
writeJSON(argv.output, VALID_DATA);
} else if (argv.file) {
writeJSON(argv.file, VALID_DATA);
if (args.output) {
ensureFile(args.output);
writeJSON(args.output, VALID_DATA);
} else if (args.file) {
writeJSON(args.file, VALID_DATA);
} else {

@@ -85,3 +101,1 @@ process.stdout.write(JSON.stringify(VALID_DATA, null, 2));

};
run();
{
"name": "ask-json",
"description": "Easy interactive prompts to create and validate data using JSON schema",
"version": "0.1.0",
"version": "0.1.1",
"author": "Jon McClure <jon.r.mcclure@gmail.com>",

@@ -6,0 +6,0 @@ "homepage": "https://github.com/reuters-graphics/ask-json",

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