Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonc-simple-parser

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonc-simple-parser - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

tasks/sample_invalid.json

8

dist/lookup.js

@@ -101,3 +101,3 @@ "use strict";

return token.index;
return parse_1.default(detokenize_1.default(token));
return (0, parse_1.default)((0, detokenize_1.default)(token));
}

@@ -113,3 +113,3 @@ else {

if (utils_1.default.isTokenLiteral(token))
return parse_1.default(detokenize_1.default(token));
return (0, parse_1.default)((0, detokenize_1.default)(token));
if (usePartialScanning)

@@ -122,6 +122,6 @@ return;

return;
return parse_1.default(detokenize_1.default(parent.token));
return (0, parse_1.default)((0, detokenize_1.default)(parent.token));
};
const lookup = (text, position, usePartialScanning = true) => {
const limit = usePartialScanning ? position : Infinity, ast = tokenize_1.default(text, limit), token = getLookupToken(ast, position), path = getLookupPath(token), isInsideProperty = getLookupIsInsideProperty(token), isInsideValue = getLookupIsInsideValue(token), property = getLookupProperty(token, isInsideProperty), value = getLookupValue(token, isInsideValue, usePartialScanning), t = token ? { type: token.type, start: token.start, end: token.end, source: token.source } : undefined, result = { path, property, value, token: t, isInsideProperty, isInsideValue };
const limit = usePartialScanning ? position : Infinity, ast = (0, tokenize_1.default)(text, limit), token = getLookupToken(ast, position), path = getLookupPath(token), isInsideProperty = getLookupIsInsideProperty(token), isInsideValue = getLookupIsInsideValue(token), property = getLookupProperty(token, isInsideProperty), value = getLookupValue(token, isInsideValue, usePartialScanning), t = token ? { type: token.type, start: token.start, end: token.end, source: token.source } : undefined, result = { path, property, value, token: t, isInsideProperty, isInsideValue };
return result;

@@ -128,0 +128,0 @@ };

@@ -11,3 +11,3 @@ "use strict";

if (reviver) { // A "reviver" could have side effects, it may not be safe to call it twice
return _parse(strip_1.default(text), reviver);
return _parse((0, strip_1.default)(text), reviver);
}

