Comparing version 1.1.1 to 1.1.2
66
cli.js
#!/usr/bin/env node | ||
'use strict'; | ||
var pkg = require('./package.json'); | ||
var jlint = require('./'); | ||
var argv = process.argv.slice(2); | ||
const jlint = require('./'); | ||
const meow = require('meow'); | ||
var symbols = require("log-symbols"); | ||
var cardinal = require('cardinal'); | ||
const symbols = require('log-symbols'); | ||
const cardinal = require('cardinal'); | ||
function help() { | ||
console.log([ | ||
'', | ||
' ' + pkg.description, | ||
'', | ||
' Example', | ||
' jlint', | ||
'', | ||
' ✔' | ||
].join('\n')); | ||
} | ||
const cli = meow(` | ||
Usage | ||
$ jlint | ||
if (argv.indexOf('--help') !== -1) { | ||
help(); | ||
return; | ||
} | ||
Options | ||
-s, --silent Don't output json | ||
if (argv.indexOf('--version') !== -1) { | ||
console.log(pkg.version); | ||
return; | ||
} | ||
function outputJson (lint) { | ||
if (argv.indexOf('--silent') === -1) { | ||
if (lint.parsed) { | ||
console.log(cardinal.highlight(lint.content, {json: true})); | ||
} else { | ||
console.log(lint.content); | ||
} | ||
Examples | ||
$ jlint --silent | ||
✔ | ||
`, { | ||
alias: { | ||
s: 'silent' | ||
} | ||
} | ||
}); | ||
jlint(function (lint) { | ||
outputJson(lint); | ||
jlint((error, json) => { | ||
if (error) { | ||
console.log(error.message); | ||
console.log(symbols.error); | ||
if (lint.parsed) { | ||
console.log(symbols.success); | ||
} else { | ||
console.log(symbols.error, lint.exception); | ||
return; | ||
} | ||
process.exit(0); | ||
if (!cli.flags.silent) { | ||
console.log(cardinal.highlight(JSON.stringify(json, null, 2), {json: true})); | ||
} | ||
console.log(symbols.success); | ||
}); |
77
index.js
'use strict'; | ||
var copypaste = require("copy-paste"); | ||
var Promise = require('es6-promise').Promise; | ||
const parseJson = require('parse-json'); | ||
const copypaste = require('copy-paste'); | ||
const cardinal = require('cardinal'); | ||
var lint = { | ||
parsed: void 0, | ||
content: void 0, | ||
exception: void 0 | ||
}; | ||
let parse = (content, cb) => { | ||
try { | ||
let json = parseJson(content); | ||
var parse = function (content) { | ||
try { | ||
lint.parsed = true; | ||
lint.content = JSON.stringify(JSON.parse(content), null, 2); | ||
} catch(ex) { | ||
lint.content = content; | ||
lint.parsed = false; | ||
lint.exception = ex; | ||
cb(null, json); | ||
} catch (e) { | ||
cb(e); | ||
} | ||
return lint; | ||
}; | ||
var promise; | ||
let promise = new Promise((resolve, reject) => { | ||
if (process.stdin && !process.stdin.isTTY) { | ||
var data = ''; | ||
if (process.stdin && !process.stdin.isTTY) { | ||
promise = new Promise(function (resolve) { | ||
var stdinData = ''; | ||
process.stdin.on('data', (chunk) => { | ||
chunk = chunk.toString(); | ||
process.stdin.on('data', function(data) { | ||
var chunk = data.toString(); | ||
if (chunk !== null) { | ||
stdinData += chunk; | ||
data += chunk; | ||
} | ||
}); | ||
process.stdin.on('end', function () { | ||
resolve(stdinData); | ||
process.stdin.on('error', (err) => { | ||
reject(err); | ||
}); | ||
}) | ||
} | ||
module.exports = function(callback){ | ||
if (process.stdin && !process.stdin.isTTY) { | ||
promise.then(function (stdinData) { | ||
callback(parse(stdinData)); | ||
process.stdin.on('end', () => { | ||
resolve(data); | ||
}); | ||
return; | ||
} | ||
}); | ||
copypaste.paste(function (err, content) { | ||
if (err) { | ||
console.log(err); | ||
module.exports = (callback) => { | ||
if (process.stdin && !process.stdin.isTTY) { | ||
promise.then((content) => parse(content, callback)).catch(err => callback(err)); | ||
} else { | ||
copypaste.paste((err, content) => { | ||
if (err) { | ||
throw err; | ||
} | ||
lint.parsed = false; | ||
callback(lint); | ||
} | ||
var parsed = parse(content); | ||
callback(lint, parsed); | ||
}); | ||
parse(content, callback); | ||
}); | ||
} | ||
}; |
{ | ||
"name": "jlint", | ||
"version": "1.1.1", | ||
"description": "CLI that parses the current JSON you have in your current clipboard", | ||
"version": "1.1.2", | ||
"description": "cli that parses the current JSON you have in your current clipboard", | ||
"main": "index.js", | ||
@@ -42,5 +42,6 @@ "scripts": { | ||
"cardinal": "0.5.0", | ||
"copy-paste": "1.1.2", | ||
"es6-promise": "2.3.0", | ||
"log-symbols": "1.0.2" | ||
"copy-paste": "1.1.3", | ||
"log-symbols": "1.0.2", | ||
"meow": "3.4.2", | ||
"parse-json": "2.2.0" | ||
}, | ||
@@ -47,0 +48,0 @@ "devDependencies": { |
@@ -1,10 +0,9 @@ | ||
# jlint [![Build Status](http://img.shields.io/travis/srn/jlint.svg?style=flat-square)](https://travis-ci.org/srn/jlint) [![Dependency Status](http://img.shields.io/gemnasium/srn/jlint.svg?style=flat-square)](https://gemnasium.com/srn/jlint) | ||
# jlint [![Build Status](http://img.shields.io/travis/srn/jlint.svg?style=flat-square)](https://travis-ci.org/srn/jlint) | ||
> cli that parses the JSON you have in your current clipboard | ||
> CLI that parses the current JSON you have in your current clipboard. | ||
## Install | ||
```sh | ||
$ npm install --global jlint | ||
$ npm i -g jlint | ||
``` | ||
@@ -20,3 +19,2 @@ | ||
✔︎ | ||
{ | ||
@@ -26,5 +24,6 @@ "hello": 1, | ||
} | ||
✔︎ | ||
``` | ||
Piping: | ||
Piping also works: | ||
@@ -31,0 +30,0 @@ ```sh |
4108
5
71
35
+ Addedmeow@3.4.2
+ Addedparse-json@2.2.0
+ Addedarray-find-index@1.0.2(transitive)
+ Addedcamelcase@1.2.1(transitive)
+ Addedcamelcase-keys@1.0.0(transitive)
+ Addedcopy-paste@1.1.3(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@2.1.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedmap-obj@1.0.1(transitive)
+ Addedmeow@3.4.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedredent@1.0.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.21(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedstrip-indent@1.0.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtrim-newlines@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
- Removedes6-promise@2.3.0
- Removedcopy-paste@1.1.2(transitive)
- Removedes6-promise@2.3.0(transitive)
Updatedcopy-paste@1.1.3