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

jsonc-parser

Package Overview
Dependencies
Maintainers
11
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonc-parser - npm Package Compare versions

Comparing version 2.3.1 to 3.0.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

3.0.0 2020-11-13
==================
* fixed API spec for `parseTree`. Can return `undefine` for empty input.
* added new API `FormattingOptions.insertFinalNewline`.
2.3.0 2020-07-03

@@ -2,0 +8,0 @@ ==================

23

lib/esm/impl/format.js

@@ -61,3 +61,3 @@ /*---------------------------------------------------------------------------------------------

function addEdit(text, startOffset, endOffset) {
if (!hasError && startOffset < rangeEnd && endOffset > rangeStart && documentText.substring(startOffset, endOffset) !== text) {
if (!hasError && (!range || (startOffset < rangeEnd && endOffset > rangeStart)) && documentText.substring(startOffset, endOffset) !== text) {
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });

@@ -76,2 +76,3 @@ }

var replaceContent = '';
var needsLineBreak = false;
while (!lineBreak && (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */)) {

@@ -82,3 +83,4 @@ // comments on the same line: keep them on the same line, but ignore them otherwise

firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
replaceContent = secondToken === 12 /* LineCommentTrivia */ ? newLineAndIndent() : '';
needsLineBreak = secondToken === 12 /* LineCommentTrivia */;
replaceContent = needsLineBreak ? newLineAndIndent() : '';
secondToken = scanNext();

@@ -113,3 +115,3 @@ }

}
else {
else if (!needsLineBreak) {
// symbol following comment on the same line: keep on same line, separate with ' '

@@ -120,7 +122,11 @@ replaceContent = ' ';

case 6 /* ColonToken */:
replaceContent = ' ';
if (!needsLineBreak) {
replaceContent = ' ';
}
break;
case 10 /* StringLiteral */:
if (secondToken === 6 /* ColonToken */) {
replaceContent = '';
if (!needsLineBreak) {
replaceContent = '';
}
break;

@@ -136,3 +142,5 @@ }

if (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */) {
replaceContent = ' ';
if (!needsLineBreak) {
replaceContent = ' ';
}
}

@@ -151,2 +159,5 @@ else if (secondToken !== 5 /* CommaToken */ && secondToken !== 17 /* EOF */) {

}
if (secondToken === 17 /* EOF */) {
replaceContent = options.insertFinalNewline ? eol : '';
}
var secondTokenStart = scanner.getTokenOffset() + formatTextStart;

@@ -153,0 +164,0 @@ addEdit(replaceContent, firstTokenEnd, secondTokenStart);

@@ -91,3 +91,3 @@ /**

*/
export declare const parseTree: (text: string, errors?: ParseError[], options?: ParseOptions) => Node;
export declare const parseTree: (text: string, errors?: ParseError[], options?: ParseOptions) => Node | undefined;
/**

@@ -262,2 +262,6 @@ * Finds the node at the given path in a JSON DOM.

eol?: string;
/**
* If set, will add a new line at the end of the document.
*/
insertFinalNewline?: boolean;
}

@@ -264,0 +268,0 @@ /**

@@ -72,3 +72,3 @@ (function (factory) {

function addEdit(text, startOffset, endOffset) {
if (!hasError && startOffset < rangeEnd && endOffset > rangeStart && documentText.substring(startOffset, endOffset) !== text) {
if (!hasError && (!range || (startOffset < rangeEnd && endOffset > rangeStart)) && documentText.substring(startOffset, endOffset) !== text) {
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });

@@ -87,2 +87,3 @@ }

var replaceContent = '';
var needsLineBreak = false;
while (!lineBreak && (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */)) {

@@ -93,3 +94,4 @@ // comments on the same line: keep them on the same line, but ignore them otherwise

firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
replaceContent = secondToken === 12 /* LineCommentTrivia */ ? newLineAndIndent() : '';
needsLineBreak = secondToken === 12 /* LineCommentTrivia */;
replaceContent = needsLineBreak ? newLineAndIndent() : '';
secondToken = scanNext();

@@ -124,3 +126,3 @@ }

}
else {
else if (!needsLineBreak) {
// symbol following comment on the same line: keep on same line, separate with ' '

@@ -131,7 +133,11 @@ replaceContent = ' ';

case 6 /* ColonToken */:
replaceContent = ' ';
if (!needsLineBreak) {
replaceContent = ' ';
}
break;
case 10 /* StringLiteral */:
if (secondToken === 6 /* ColonToken */) {
replaceContent = '';
if (!needsLineBreak) {
replaceContent = '';
}
break;

@@ -147,3 +153,5 @@ }

if (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */) {
replaceContent = ' ';
if (!needsLineBreak) {
replaceContent = ' ';
}
}

@@ -162,2 +170,5 @@ else if (secondToken !== 5 /* CommaToken */ && secondToken !== 17 /* EOF */) {

}
if (secondToken === 17 /* EOF */) {
replaceContent = options.insertFinalNewline ? eol : '';
}
var secondTokenStart = scanner.getTokenOffset() + formatTextStart;

@@ -164,0 +175,0 @@ addEdit(replaceContent, firstTokenEnd, secondTokenStart);

@@ -91,3 +91,3 @@ /**

*/
export declare const parseTree: (text: string, errors?: ParseError[], options?: ParseOptions) => Node;
export declare const parseTree: (text: string, errors?: ParseError[], options?: ParseOptions) => Node | undefined;
/**

@@ -262,2 +262,6 @@ * Finds the node at the given path in a JSON DOM.

eol?: string;
/**
* If set, will add a new line at the end of the document.
*/
insertFinalNewline?: boolean;
}

@@ -264,0 +268,0 @@ /**

{
"name": "jsonc-parser",
"version": "2.3.1",
"version": "3.0.0",
"description": "Scanner and parser for JSON with comments.",

@@ -18,9 +18,9 @@ "main": "./lib/umd/main.js",

"devDependencies": {
"mocha": "^8.1.3",
"typescript": "^4.0.2",
"mocha": "^8.2.1",
"typescript": "^4.0.5",
"@types/node": "^10.12.12",
"@types/mocha": "^5.2.7",
"@typescript-eslint/eslint-plugin": "^4.1.1",
"@typescript-eslint/parser": "^4.1.1",
"eslint": "^7.9.0",
"@typescript-eslint/eslint-plugin": "^4.7.0",
"@typescript-eslint/parser": "^4.7.0",
"eslint": "^7.13.0",
"rimraf": "^3.0.2"

@@ -27,0 +27,0 @@ },

@@ -145,3 +145,3 @@ # jsonc-parser

*/
export declare function parseTree(text: string, errors?: ParseError[], options?: ParseOptions): Node;
export declare function parseTree(text: string, errors?: ParseError[], options?: ParseOptions): Node | undefined;

@@ -148,0 +148,0 @@ export declare type NodeType = "object" | "array" | "property" | "string" | "number" | "boolean" | "null";

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