fixjson
Version:
JSON fixer for humans using (relaxed) JSON5
63 lines (59 loc) • 2.79 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const yargs = require("yargs");
const __1 = require("..");
const USAGE = `Usage: $0 [-w|-i|--minify|--stdin-filename] [paths...]
JSON fixer for Humans using (relaxed) JSON5. If no path is given, it reads from STDIN. Input should be a JSON5 string. Quotes for keys in objects can be ommitted. Trailing comma at the end of array or object is allowed. Number can be written in hex format (e.g. 0xff).
In addition, input JSON5 string can be relaxed. Missing commas are allowed in objects and arrays. String literals can contain newlines. Note that NaN and Infinity as number are not permitted.
If --indent (or -i) option is not given, indent level is automatically detected.
For more detail please visit https://github.com/rhysd/fixjson.`;
/* tslint:disable:no-console */
/* tslint:disable:no-floating-promises */
(() => __awaiter(void 0, void 0, void 0, function* () {
/* tslint:enable:no-floating-promises */
try {
const argv = yargs
.usage(USAGE)
.option('write', {
alias: 'w',
describe: 'overwrite a file instead of outputting to stdout',
type: 'boolean',
default: false,
})
.option('minify', {
describe: 'disable pretty print',
type: 'boolean',
default: false,
})
.option('indent', {
alias: 'i',
describe: 'indent of JSON output',
type: 'number',
default: undefined,
})
.option('stdin-filename', {
describe: 'assuming a file name when reading from stdin',
type: 'string',
default: undefined,
}).argv;
const numFormatted = yield new __1.default(argv).main(argv._);
if (argv._.length > 0 && argv.write) {
console.log('formatted', numFormatted, 'file(s)');
}
}
catch (e) {
console.error('Error:', e.message);
process.exit(1);
}
}))();
//# sourceMappingURL=main.js.map