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 0.1.2 to 0.2.0

24

lib/main.d.ts

@@ -96,10 +96,26 @@ export declare enum ScanError {

}
export declare type Segment = string | number;
export interface Location {
/**
* The previous property key or literal value (string, number, boolean or null) or undefined.
*/
previousNode?: Node;
segments: string[];
matches: (segments: string[]) => boolean;
completeProperty: boolean;
/**
* The path describing the location in the JSON document. The path consists of a sequence strings
* representing an object property or numbers for array indices.
*/
path: Segment[];
/**
* Matches the locations path against a pattern consisting of strings (for properties) and numbers (for array indices).
* '*' will match a single segment, of any property name or index.
* '**' will match a sequece of segments or no segment, of any property name or index.
*/
matches: (patterns: Segment[]) => boolean;
/**
* If set, the location's offset is at a property key.
*/
isAtPropertyKey: boolean;
}
/**
* For a given offset, evaluate the location in the JSON document. Each segment in a location is either a property names or an array accessors.
* For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
*/

@@ -106,0 +122,0 @@ export declare function getLocation(text: string, position: number): Location;

46

lib/main.js

@@ -563,6 +563,6 @@ /*---------------------------------------------------------------------------------------------

/**
* For a given offset, evaluate the location in the JSON document. Each segment in a location is either a property names or an array accessors.
* For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
*/
function getLocation(text, position) {
var segments = [];
var segments = []; // strings or numbers
var earlyReturnException = new Object();

@@ -576,4 +576,3 @@ var previousNode = void 0;

};
var completeProperty = false;
var hasComma = false;
var isAtPropertyKey = false;
function setPreviousNode(value, offset, length, type) {

@@ -594,4 +593,4 @@ previousNodeInst.value = value;

previousNode = void 0;
completeProperty = position > offset;
hasComma = false;
isAtPropertyKey = position > offset;
segments.push(''); // push a placeholder (will be replaced or removed)
},

@@ -603,4 +602,3 @@ onObjectProperty: function (name, offset, length) {

setPreviousNode(name, offset, length, 'property');
hasComma = false;
segments.push(name);
segments[segments.length - 1] = name;
if (position <= offset + length) {

@@ -615,6 +613,3 @@ throw earlyReturnException;

previousNode = void 0;
if (!hasComma) {
segments.pop();
}
hasComma = false;
segments.pop();
},

@@ -626,4 +621,3 @@ onArrayBegin: function (offset, length) {

previousNode = void 0;
segments.push('[0]');
hasComma = false;
segments.push(0);
},

@@ -635,6 +629,3 @@ onArrayEnd: function (offset, length) {

previousNode = void 0;
if (!hasComma) {
segments.pop();
}
hasComma = false;
segments.pop();
},

@@ -656,15 +647,15 @@ onLiteralValue: function (value, offset, length) {

previousNode.columnOffset = offset;
completeProperty = false;
isAtPropertyKey = false;
previousNode = void 0;
}
else if (sep === ',') {
var last = segments.pop();
if (last[0] === '[' && last[last.length - 1] === ']') {
segments.push('[' + (parseInt(last.substr(1, last.length - 2)) + 1) + ']');
var last = segments[segments.length - 1];
if (typeof last === 'number') {
segments[segments.length - 1] = last + 1;
}
else {
completeProperty = true;
isAtPropertyKey = true;
segments[segments.length - 1] = '';
}
previousNode = void 0;
hasComma = true;
}

@@ -679,6 +670,9 @@ }

}
if (segments[segments.length - 1] === '') {
segments.pop();
}
return {
segments: segments,
path: segments,
previousNode: previousNode,
completeProperty: completeProperty,
isAtPropertyKey: isAtPropertyKey,
matches: function (pattern) {

@@ -685,0 +679,0 @@ var k = 0;

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

@@ -5,0 +5,0 @@ "main": "./lib/main.js",

@@ -136,5 +136,29 @@ # jsonc-parser

/**
* For a given offset, evaluate the location in the JSON document. Each segment in a location is either a property names or an array accessors.
* For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
*/
export declare function getLocation(text: string, position: number): Location;
export declare type Segment = string | number;
export interface Location {
/**
* The previous property key or literal value (string, number, boolean or null) or undefined.
*/
previousNode?: Node;
/**
* The path describing the location in the JSON document. The path consists of a sequence strings
* representing an object property or numbers for array indices.
*/
path: Segment[];
/**
* Matches the locations path against a pattern consisting of strings (for properties) and numbers (for array indices).
* '*' will match a single segment, of any property name or index.
* '**' will match a sequece of segments or no segment, of any property name or index.
*/
matches: (patterns: Segment[]) => boolean;
/**
* If set, the location's offset is at a property key.
*/
isAtPropertyKey: boolean;
}
```

@@ -141,0 +165,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