From 75c33ac9cadcaa9ccb82ed0773986242fd60d5ba Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:39 +0800 Subject: [PATCH 01/30] add unsafe mode (Step: 1) Step: 1 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- .editorconfig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..48a48b8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +# http://editorconfig.org +root = true + +[*] +charset = utf-8 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.js] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[{package.json,*.yml,.*rc}] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true From 4cc7250568b407ced641577f3cc919c5bf682c6f Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:40 +0800 Subject: [PATCH 02/30] add unsafe mode (Step: 2) Step: 2 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- test/file/unsafe_array.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/file/unsafe_array.json diff --git a/test/file/unsafe_array.json b/test/file/unsafe_array.json new file mode 100644 index 0000000..fbf6d3b --- /dev/null +++ b/test/file/unsafe_array.json @@ -0,0 +1,18 @@ +/** + blah + */ +// comment at top +{ + // comment for a + /* block comment */ + "a": 1, // comment at right + + + + "ignore": [ + "node_modules", + "dist", + ], + +} +// comment at bottom From bf33cbf5d0556ec140f413df495f818088f8f04e Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:41 +0800 Subject: [PATCH 03/30] add unsafe mode (Step: 3) Step: 3 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- test/file/unsafe_array.json.dist | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/file/unsafe_array.json.dist diff --git a/test/file/unsafe_array.json.dist b/test/file/unsafe_array.json.dist new file mode 100644 index 0000000..843a78e --- /dev/null +++ b/test/file/unsafe_array.json.dist @@ -0,0 +1,7 @@ +{ + "a": 1, + "ignore": [ + "node_modules", + "dist" + ] +} \ No newline at end of file From 4639bce142ed8eb1152764c1b990fee2619795df Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:42 +0800 Subject: [PATCH 04/30] add unsafe mode (Step: 4) Step: 4 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- test/file/unsafe_json.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/file/unsafe_json.json diff --git a/test/file/unsafe_json.json b/test/file/unsafe_json.json new file mode 100644 index 0000000..0fe6bd9 --- /dev/null +++ b/test/file/unsafe_json.json @@ -0,0 +1,22 @@ +/** + blah + */ +// comment at top +{ + // comment for a + /* block comment */ + "a": 1, // comment at right + + "development": { + "retainLines": true, + "sourceMaps": true, + "auxiliaryCommentAfter": true + }, + + "ignore": [ + "node_modules", + "dist", + ], + +} +// comment at bottom From 024e1286e936346cce73ab69a211efd52c87e0bc Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:42 +0800 Subject: [PATCH 05/30] add unsafe mode (Step: 5) Step: 5 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- test/file/unsafe_json.json.dist | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/file/unsafe_json.json.dist diff --git a/test/file/unsafe_json.json.dist b/test/file/unsafe_json.json.dist new file mode 100644 index 0000000..5349b15 --- /dev/null +++ b/test/file/unsafe_json.json.dist @@ -0,0 +1,12 @@ +{ + "a": 1, + "development": { + "retainLines": true, + "sourceMaps": true, + "auxiliaryCommentAfter": true + }, + "ignore": [ + "node_modules", + "dist" + ] +} \ No newline at end of file From e48e5128f24c92859672da3607b716803e49d8a6 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:43 +0800 Subject: [PATCH 06/30] add unsafe mode (Step: 6) Step: 6 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- test/file/unsafe_object.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/file/unsafe_object.json diff --git a/test/file/unsafe_object.json b/test/file/unsafe_object.json new file mode 100644 index 0000000..bc9908c --- /dev/null +++ b/test/file/unsafe_object.json @@ -0,0 +1,19 @@ +/** + blah + */ +// comment at top +{ + // comment for a + /* block comment */ + "a": 1, // comment at right + + "development": { + "retainLines": true, + "sourceMaps": true, + "auxiliaryCommentAfter": true, + }, + + + +} +// comment at bottom From e53fc1055c5eb331bfcad31a921f2853afb8dea9 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:44 +0800 Subject: [PATCH 07/30] add unsafe mode (Step: 7) Step: 7 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- test/file/unsafe_object.json.dist | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/file/unsafe_object.json.dist diff --git a/test/file/unsafe_object.json.dist b/test/file/unsafe_object.json.dist new file mode 100644 index 0000000..ae05692 --- /dev/null +++ b/test/file/unsafe_object.json.dist @@ -0,0 +1,8 @@ +{ + "a": 1, + "development": { + "retainLines": true, + "sourceMaps": true, + "auxiliaryCommentAfter": true + } +} \ No newline at end of file From 138842a1957d13e526da24db836a84bd9c960371 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:45 +0800 Subject: [PATCH 08/30] add unsafe mode (Step: 8) Step: 8 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- test/unsafe_json.js | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/unsafe_json.js diff --git a/test/unsafe_json.js b/test/unsafe_json.js new file mode 100644 index 0000000..62e4e09 --- /dev/null +++ b/test/unsafe_json.js @@ -0,0 +1,49 @@ +/** + * Created by user on 2017/1/17. + */ + +'use strict'; + +var expect = require('chai').expect; +var parser = require('../') + +const fs = require('fs'); + +const options = { + unsafe: true, + debug: true, + }; + +const dir = "./test/file/"; + +describe("parse(unsafe)", function () + { + let list = fs.readdirSync(dir) + +//let file = 'unsafe_object.json'; + + list.forEach(function (file) + { + if (file.match(/^unsafe_.+\.json$/)) + { + it(file, function (done) + { + let j = parser.parse(fs.readFileSync(dir + file).toString(), null, true, options); + let d = JSON.parse(fs.readFileSync(dir + file + '.dist').toString()); + + let o = JSON.stringify(j, null, "\t"); + + fs.writeFileSync(dir + '/../temp/' + file, o) + + expect(JSON.parse(o)).to.deep.equal(d); + + done() + } + ) + } + } + ) + + } +) + From 11cb3b758df9017a123f06af50ea7acda5b5ba0e Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:45 +0800 Subject: [PATCH 09/30] add unsafe mode (Step: 9) Step: 9 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- index.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 14f71e4..f52260d 100644 --- a/index.js +++ b/index.js @@ -38,11 +38,19 @@ var index; var reviver; var remove_comments; -function parse (code, rev, no_comments) { +let options = { + debug: false, + unsafe: false, +}; + +function parse (code, rev, no_comments, opt) { tokens = tokenize(code); reviver = rev; remove_comments = no_comments; + options = Object.assign({}, opt); + options.unsafe = !!options.unsafe; + if (!tokens.length) { unexpected_end(); } @@ -100,7 +108,6 @@ function walk () { next(); return JSON.parse(negative + value); } - unexpected(); } @@ -118,11 +125,11 @@ function expect (a) { function unexpected () { - throw new SyntaxError('Unexpected token ' + current.value.slice(0, 1)); + throw new JsonSyntaxError('Unexpected token ' + current.value.slice(0, 1) + ' in JSON at position ' + current.loc.start.column); } function unexpected_end () { - throw new SyntaxError('Unexpected end of input'); + throw new JsonSyntaxError('Unexpected end of JSON input'); } @@ -136,6 +143,12 @@ function parse_object () { expect(','); next(); } + + if (started && options.unsafe && is('}') && is(',', -1)) + { + break; + } + started = true; expect('String'); name = JSON.parse(current.value); @@ -148,6 +161,7 @@ function parse_object () { obj[name] = transform(name, walk()); } next(); + return obj; } @@ -161,6 +175,12 @@ function parse_array () { expect(','); next(); } + + if (started && options.unsafe && is(']') && is(',', -1)) + { + break; + } + started = true; array[i] = transform(i, walk()); i ++; @@ -170,7 +190,16 @@ function parse_array () { } -function type () { +function type (offset) { + if (offset) + { + let a = tokens[index + offset] + + return (a && a.type === 'Punctuator' + ? a.value + : a.type) || void(0); + } + if (!current) { unexpected_end(); } @@ -181,8 +210,8 @@ function type () { } -function is (t) { - return type() === t; +function is (t, offset) { + return type(offset) === t; } @@ -209,7 +238,7 @@ function sort_comment_tokens () { // Whether there are comments left. return !!comment; } - + var head_comments = []; var foot_comments = []; @@ -262,7 +291,7 @@ function sort_comment_tokens () { function left (a, b) { - return a + return a && ( a.loc.start.line < b.loc.start.line || @@ -273,7 +302,7 @@ function left (a, b) { function right (a, b) { - return a + return a && a.loc.start.line === b.loc.start.line && a.loc.start.column > b.loc.start.column; } @@ -284,3 +313,19 @@ function comment_content (comment) { ? '/*' + comment.value + '*/' : '//' + comment.value; } + +class JsonSyntaxError extends SyntaxError { + constructor(message) { + super(message); + + if (options.debug) + { + this.message += "\n\n" + JSON.stringify({ + index: index, + current: current, + prev: tokens[index-1], + next: tokens[index+1] + }, null, "\t") + } + } +} From 0c711aec8b62667a71a5882e734e23a8eac74da6 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 20:42:46 +0800 Subject: [PATCH 10/30] add unsafe mode (Step: 10) Step: 10 [A ] new file: .editorconfig test/file/unsafe_array.json test/file/unsafe_array.json.dist test/file/unsafe_json.json test/file/unsafe_json.json.dist test/file/unsafe_object.json test/file/unsafe_object.json.dist test/unsafe_json.js [ M] modified - Changes not staged for commit: index.js package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d6a0256..63e3aeb 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "JSON parser to parse JSON object and MAINTAIN comments.", "main": "index.js", "scripts": { - "test": "./node_modules/.bin/mocha --reporter spec ./test/*.js" + "test": "mocha --reporter spec ./test" }, "repository": { "type": "git", From 5ba1e3ae869f7e56213d36c60e2e1095bfba23ff Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 21:39:54 +0800 Subject: [PATCH 11/30] support single-quoted 'ig"n\"o\'r\'e' = "ig\"n\"o'r'e", 'ignore' = "ignore" (Step: 1) Step: 1 [A ] new file: test/file/unsafe_quoted.json test/file/unsafe_quoted.json.dist test/file/unsafe_quoted2.json test/file/unsafe_quoted2.json.dist [ M] modified - Changes not staged for commit: index.js test/unsafe_json.js --- test/file/unsafe_quoted.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/file/unsafe_quoted.json diff --git a/test/file/unsafe_quoted.json b/test/file/unsafe_quoted.json new file mode 100644 index 0000000..213e705 --- /dev/null +++ b/test/file/unsafe_quoted.json @@ -0,0 +1,21 @@ +/** + blah + */ +// comment at top +{ + // comment for a + /* block comment */ + "a": 1, // comment at right + + 'ig"n\"ore': [ + "node_m'odules", + "dist", + ], + + 'ignore': [ + "node_modules", + "dist", + ], + +} +// comment at bottom From 8131b42caca0a6c69b8a7db1caa954577093dfbc Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 21:39:55 +0800 Subject: [PATCH 12/30] support single-quoted 'ig"n\"o\'r\'e' = "ig\"n\"o'r'e", 'ignore' = "ignore" (Step: 2) Step: 2 [A ] new file: test/file/unsafe_quoted.json test/file/unsafe_quoted.json.dist test/file/unsafe_quoted2.json test/file/unsafe_quoted2.json.dist [ M] modified - Changes not staged for commit: index.js test/unsafe_json.js --- test/file/unsafe_quoted.json.dist | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/file/unsafe_quoted.json.dist diff --git a/test/file/unsafe_quoted.json.dist b/test/file/unsafe_quoted.json.dist new file mode 100644 index 0000000..65351b8 --- /dev/null +++ b/test/file/unsafe_quoted.json.dist @@ -0,0 +1,11 @@ +{ + "a": 1, + "ig\"n\"ore": [ + "node_m'odules", + "dist" + ], + "ignore": [ + "node_modules", + "dist" + ] +} \ No newline at end of file From 6374f7e009854174fc3c7422be5fa6115e98a11e Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 21:39:56 +0800 Subject: [PATCH 13/30] support single-quoted 'ig"n\"o\'r\'e' = "ig\"n\"o'r'e", 'ignore' = "ignore" (Step: 3) Step: 3 [A ] new file: test/file/unsafe_quoted.json test/file/unsafe_quoted.json.dist test/file/unsafe_quoted2.json test/file/unsafe_quoted2.json.dist [ M] modified - Changes not staged for commit: index.js test/unsafe_json.js --- test/file/unsafe_quoted2.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/file/unsafe_quoted2.json diff --git a/test/file/unsafe_quoted2.json b/test/file/unsafe_quoted2.json new file mode 100644 index 0000000..afc4f27 --- /dev/null +++ b/test/file/unsafe_quoted2.json @@ -0,0 +1,21 @@ +/** + blah + */ +// comment at top +{ + // comment for a + /* block comment */ + "a": 1, // comment at right + + 'ig"n\"o\'r\'e': [ + "node_m'odules", + "dist", + ], + + 'ignore': [ + "node_modules", + "dist", + ], + +} +// comment at bottom From cb5dc507ecb33d30a5bbd3e7c26e0769c1cfb6bc Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 21:39:57 +0800 Subject: [PATCH 14/30] support single-quoted 'ig"n\"o\'r\'e' = "ig\"n\"o'r'e", 'ignore' = "ignore" (Step: 4) Step: 4 [A ] new file: test/file/unsafe_quoted.json test/file/unsafe_quoted.json.dist test/file/unsafe_quoted2.json test/file/unsafe_quoted2.json.dist [ M] modified - Changes not staged for commit: index.js test/unsafe_json.js --- test/file/unsafe_quoted2.json.dist | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/file/unsafe_quoted2.json.dist diff --git a/test/file/unsafe_quoted2.json.dist b/test/file/unsafe_quoted2.json.dist new file mode 100644 index 0000000..6173d1d --- /dev/null +++ b/test/file/unsafe_quoted2.json.dist @@ -0,0 +1,11 @@ +{ + "a": 1, + "ig\"n\"o'r'e": [ + "node_m'odules", + "dist" + ], + "ignore": [ + "node_modules", + "dist" + ] +} \ No newline at end of file From e814dcc5137baf471deca64f66c682ea3f00ca48 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 21:39:58 +0800 Subject: [PATCH 15/30] support single-quoted 'ig"n\"o\'r\'e' = "ig\"n\"o'r'e", 'ignore' = "ignore" (Step: 5) Step: 5 [A ] new file: test/file/unsafe_quoted.json test/file/unsafe_quoted.json.dist test/file/unsafe_quoted2.json test/file/unsafe_quoted2.json.dist [ M] modified - Changes not staged for commit: index.js test/unsafe_json.js --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f52260d..4bb0bf9 100644 --- a/index.js +++ b/index.js @@ -132,6 +132,15 @@ function unexpected_end () { throw new JsonSyntaxError('Unexpected end of JSON input'); } +function unsafe_quoted(str) +{ + return str.replace(/^'(.*)'$/, function($0, $1) + { + let s = '"' + $1.replace(/\\?(")/g, "\\$1").replace(/\\(')/g, "$1") + '"'; + console.log(str, '=', s); + return s; + }) +} function parse_object () { var obj = {}; @@ -151,7 +160,7 @@ function parse_object () { started = true; expect('String'); - name = JSON.parse(current.value); + name = JSON.parse(options.unsafe ? unsafe_quoted(current.value) : current.value); if (current.comments && !remove_comments) { obj['// ' + name] = current.comments; } From b0442b07b4011d089fe9aa1734d41e097eb8d188 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 21:39:59 +0800 Subject: [PATCH 16/30] support single-quoted 'ig"n\"o\'r\'e' = "ig\"n\"o'r'e", 'ignore' = "ignore" (Step: 6) Step: 6 [A ] new file: test/file/unsafe_quoted.json test/file/unsafe_quoted.json.dist test/file/unsafe_quoted2.json test/file/unsafe_quoted2.json.dist [ M] modified - Changes not staged for commit: index.js test/unsafe_json.js --- test/unsafe_json.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/unsafe_json.js b/test/unsafe_json.js index 62e4e09..51eedd5 100644 --- a/test/unsafe_json.js +++ b/test/unsafe_json.js @@ -29,11 +29,18 @@ describe("parse(unsafe)", function () it(file, function (done) { let j = parser.parse(fs.readFileSync(dir + file).toString(), null, true, options); - let d = JSON.parse(fs.readFileSync(dir + file + '.dist').toString()); + let d = ''; + + try + { + d = JSON.parse(fs.readFileSync(dir + file + '.dist').toString()); + } + catch (e) + {} let o = JSON.stringify(j, null, "\t"); - fs.writeFileSync(dir + '/../temp/' + file, o) + fs.writeFileSync(dir + '/../temp/' + file + '.dist', o) expect(JSON.parse(o)).to.deep.equal(d); From dcb75b06f8ca93cb1368f70afce33f1efe6c2826 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 21:49:59 +0800 Subject: [PATCH 17/30] . (Step: 1) Step: 1 [ M] modified - Changes not staged for commit: index.js test/file/unsafe_quoted2.json --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4bb0bf9..844c9ba 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,7 @@ function walk () { case 'Numeric': var value = current.value; next(); - return JSON.parse(negative + value); + return JSON.parse((options.unsafe && tt == 'String') ? unsafe_quoted(negative + value) : negative + value); } unexpected(); } From 5abdb85acbb7db7381b43002816f03a7d1222b94 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 21:50:00 +0800 Subject: [PATCH 18/30] . (Step: 2) Step: 2 [ M] modified - Changes not staged for commit: index.js test/file/unsafe_quoted2.json --- test/file/unsafe_quoted2.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/file/unsafe_quoted2.json b/test/file/unsafe_quoted2.json index afc4f27..1065efa 100644 --- a/test/file/unsafe_quoted2.json +++ b/test/file/unsafe_quoted2.json @@ -9,7 +9,7 @@ 'ig"n\"o\'r\'e': [ "node_m'odules", - "dist", + 'dist', ], 'ignore': [ From f497e0f0a24b7681f7ec8ba0ebd3634e34be222b Mon Sep 17 00:00:00 2001 From: bluelovers Date: Tue, 17 Jan 2017 21:51:25 +0800 Subject: [PATCH 19/30] . --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 844c9ba..5640ad3 100644 --- a/index.js +++ b/index.js @@ -137,7 +137,7 @@ function unsafe_quoted(str) return str.replace(/^'(.*)'$/, function($0, $1) { let s = '"' + $1.replace(/\\?(")/g, "\\$1").replace(/\\(')/g, "$1") + '"'; - console.log(str, '=', s); + //console.log(str, '=', s); return s; }) } From 6020ed4406e40a105800da0e8b155b90a85c9785 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Wed, 18 Jan 2017 14:42:49 +0800 Subject: [PATCH 20/30] . --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 63e3aeb..aaa2bb0 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "JSON parser to parse JSON object and MAINTAIN comments.", "main": "index.js", "scripts": { - "test": "mocha --reporter spec ./test" + "test": "mocha" }, "repository": { "type": "git", From 5974f8cb7897a5d9a7dc942b1c8675bdca1cf388 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:36:58 +0800 Subject: [PATCH 21/30] . (Step: 1) Step: 1 [ R] renamed - Changes not staged for commit: test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js [A ] new file: src/index.js src/tokenize.js test/benchmark.perf.js test/temp/.gitkeep [ M] modified - Changes not staged for commit: .editorconfig .gitignore index.js package.json --- test/{json-parser.js => json-parser.test.js} | 2 +- test/{unsafe_json.js => unsafe_json.test.js} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename test/{json-parser.js => json-parser.test.js} (98%) rename test/{unsafe_json.js => unsafe_json.test.js} (96%) diff --git a/test/json-parser.js b/test/json-parser.test.js similarity index 98% rename from test/json-parser.js rename to test/json-parser.test.js index b7db424..1b92885 100644 --- a/test/json-parser.js +++ b/test/json-parser.test.js @@ -1,7 +1,7 @@ 'use strict'; var expect = require('chai').expect; -var parser = require('../'); +var parser = require('../src'); // var a = parser.parse('//top\n{// top a\n/* abc */"a":1,//right\n/* bcd */"b":{"a":1}}//bottom'); // // var a = parser.parse('{/*top*/"a":1,//right\n/*abc*/"b":{"a":1}}'); diff --git a/test/unsafe_json.js b/test/unsafe_json.test.js similarity index 96% rename from test/unsafe_json.js rename to test/unsafe_json.test.js index 51eedd5..4869e60 100644 --- a/test/unsafe_json.js +++ b/test/unsafe_json.test.js @@ -5,7 +5,7 @@ 'use strict'; var expect = require('chai').expect; -var parser = require('../') +var parser = require('../src') const fs = require('fs'); From b71754077fa96789c326e17b49aaed79a721340a Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:36:59 +0800 Subject: [PATCH 22/30] . (Step: 2) Step: 2 [ R] renamed - Changes not staged for commit: test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js [A ] new file: src/index.js src/tokenize.js test/benchmark.perf.js test/temp/.gitkeep [ M] modified - Changes not staged for commit: .editorconfig .gitignore index.js package.json --- src/index.js | 397 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 397 insertions(+) create mode 100644 src/index.js diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..95c2339 --- /dev/null +++ b/src/index.js @@ -0,0 +1,397 @@ +/** + * Created by user on 2017/1/18. + */ + +const tokenize = exports.tokenize = require('./tokenize').tokenize; + +const parse = exports.parse = function parse (code, ...args) +{ + let tokens; + let current; + let index; + + let options = {}; + + if (args.length && typeof args[args.length-1] == 'object') + { + options = args.pop(); + } + + if (args.length) + { + let [reviver, remove_comments] = args; + + if (typeof options.reviver == 'undefined') + { + options.reviver = reviver; + } + + if (typeof options.remove_comments == 'undefined') + { + options.remove_comments = remove_comments; + } + } + + options = Object.assign({}, parse.defaultOptions, options); + + let transform = options.reviver ? transform1 : transform2; + + return _parse(code, options) + + function _parse(code, options) + { + tokens = tokenize(code); + + if (!tokens.length) + { + unexpected_end(); + } + + if (sort_comment_tokens() === false && !options.reviver && options.unsafe !== true) + { + return JSON.parse(code) + } + + index = -1; + next(); + + var result = walk(); + + if (Object(result) === result && !options.remove_comments) + { + if (tokens.head_comments.length) + { + result['//^'] = tokens.head_comments; + } + + if (tokens.foot_comments.length) + { + result['//$'] = tokens.foot_comments; + } + } + + result = transform('', result); +// options.reviver = null; + return result; + } + + function transform1(k, v) + { + return options.reviver + ? options.reviver(k, v) + : v; + } + + function transform2(k, v) + { + return v; + } + + function walk() + { + var tt = type(); + var negative = ''; + if (tt === '-') + { + next(); + tt = type(); + negative = '-'; + } + switch (tt) + { + case '{': + next(); + return parse_object(); + case '[': + next(); + return parse_array(); + case 'String': + case 'Boolean': + case 'Null': + case 'Numeric': + var value = current.value; + next(); + return JSON.parse((options.unsafe && tt == 'String') + ? unsafe_quoted(negative + value) + : negative + value + ); + } + unexpected(); + } + + function next() + { + return current = tokens[++index]; + } + + function expect(a) + { + if (!is(a)) + { + unexpected(); + } + } + + function unexpected_debug() + { + if (options.debug) + { + this.message += "\n\n" + JSON.stringify({ + index: index, + current: current, + prev: tokens[index - 1], + next: tokens[index + 1] + }, null, "\t" + ) + } + } + + function unexpected() + { + throw new JsonSyntaxError('Unexpected token ' + current.value.slice(0, 1) + ' in JSON at position ' + current.loc.start.column, unexpected_debug); + } + + function unexpected_end() + { + throw new JsonRangeError('Unexpected end of JSON input', unexpected_debug); + } + + function unsafe_quoted(str) + { + if (str.indexOf('\'') !== 0) return str; + + return str.replace(/^'(.*)'$/, function ($0, $1) + { + let s = '"' + $1.replace(/\\?(")/g, "\\$1").replace(/\\(')/g, "$1") + '"'; + //console.log(str, '=', s); + return s; + } + ) + } + + function parse_object() + { + var obj = {}; + var comment; + var started; + var name; + while (!is('}')) + { + if (started) + { + expect(','); + next(); + + if (options.unsafe && is('}')) + { + break; + } + } + + started = true; + expect('String'); + name = JSON.parse(options.unsafe ? unsafe_quoted(current.value) : current.value); + if (current.comments && !options.remove_comments) + { + obj['// ' + name] = current.comments; + } + next(); + expect(':'); + next(); + obj[name] = transform(name, walk()); + } + next(); + + return obj; + } + + function parse_array() + { + var array = []; + var started; + var i = 0; + while (!is(']')) + { + if (started) + { + expect(','); + next(); + + if (options.unsafe && is(']')) + { + break; + } + } + + started = true; + array[i] = transform(i, walk()); + i++; + } + next(); + return array; + } + + function type() + { + if (!current) + { + unexpected_end(); + } + + return current.type === 'Punctuator' + ? current.value + : current.type; + } + + function is(t) + { + return type() === t; + } + + function sort_comment_tokens() + { + var ts = tokens; + var comments = ts.comments; + if (!comments) + { + return false; + } + + function compare_to_then_push(condition, to, setup) + { + var comment; + var first = true; + var host; + while ((comment = comments[ci++]) && condition(comment, to)) + { + if (first) + { + host = setup(); + } + first = false; + host.push(comment_content(comment)); + } + + ci--; + // Whether there are comments left. + return !!comment; + } + + var head_comments = []; + var foot_comments = []; + + var first = ts[0]; + var ci = 0; + var comment = compare_to_then_push(left, first, function () + { + return head_comments; + } + ); + + var i = 0; + var token; + var next; + for (; i < ts.length; i++) + { + if (!comment) + { + break; + } + + token = ts[i]; + next = ts[i + 1]; + + if (token.type === 'String' && next && next.value === ':') + { + comment = compare_to_then_push(left, token, function () + { + token.comments || (token.comments = []); + return token.comments[0] || (token.comments[0] = []); + } + ); + + if (!comment) + { + break; + } + + comment = compare_to_then_push(right, token, function () + { + token.comments || (token.comments = []); + return token.comments[1] || (token.comments[1] = []); + } + ); + } + } + + compare_to_then_push(function () + { + return true + }, null, function () + { + return foot_comments; + } + ); + + comments.length = 0; + delete ts.comments; + + tokens.head_comments = head_comments; + tokens.foot_comments = foot_comments; + } + + function left(a, b) + { + return a + && ( + a.loc.start.line < b.loc.start.line + || + a.loc.start.line === b.loc.start.line + && a.loc.start.column < b.loc.start.column + ); + } + + function right(a, b) + { + return a + && a.loc.start.line === b.loc.start.line + && a.loc.start.column > b.loc.start.column; + } + + function comment_content(comment) + { + return comment.type === 'Block' + ? '/*' + comment.value + '*/' + : '//' + comment.value; + } + +} + +parse.defaultOptions = { + //debug: false, + unsafe: false, +}; + +class JsonSyntaxError extends SyntaxError { + constructor(message, callback) + { + super(message); + + if (typeof callback == "function") + { + callback.call(this) + } + } +} + +class JsonRangeError extends RangeError { + constructor(message, callback) + { + super(message); + + if (typeof callback == "function") + { + callback.call(this) + } + } +} From 4d42e65c11879352a1c8d50b694d7d77ac5f7a32 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:36:59 +0800 Subject: [PATCH 23/30] . (Step: 3) Step: 3 [ R] renamed - Changes not staged for commit: test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js [A ] new file: src/index.js src/tokenize.js test/benchmark.perf.js test/temp/.gitkeep [ M] modified - Changes not staged for commit: .editorconfig .gitignore index.js package.json --- src/tokenize.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/tokenize.js diff --git a/src/tokenize.js b/src/tokenize.js new file mode 100644 index 0000000..88233d2 --- /dev/null +++ b/src/tokenize.js @@ -0,0 +1,41 @@ +/** + * Created by user on 2017/1/18. + */ + +const esprima = require('esprima'); + +exports.tokenize = function tokenize(code) +{ + var list = esprima.tokenize(code, { + comment: true, + loc: true + } + ); + if (list.comment) + { + return list; + } + + var result = []; + var comments = []; + list.map(function (t) + { + if (t.type === 'LineComment') + { + t.type = 'Line'; + comments.push(t); + } + else if (t.type === 'BlockComment') + { + t.type = 'Block'; + comments.push(t); + } + else + { + result.push(t); + } + } + ); + result.comments = comments; + return result; +} From 11da80b0edae4a52d2eacc73633a3d73dee3943f Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:37:00 +0800 Subject: [PATCH 24/30] . (Step: 4) Step: 4 [ R] renamed - Changes not staged for commit: test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js [A ] new file: src/index.js src/tokenize.js test/benchmark.perf.js test/temp/.gitkeep [ M] modified - Changes not staged for commit: .editorconfig .gitignore index.js package.json --- test/benchmark.perf.js | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/benchmark.perf.js diff --git a/test/benchmark.perf.js b/test/benchmark.perf.js new file mode 100644 index 0000000..a4708b3 --- /dev/null +++ b/test/benchmark.perf.js @@ -0,0 +1,53 @@ +/** + * Created by user on 2017/1/18. + */ + +const myjson = require('../src'); + +var perf = require('mocha-benchmark').create({ + Benchmark: require('benchmark'), + versions: [ + /* order can be important when we introduce test failing options */ + ['JSON', (JSON.__name = 'JSON', JSON)], + //['old', require('../')], + ['new', (myjson.__name = 'json-parser', myjson)] + ], + /* could be describe */ +// suite: describe, +// /* or it */ +// test: it, +}); + +// perf.suite only runs the last version (usually your latest) +perf.suite('libGlobal', function(perf, libGlobal) { + + const fs = require('fs'); + const str = fs.readFileSync("./test/file/" + "unsafe_json.json.dist").toString() + + const options = { + unsafe: true, + debug: true, + }; + +// let p = require('../') + +// console.log(p.parse(str, options.reviver, options.remove_comments, options)) + +// perf.test('my lib should be fast', function() { +// //libGlobal.doStuff(); +// +// p.parse(str, options.reviver, options.remove_comments, options); +// +// }); + + // all tests inside compare run for each version + perf.compare(function(perf, libGlobal) { + + perf.test(libGlobal.__name, function() { + // libGlobal will be previous then latest + + libGlobal.parse(str, options.reviver, options.remove_comments, options); + + }); + }); +}); From 64f4cd831feecd5cb8a961f096b62026bb338335 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:37:01 +0800 Subject: [PATCH 25/30] . (Step: 5) Step: 5 [ R] renamed - Changes not staged for commit: test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js [A ] new file: src/index.js src/tokenize.js test/benchmark.perf.js test/temp/.gitkeep [ M] modified - Changes not staged for commit: .editorconfig .gitignore index.js package.json --- .editorconfig | 2 -- 1 file changed, 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 48a48b8..a118421 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,8 +9,6 @@ trim_trailing_whitespace = true trim_trailing_whitespace = false [*.js] -indent_style = space -indent_size = 2 trim_trailing_whitespace = true [{package.json,*.yml,.*rc}] From a4360cf327b45797003e28138fd87274beb37eb3 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:37:01 +0800 Subject: [PATCH 26/30] . (Step: 6) Step: 6 [ R] renamed - Changes not staged for commit: test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js [A ] new file: src/index.js src/tokenize.js test/benchmark.perf.js test/temp/.gitkeep [ M] modified - Changes not staged for commit: .editorconfig .gitignore index.js package.json --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f59aca0..4043a53 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ temp/ tmp/ +/test/temp/* +!/test/temp/.gitkeep +.idea From 85a285442744975437e76f1c0f9655a22efbc362 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:37:02 +0800 Subject: [PATCH 27/30] . (Step: 7) Step: 7 [ R] renamed - Changes not staged for commit: test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js [A ] new file: src/index.js src/tokenize.js test/benchmark.perf.js test/temp/.gitkeep [ M] modified - Changes not staged for commit: .editorconfig .gitignore index.js package.json --- index.js | 342 +------------------------------------------------------ 1 file changed, 4 insertions(+), 338 deletions(-) diff --git a/index.js b/index.js index 5640ad3..4f94775 100644 --- a/index.js +++ b/index.js @@ -1,340 +1,6 @@ 'use strict'; -var esprima = require('esprima'); - -exports.tokenize = tokenize; -exports.parse = parse; - - -function tokenize (code) { - var list = esprima.tokenize(code, { - comment: true, - loc: true - }); - if (list.comment) { - return list; - } - - var result = []; - var comments = []; - list.map(function (t) { - if (t.type === 'LineComment') { - t.type = 'Line'; - comments.push(t); - } else if (t.type === 'BlockComment') { - t.type = 'Block'; - comments.push(t); - } else { - result.push(t); - } - }); - result.comments = comments; - return result; -} - -var tokens; -var current; -var index; -var reviver; -var remove_comments; - -let options = { - debug: false, - unsafe: false, -}; - -function parse (code, rev, no_comments, opt) { - tokens = tokenize(code); - reviver = rev; - remove_comments = no_comments; - - options = Object.assign({}, opt); - options.unsafe = !!options.unsafe; - - if (!tokens.length) { - unexpected_end(); - } - - sort_comment_tokens(); - - index = -1; - next(); - - var result = walk(); - - if (Object(result) === result && !remove_comments) { - if (tokens.head_comments.length) { - result['//^'] = tokens.head_comments; - } - - if (tokens.foot_comments.length) { - result['//$'] = tokens.foot_comments; - } - } - - result = transform('', result); - reviver = null; - return result; -} - - -function transform (k, v) { - return reviver - ? reviver(k, v) - : v; -} - - -function walk () { - var tt = type(); - var negative = ''; - if (tt === '-') { - next(); - tt = type(); - negative = '-'; - } - switch (tt) { - case '{': - next(); - return parse_object(); - case '[': - next(); - return parse_array(); - case 'String': - case 'Boolean': - case 'Null': - case 'Numeric': - var value = current.value; - next(); - return JSON.parse((options.unsafe && tt == 'String') ? unsafe_quoted(negative + value) : negative + value); - } - unexpected(); -} - - -function next () { - return current = tokens[++ index]; -} - - -function expect (a) { - if (!is(a)) { - unexpected(); - } -} - - -function unexpected () { - throw new JsonSyntaxError('Unexpected token ' + current.value.slice(0, 1) + ' in JSON at position ' + current.loc.start.column); -} - -function unexpected_end () { - throw new JsonSyntaxError('Unexpected end of JSON input'); -} - -function unsafe_quoted(str) -{ - return str.replace(/^'(.*)'$/, function($0, $1) - { - let s = '"' + $1.replace(/\\?(")/g, "\\$1").replace(/\\(')/g, "$1") + '"'; - //console.log(str, '=', s); - return s; - }) -} - -function parse_object () { - var obj = {}; - var comment; - var started; - var name; - while (!is('}')){ - if (started) { - expect(','); - next(); - } - - if (started && options.unsafe && is('}') && is(',', -1)) - { - break; - } - - started = true; - expect('String'); - name = JSON.parse(options.unsafe ? unsafe_quoted(current.value) : current.value); - if (current.comments && !remove_comments) { - obj['// ' + name] = current.comments; - } - next(); - expect(':'); - next(); - obj[name] = transform(name, walk()); - } - next(); - - return obj; -} - - -function parse_array () { - var array = []; - var started; - var i = 0; - while(!is(']')){ - if (started) { - expect(','); - next(); - } - - if (started && options.unsafe && is(']') && is(',', -1)) - { - break; - } - - started = true; - array[i] = transform(i, walk()); - i ++; - } - next(); - return array; -} - - -function type (offset) { - if (offset) - { - let a = tokens[index + offset] - - return (a && a.type === 'Punctuator' - ? a.value - : a.type) || void(0); - } - - if (!current) { - unexpected_end(); - } - - return current.type === 'Punctuator' - ? current.value - : current.type; -} - - -function is (t, offset) { - return type(offset) === t; -} - - -function sort_comment_tokens () { - var ts = tokens; - var comments = ts.comments; - if (!comments) { - return; - } - - function compare_to_then_push (condition, to, setup) { - var comment; - var first = true; - var host; - while((comment = comments[ci ++]) && condition(comment, to)){ - if (first) { - host = setup(); - } - first = false; - host.push(comment_content(comment)); - } - - ci --; - // Whether there are comments left. - return !!comment; - } - - var head_comments = []; - var foot_comments = []; - - var first = ts[0]; - var ci = 0; - var comment = compare_to_then_push(left, first, function () { - return head_comments; - }); - - var i = 0; - var token; - var next; - for (; i < ts.length; i ++) { - if (!comment) { - break; - } - - token = ts[i]; - next = ts[i + 1]; - - if (token.type === 'String' && next && next.value === ':') { - comment = compare_to_then_push(left, token, function () { - token.comments || (token.comments = []); - return token.comments[0] || (token.comments[0] = []); - }); - - if (!comment) { - break; - } - - comment = compare_to_then_push(right, token, function () { - token.comments || (token.comments = []); - return token.comments[1] || (token.comments[1] = []); - }); - } - } - - compare_to_then_push(function () { - return true - }, null, function () { - return foot_comments; - }); - - comments.length = 0; - delete ts.comments; - - tokens.head_comments = head_comments; - tokens.foot_comments = foot_comments; -} - - -function left (a, b) { - return a - && ( - a.loc.start.line < b.loc.start.line - || - a.loc.start.line === b.loc.start.line - && a.loc.start.column < b.loc.start.column - ); -} - - -function right (a, b) { - return a - && a.loc.start.line === b.loc.start.line - && a.loc.start.column > b.loc.start.column; -} - - -function comment_content (comment) { - return comment.type === 'Block' - ? '/*' + comment.value + '*/' - : '//' + comment.value; -} - -class JsonSyntaxError extends SyntaxError { - constructor(message) { - super(message); - - if (options.debug) - { - this.message += "\n\n" + JSON.stringify({ - index: index, - current: current, - prev: tokens[index-1], - next: tokens[index+1] - }, null, "\t") - } - } -} +Object.assign(module.exports, { + tokenize: require('./src/tokenize').tokenize, + parse: require('./src/index').parse, +}); From caf0f88ac220d9c52d31cd46dde68f5dc61580a5 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:37:02 +0800 Subject: [PATCH 28/30] . (Step: 8) Step: 8 [ R] renamed - Changes not staged for commit: test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js test/json-parser.js -> test/json-parser.test.js test/unsafe_json.js -> test/unsafe_json.test.js [A ] new file: src/index.js src/tokenize.js test/benchmark.perf.js test/temp/.gitkeep [ M] modified - Changes not staged for commit: .editorconfig .gitignore index.js package.json --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index aaa2bb0..f9afbe5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "json-parser", - "version": "1.1.5", + "name": "json-parser2", + "version": "2.1.5", "description": "JSON parser to parse JSON object and MAINTAIN comments.", "main": "index.js", "scripts": { @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/kaelzhang/node-json-parser.git" + "url": "git://github.com/bluelovers/node-json-parser.git" }, "keywords": [ "json-parser", @@ -26,7 +26,7 @@ "author": "kaelzhang", "license": "MIT", "bugs": { - "url": "https://github.com/kaelzhang/node-json-parser/issues" + "url": "https://github.com/bluelovers/node-json-parser/issues" }, "devDependencies": { "mocha": "*", From b1a336b677404a342804f6282d30ec832515d593 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:41:10 +0800 Subject: [PATCH 29/30] . --- .editorconfig | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/.editorconfig b/.editorconfig index a118421..967c29f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,17 +1,15 @@ -# http://editorconfig.org -root = true - [*] -charset = utf-8 -trim_trailing_whitespace = true +charset=utf-8 +end_of_line=lf +insert_final_newline=true +indent_style=tab +tab_width=4 -[*.md] -trim_trailing_whitespace = false +[{.babelrc,.stylelintrc,.eslintrc,*.bowerrc,*.jsb3,*.jsb2,*.json}] +indent_style=space +indent_size=2 -[*.js] -trim_trailing_whitespace = true +[{*.yml,*.yaml}] +indent_style=space +indent_size=2 -[{package.json,*.yml,.*rc}] -indent_style = space -indent_size = 2 -trim_trailing_whitespace = true From f540ce352925035faea6652330aa1de7b7367af4 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 9 Mar 2017 21:47:28 +0800 Subject: [PATCH 30/30] . --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7cd1f7b..e290a7d 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,21 @@ -[![NPM version](https://badge.fury.io/js/json-parser.svg)](http://badge.fury.io/js/json-parser) -[![Build Status](https://travis-ci.org/kaelzhang/node-json-parser.svg?branch=master)](https://travis-ci.org/kaelzhang/node-json-parser) - - # json-parser JSON parser to parse JSON object and MAINTAIN comments. This is a very low level module. For most situations, recommend to use [`comment-json`](https://www.npmjs.org/package/comment-json) instead. +## this version + +this version base on kaelzhang/node-json-parser + +but add support load unsafe/un-strict json + +see test file + ## Install ```sh -$ npm install json-parser --save +$ npm install json-parser2 --save ``` ## Usage