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

jsonc-parser

Package Overview
Dependencies
Maintainers
0
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 3.2.1 to 3.3.0

4

CHANGELOG.md

@@ -0,2 +1,6 @@

3.3.0 2022-06-24
=================
- `JSONVisitor.onObjectBegin` and `JSONVisitor.onArrayBegin` can now return `false` to instruct the visitor that no children should be visited.
3.2.0 2022-08-30

@@ -3,0 +7,0 @@ =================

@@ -351,15 +351,42 @@ /*---------------------------------------------------------------------------------------------

const _jsonPath = [];
// Depth of onXXXBegin() callbacks suppressed. onXXXEnd() decrements this if it isn't 0 already.
// Callbacks are only called when this value is 0.
let suppressedCallbacks = 0;
function toNoArgVisit(visitFunction) {
return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
}
function toNoArgVisitWithPath(visitFunction) {
return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
}
function toOneArgVisit(visitFunction) {
return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
}
function toOneArgVisitWithPath(visitFunction) {
return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
}
const onObjectBegin = toNoArgVisitWithPath(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisitWithPath(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
function toBeginVisit(visitFunction) {
return visitFunction ?
() => {
if (suppressedCallbacks > 0) {
suppressedCallbacks++;
}
else {
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
if (cbReturn === false) {
suppressedCallbacks = 1;
}
}
}
: () => true;
}
function toEndVisit(visitFunction) {
return visitFunction ?
() => {
if (suppressedCallbacks > 0) {
suppressedCallbacks--;
}
if (suppressedCallbacks === 0) {
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
}
}
: () => true;
}
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
const disallowComments = options && options.disallowComments;

@@ -366,0 +393,0 @@ const allowTrailingComma = options && options.allowTrailingComma;

6

lib/esm/main.d.ts

@@ -198,4 +198,5 @@ /**

* Invoked when an open brace is encountered and an object is started. The offset and length represent the location of the open brace.
* When `false` is returned, the object properties will not be visited.
*/
onObjectBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void;
onObjectBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => boolean | void;
/**

@@ -213,4 +214,5 @@ * Invoked when a property is encountered. The offset and length represent the location of the property name.

* Invoked when an open bracket is encountered. The offset and length represent the location of the open bracket.
* When `false` is returned, the array items will not be visited.
*/
onArrayBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void;
onArrayBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => boolean | void;
/**

@@ -217,0 +219,0 @@ * Invoked when a closing bracket is encountered. The offset and length represent the location of the closing bracket.

@@ -370,15 +370,42 @@ (function (factory) {

const _jsonPath = [];
// Depth of onXXXBegin() callbacks suppressed. onXXXEnd() decrements this if it isn't 0 already.
// Callbacks are only called when this value is 0.
let suppressedCallbacks = 0;
function toNoArgVisit(visitFunction) {
return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
}
function toNoArgVisitWithPath(visitFunction) {
return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
}
function toOneArgVisit(visitFunction) {
return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
}
function toOneArgVisitWithPath(visitFunction) {
return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
}
const onObjectBegin = toNoArgVisitWithPath(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisitWithPath(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
function toBeginVisit(visitFunction) {
return visitFunction ?
() => {
if (suppressedCallbacks > 0) {
suppressedCallbacks++;
}
else {
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
if (cbReturn === false) {
suppressedCallbacks = 1;
}
}
}
: () => true;
}
function toEndVisit(visitFunction) {
return visitFunction ?
() => {
if (suppressedCallbacks > 0) {
suppressedCallbacks--;
}
if (suppressedCallbacks === 0) {
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
}
}
: () => true;
}
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
const disallowComments = options && options.disallowComments;

@@ -385,0 +412,0 @@ const allowTrailingComma = options && options.allowTrailingComma;

@@ -198,4 +198,5 @@ /**

* Invoked when an open brace is encountered and an object is started. The offset and length represent the location of the open brace.
* When `false` is returned, the object properties will not be visited.
*/
onObjectBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void;
onObjectBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => boolean | void;
/**

@@ -213,4 +214,5 @@ * Invoked when a property is encountered. The offset and length represent the location of the property name.

* Invoked when an open bracket is encountered. The offset and length represent the location of the open bracket.
* When `false` is returned, the array items will not be visited.
*/
onArrayBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void;
onArrayBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => boolean | void;
/**

@@ -217,0 +219,0 @@ * Invoked when a closing bracket is encountered. The offset and length represent the location of the closing bracket.

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

@@ -8,2 +8,8 @@ "main": "./lib/umd/main.js",

"module": "./lib/esm/main.js",
"exports": {
"types": "./lib/umd/main.d.ts",
"import": "./lib/esm/main.js",
"require": "./lib/umd/main.js",
"browser": "./lib/esm/main.js"
},
"author": "Microsoft Corporation",

@@ -19,10 +25,10 @@ "repository": {

"devDependencies": {
"mocha": "^10.2.0",
"typescript": "^5.3.3",
"@types/node": "^16.x",
"@types/mocha": "^10.0.6",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"eslint": "^8.56.0",
"rimraf": "^5.0.5"
"@types/mocha": "^10.0.7",
"@types/node": "^18.x",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"eslint": "^8.57.0",
"mocha": "^10.4.0",
"rimraf": "^5.0.7",
"typescript": "^5.4.2"
},

@@ -29,0 +35,0 @@ "scripts": {

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

- the *parseTree* function computes a hierarchical DOM with offsets representing the encountered properties and values.
- the *parse* function evaluates the JavaScript object represented by JSON string in a fault tolerant fashion.
- the *parse* function evaluates the JavaScript object represented by JSON string in a fault tolerant fashion.
- the *getLocation* API returns a location object that describes the property or value located at a given offset in a JSON document.

@@ -41,3 +41,3 @@ - the *findNodeAtLocation* API finds the node at a given location path in a JSON DOM.

export function createScanner(text: string, ignoreTrivia: boolean = false): JSONScanner;
/**

@@ -111,3 +111,3 @@ * The scanner object, representing a JSON scanner at a position in the input string.

* Visitor called by {@linkcode visit} when parsing JSON.
*
*
* The visitor functions have the following common parameters:

@@ -117,3 +117,3 @@ * - `offset`: Global offset within the JSON document, starting at 0

* - `startCharacter`: Start character (column) within the current line, starting at 0
*
*
* Additionally some functions have a `pathSupplier` parameter which can be used to obtain the

@@ -125,4 +125,5 @@ * current `JSONPath` within the document.

* Invoked when an open brace is encountered and an object is started. The offset and length represent the location of the open brace.
* When `false` is returned, the array items will not be visited.
*/
onObjectBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void;
onObjectBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void | boolean;