@@ -19,3 +19,3 @@ else {

catch (error) { // Stripping out any potential comments and trailing commas and trying again
const textStripped = strip_1.default(text);
const textStripped = (0, strip_1.default)(text);
if (text === textStripped) { // Parsing it again would inevitably lead to the same error

@@ -22,0 +22,0 @@ throw error;

@@ -9,5 +9,5 @@ "use strict";

context_1.default.init();
return parser_1.default(text);
return (0, parser_1.default)(text);
};
/* EXPORT */
exports.default = strip;

@@ -8,4 +8,4 @@ "use strict";

/* PARSER */
const parser = reghex_1.parse(grammar_1.default(tokens_1.default));
const parser = (0, reghex_1.parse)((0, grammar_1.default)(tokens_1.default));
/* EXPORT */
exports.default = parser;

@@ -23,3 +23,3 @@ "use strict";

const _Separated = $.Passthrough `${Trivia}*`;
const _Merged = $.Whitespace `${/(?:[ \t\r\n]+|\/\/.*|\/\*[^]*?\*\/)*/}`;
const _Merged = $.Whitespace `${/(?:[ \t\r\n]|\/\/.*|\/\*[^]*?\*\/)*/}`;
const _ = $.Newline === $.Whitespace && $.Whitespace === $.CommentLine && $.CommentLine === $.CommentBlock ? _Merged : _Separated;

@@ -40,3 +40,3 @@ /* COMMA */

/* STRING */
const String = $.String `${/"(?:[^\u0000-\u001F\\"]+|\\["bfnrt\\/]|\\u[0-9a-fA-F]{4})*"/}`;
const String = $.String `${/"(?:[^\u0000-\u001F\\"]|\\["bfnrt\\/]|\\u[0-9a-fA-F]{4})*"/}`;
/* ARRAY */

@@ -43,0 +43,0 @@ const ArrayOpen = $.ArrayOpen `${'['}`;

@@ -9,5 +9,5 @@ "use strict";

context_1.default.init(limit);
return parser_1.default(text);
return (0, parser_1.default)(text);
};
/* EXPORT */
exports.default = tokenize;

@@ -8,4 +8,4 @@ "use strict";

/* PARSER */
const parser = reghex_1.parse(grammar_1.default(tokens_1.default));
const parser = (0, reghex_1.parse)((0, grammar_1.default)(tokens_1.default));
/* EXPORT */
exports.default = parser;

@@ -37,3 +37,3 @@ "use strict";

const transformer = tokens[type];
const matcher = transformer.unwrapped ? transformer : cache.get(transformer) || reghex_1.match(type, transformer);
const matcher = transformer.unwrapped ? transformer : cache.get(transformer) || (0, reghex_1.match)(type, transformer);
cache.set(transformer, matcher);

@@ -40,0 +40,0 @@ acc[type] = matcher;

@@ -8,3 +8,3 @@ "use strict";

try {
parse_1.default(text);
(0, parse_1.default)(text);
return true;

@@ -11,0 +11,0 @@ }

{
"name": "jsonc-simple-parser",
"description": "A simple JSON parser that supports comments and optional trailing commas.",
"version": "2.2.0",
"version": "2.2.1",
"main": "dist/index.js",

@@ -12,3 +12,3 @@ "types": "dist/index.d.ts",

"compile:watch": "tsc --skipLibCheck --watch",
"test:test262:init": "git clone git@github.com:tc39/test262.git ./test/test262 && rm ./test/test262/test/built-ins/JSON/parse/name.js",
"test:test262:init": "git clone https://github.com/tc39/test262.git ./test/test262 && rm ./test/test262/test/built-ins/JSON/parse/name.js",
"test:test262:prelude": "{ echo 'var module = {}, exports = {};' && esbuild dist/index.js --bundle --format=cjs --minify --target=es2016 && echo 'JSON.parse=module.exports.default.parse;JSON.stringify=module.exports.default.stringify;' } > test/test262/prelude.js",

@@ -15,0 +15,0 @@ "test:test262:execute": "test262-harness -t 8 --prelude ./test/test262/prelude.js ./test/test262/test/built-ins/JSON/parse/*.js ./test/test262/test/built-ins/JSON/stringify/*.js",

@@ -53,3 +53,3 @@

const _Merged
= $.Whitespace`${/(?:[ \t\r\n]+|\/\/.*|\/\*[^]*?\*\/)*/}`;
= $.Whitespace`${/(?:[ \t\r\n]|\/\/.*|\/\*[^]*?\*\/)*/}`;

@@ -95,3 +95,3 @@ const _ = $.Newline === $.Whitespace && $.Whitespace === $.CommentLine && $.CommentLine === $.CommentBlock ? _Merged : _Separated;

const String
= $.String`${/"(?:[^\u0000-\u001F\\"]+|\\["bfnrt\\/]|\\u[0-9a-fA-F]{4})*"/}`;
= $.String`${/"(?:[^\u0000-\u001F\\"]|\\["bfnrt\\/]|\\u[0-9a-fA-F]{4})*"/}`;

@@ -98,0 +98,0 @@ /* ARRAY */

@@ -10,2 +10,4 @@

{default: JSONC} = require ( '../dist' ),
sampleInvalidPath = path.resolve ( __dirname, 'sample_invalid.json' ),
sampleInvalid = fs.readFileSync ( sampleInvalidPath, 'utf8' ),
sampleWithCommentsPath = path.resolve ( __dirname, 'sample_with_comments.json' ),

@@ -27,2 +29,33 @@ sampleWithComments = fs.readFileSync ( sampleWithCommentsPath, 'utf8' ),

benchmark.group ( 'Invalid', () => {
benchmark ({
name: 'JSONC.parse',
fn: () => {
try {
JSONC.parse ( sampleInvalid );
} catch {}
}
});
benchmark ({
name: 'JSONC.parse (VSC)',
fn: () => {
try {
VSCJSONC.parse ( sampleInvalid );
} catch {}
}
});
benchmark ({
name: 'JSON5.parse',
fn: () => {
try {
JSON5.parse ( sampleInvalid );
} catch {}
}
});
});
benchmark.group ( 'With Comments', () => {

@@ -29,0 +62,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc