forked from lxm_front/jsonlint-mod
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c42d2abffc | ||
|
|
ee5c2d557c | ||
|
|
2e869ca7ec | ||
|
|
833a75648f | ||
|
|
efd1ae6071 | ||
|
|
0653b731db | ||
|
|
5cca03512e | ||
|
|
4c65154163 | ||
|
|
c21e8eb8de | ||
|
|
6d09e77ef9 | ||
|
|
1956caa5a4 | ||
|
|
5a52ba4662 | ||
|
|
1ff64514b6 | ||
|
|
19fd9a63d2 | ||
|
|
36370390e0 |
4
Makefile
4
Makefile
@@ -6,6 +6,10 @@ build:
|
||||
mv jsonlint.js lib/jsonlint.js
|
||||
node scripts/bundle.js | uglifyjs > web/jsonlint.js
|
||||
|
||||
deploy:
|
||||
cp web/jsonlint.js ../jsonlint-pages/jsonlint.js
|
||||
cd ../jsolint-pages && git commit -a -m 'deploy site updates' && git push origin gh-pages
|
||||
|
||||
test: lib/jsonlint.js test/all-tests.js
|
||||
node test/all-tests.js
|
||||
|
||||
|
||||
12
README.md
12
README.md
@@ -1,7 +1,7 @@
|
||||
JSON Lint
|
||||
=========
|
||||
|
||||
A pure [JavaScript version](http://zaach.github.com/jsonlint/) of the service provided at [jsonlin.com](http://jsonlint.com).
|
||||
A pure [JavaScript version](http://zaach.github.com/jsonlint/) of the service provided at [jsonlint.com](http://jsonlint.com).
|
||||
|
||||
## Command line interface
|
||||
Install jsonlint with npm to use the command line interface:
|
||||
@@ -40,3 +40,13 @@ I'm not sure why you wouldn't use the built in `JSON.parse` but you can use json
|
||||
jsonlint.parse('{"creative?": false}');
|
||||
|
||||
It returns the parsed object or throws an `Error`.
|
||||
|
||||
## MIT License
|
||||
|
||||
Copyright (C) 2012 Zachary Carter
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
30
lib/cli.js
30
lib/cli.js
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var sys = require("sys");
|
||||
var fs = require("fs");
|
||||
var parser = require("./jsonlint").parser;
|
||||
var options = require("nomnom")
|
||||
@@ -11,6 +10,7 @@ var options = require("nomnom")
|
||||
help: "file to parse; otherwise uses stdin"
|
||||
},
|
||||
version: {
|
||||
flag : true,
|
||||
string: '-v, --version',
|
||||
help: 'print version and exit',
|
||||
callback: function() {
|
||||
@@ -18,30 +18,46 @@ var options = require("nomnom")
|
||||
}
|
||||
},
|
||||
sort : {
|
||||
flag : true,
|
||||
string: '-s, --sort-keys',
|
||||
help: 'sort object keys'
|
||||
},
|
||||
inplace : {
|
||||
flag : true,
|
||||
string: '-i, --in-place',
|
||||
help: 'overwrite the file'
|
||||
},
|
||||
indent : {
|
||||
string: '-t CHAR, --indent CHAR',
|
||||
default: " ",
|
||||
"default": " ",
|
||||
help: 'character(s) to use for indentation'
|
||||
},
|
||||
compact : {
|
||||
flag : true,
|
||||
string: '-c, --compact',
|
||||
help : 'compact error display'
|
||||
}
|
||||
})
|
||||
.parseArgs();
|
||||
|
||||
if (options.compact) {
|
||||
var fileName = options.file? options.file + ': ' : '';
|
||||
parser.parseError = parser.lexer.parseError = function(str, hash) {
|
||||
console.error(fileName + 'line '+ hash.loc.first_line +', col '+ hash.loc.last_column +', found: \''+ hash.token +'\' - expected: '+ hash.expected.join(', ') +'.');
|
||||
throw new Error(str);
|
||||
};
|
||||
}
|
||||
|
||||
function parse (source) {
|
||||
try {
|
||||
var parsed = options.sort ?
|
||||
sortObject(parser.parse(source)) :
|
||||
parser.parse(source);
|
||||
parser.parse(source);
|
||||
return JSON.stringify(parsed,null,options.indent);
|
||||
} catch (e) {
|
||||
sys.puts(e);
|
||||
if (! options.compact) {
|
||||
console.log(e);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -49,12 +65,12 @@ function parse (source) {
|
||||
function main (args) {
|
||||
var source = '';
|
||||
if (options.file) {
|
||||
var path = require('path').join(process.cwd(), options.file);
|
||||
var path = require('path').normalize(options.file);
|
||||
source = parse(fs.readFileSync(path, "utf8"));
|
||||
if (options.inplace) {
|
||||
fs.writeSync(fs.openSync(path,'w+'), source, 0, "utf8");
|
||||
} else {
|
||||
sys.puts(source);
|
||||
console.log(source);
|
||||
}
|
||||
} else {
|
||||
var stdin = process.openStdin();
|
||||
@@ -64,7 +80,7 @@ function main (args) {
|
||||
source += chunk.toString('utf8');
|
||||
});
|
||||
stdin.on('end', function () {
|
||||
sys.puts(parse(source));
|
||||
console.log(parse(source));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
11
package.json
11
package.json
@@ -8,7 +8,7 @@
|
||||
"lint",
|
||||
"jsonlint"
|
||||
],
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.2",
|
||||
"preferGlobal": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -22,10 +22,10 @@
|
||||
"jsonlint": "lib/cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "0.4 || 0.5"
|
||||
"node": ">= 0.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"nomnom": ">= 0.4.3"
|
||||
"nomnom": ">= 1.x.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "*",
|
||||
@@ -35,5 +35,6 @@
|
||||
"scripts": {
|
||||
"test": "node test/all-tests.js"
|
||||
},
|
||||
"homepage": "http://zaach.github.com/jsonlint/"
|
||||
}
|
||||
"homepage": "http://zaach.github.com/jsonlint/",
|
||||
"optionalDependencies": {}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
|
||||
/*
|
||||
ECMA-262 5th Edition, 15.12.1 The JSON Grammar.
|
||||
Modified to forbid top level primitives.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user