Skip to content

Commit

Permalink
merge, fix test, bump the version
Browse files Browse the repository at this point in the history
  • Loading branch information
kof committed Sep 28, 2015
2 parents ac622f3 + 4966c60 commit 4c39b0f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fs = require('fs'),
Path = require('path'),
jsonlint = require('jsonlint');
jph = require('json-parse-helpfulerror');

/**
* Default options.
Expand All @@ -16,8 +16,10 @@ exports.options = {
freeze: false,
// you can use any other extension for your config files, f.e. *.cjson
ext: '.json',
// you can use any parser, f.e. you could switch to JSON.parse for speed
parse: jsonlint.parse
// you can use any parser you want. the default uses JSON.parse for maximum
// speed, if it throws it uses uses an alternative parser to give more
// helpful errors
parse: jph.parse
}

/**
Expand Down
40 changes: 22 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
{
"name": "cjson",
"description": "cjson - Commented JavaScript Object Notation. It is a json loader, which parses only valid json files, but with comments enabled. Useful for loading configs.",
"version": "0.3.1",
"repository": "git://github.com/kof/node-cjson.git",
"keywords": [ "json", "parser", "comments", "config", "loader"],
"author": "Oleg Slobodskoi <oleg008@gmail.com>",
"engines": {
"node": ">= 0.3.0"
},
"dependencies": {
"jsonlint": "1.6.0"
},
"licenses": [
{
"type": "MIT",
"url" : "http://www.opensource.org/licenses/mit-license.php"
}
]
"name": "cjson",
"description": "cjson - Commented JavaScript Object Notation. It is a json loader, which parses only valid json files, but with comments enabled. Useful for loading configs.",
"version": "0.3.2",
"repository": "git://github.com/kof/node-cjson.git",
"keywords": [
"json",
"parser",
"comments",
"config",
"loader"
],
"author": "Oleg Slobodskoi <oleg008@gmail.com>",
"engines": {
"node": ">= 0.3.0"
},
"dependencies": {
"json-parse-helpfulerror": "^1.0.3"
},
"scripts": {
"test": "node ./test/test.js"
},
"license": "MIT"
}
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ Load config file from given path, array of paths or directory. Second parameter
freeze: false,
// you can use any other extension for your config files, f.e. .cjson
ext: '.json',
// you can use any parser, f.e. you could switch to JSON.parse for speed
parse: jsonlint.parse
// you can use any parser you want. the default uses JSON.parse for maximum
// speed, if it throws it uses uses an alternative parser to give more
// helpful errors
parse: jph.parse
}


Expand Down
10 changes: 5 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ a.deepEqual(cjson.parse(str), data.conf2, '.parse method with comments');
try {
cjson.load(fixtures + '/errors/invalid.cjson');
} catch (e) {
// Matching the line "Expecting ...."
var message = e.message.match(/^[^\^]*[^]\s(.*)\sFile:.*$/)[1];
// Message was errorneously appended with a quote.
// Taking the first line from the error message
var message = e.message.split('\n')[0];
// The error we expect is that the value ended with \n instead of quotes
a.equal(
message,
"Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'",
message.trim().toLowerCase(),
"unexpected token '}' at 2:17",
'Assert that the error message is properly formatted.'
);
}
Expand Down

0 comments on commit 4c39b0f

Please sign in to comment.