pax_global_header00006660000000000000000000000064124521207430014512gustar00rootroot0000000000000052 comment=eedb116ec96b5c479be3919b526d6de0a521be5e json-parse-helpfulerror-1.0.3/000077500000000000000000000000001245212074300163035ustar00rootroot00000000000000json-parse-helpfulerror-1.0.3/.editorconfig000066400000000000000000000003271245212074300207620ustar00rootroot00000000000000root = true [*] end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [*.js, **/*.js] indent_size = 4 indent_style = space [{package.json,.travis.yml}] indent_size = 2 indent_style = space json-parse-helpfulerror-1.0.3/.gitignore000066400000000000000000000011131245212074300202670ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript json-parse-helpfulerror-1.0.3/LICENSE000066400000000000000000000020651245212074300173130ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Sam Mikes 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. json-parse-helpfulerror-1.0.3/README.md000066400000000000000000000010331245212074300175570ustar00rootroot00000000000000# json-parse-helpfulerror A drop-in replacement for `JSON.parse` that uses to provide more useful error messages in the event of a parse error. # Example ## Installation ``` npm i -S json-parse-helpfulerror ``` ## Use ```js var jph = require('json-parse-helpfulerror'); var notJSON = "{'foo': 3}"; // keys must be double-quoted in JSON JSON.parse(notJSON); // throws unhelpful error jph.parse("{'foo': 3}") // throws more helpful error: "Unexpected token '\''..." ``` # License MITjson-parse-helpfulerror-1.0.3/index.js000066400000000000000000000007611245212074300177540ustar00rootroot00000000000000'use strict'; var jju = require('jju'); function parse(text, reviver) { try { return JSON.parse(text, reviver); } catch (err) { // we expect this to throw with a more informative message jju.parse(text, { mode: 'json', reviver: reviver }); // backup if jju is not as strict as JSON.parse; re-throw error // data-dependent code path, I do not know how to cover it throw err; } } exports.parse = parse; json-parse-helpfulerror-1.0.3/package.json000066400000000000000000000014751245212074300206000ustar00rootroot00000000000000{ "name": "json-parse-helpfulerror", "version": "1.0.3", "description": "A drop-in replacement for JSON.parse that uses `jju` to give helpful errors", "main": "index.js", "scripts": { "test": "lab -c", "lint": "jslint --edition=latest --terse *.js" }, "repository": { "type": "git", "url": "https://github.com/smikes/json-parse-helpfulerror.git" }, "keywords": [ "json", "parse", "line", "doublequote", "error" ], "author": "Sam Mikes ", "license": "MIT", "bugs": { "url": "https://github.com/smikes/json-parse-helpfulerror/issues" }, "homepage": "https://github.com/smikes/json-parse-helpfulerror", "devDependencies": { "code": "^1.2.1", "jslint": "^0.7.1", "lab": "^5.1.1" }, "dependencies": { "jju": "^1.1.0" } } json-parse-helpfulerror-1.0.3/test/000077500000000000000000000000001245212074300172625ustar00rootroot00000000000000json-parse-helpfulerror-1.0.3/test/test.js000066400000000000000000000014331245212074300206000ustar00rootroot00000000000000var Code = require('code'), Lab = require('lab'), lab = Lab.script(), jph = require('..'); // 'json-parse-helpfulerror' exports.lab = lab; lab.test('can parse', function (done) { var o = jph.parse('{"foo": "bar"}'); Code.expect(o.foo).to.equal('bar'); done(); }); lab.test('helpful error for bad JSON', function (done) { var bad = "{'foo': 'bar'}"; Code.expect(function () { JSON.parse(bad) }).to.throw(); Code.expect(function () { jph.parse(bad) }).to.throw(SyntaxError, "Unexpected token '\\'' at 1:2\n" + bad + '\n ^'); done(); }); lab.test('fails if reviver throws', function (done) { function badReviver() { throw new ReferenceError('silly'); } Code.expect(function () { jph.parse('3', badReviver) }).to.throw(ReferenceError, 'silly'); done(); });