@@ -141,4 +142,5 @@ /**

* Invoked when an open bracket is encountered. The offset and length represent the location of the open bracket.
* When `false` is returned, the array items will not be visited.*
*/
onArrayBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void;
onArrayBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void | boolean;
/**

@@ -242,3 +244,3 @@ * Invoked when a closing bracket is encountered. The offset and length represent the location of the closing bracket.

/**
* Evaluates the JavaScript object of the given JSON DOM node
* Evaluates the JavaScript object of the given JSON DOM node
*/

@@ -249,4 +251,4 @@ export function getNodeValue(node: Node): any;

* Computes the edit operations needed to format a JSON document.
*
* @param documentText The input text
*
* @param documentText The input text
* @param range The range to format or `undefined` to format the full content

@@ -261,6 +263,6 @@ * @param options The formatting options

* Computes the edit operations needed to modify a value in the JSON document.
*
* @param documentText The input text
*
* @param documentText The input text
* @param path The path of the value to change. The path represents either to the document root, a property or an array item.
* If the path points to an non-existing property or item, it will be created.
* If the path points to an non-existing property or item, it will be created.
* @param value The new value for the specified property or item. If the value is undefined,

@@ -276,3 +278,3 @@ * the property or item will be removed.

* Applies edits to an input string.
* @param text The input text
* @param text The input text
* @param edits Edit operations following the format described in {@linkcode EditResult}.

@@ -319,3 +321,3 @@ * @returns The text with the applied edits.

/**
* The start offset of the range.
* The start offset of the range.
*/

@@ -329,3 +331,3 @@ offset: number;

/**
/**
* Options used by {@linkcode format} when computing the formatting edit operations

@@ -348,3 +350,3 @@ */

/**
/**
* Options used by {@linkcode modify} when computing the modification edit operations

@@ -351,0 +353,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