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

@stoplight/json

Package Overview
Dependencies
Maintainers
11
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoplight/json - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

4

getJsonPathForPosition.js

@@ -7,6 +7,6 @@ "use strict";

const endOffset = lineMap[position.line + 1];
if (startOffset === undefined) {
if (startOffset === void 0) {
return;
}
const node = jsonc_parser_1.findNodeAtOffset(ast, endOffset === undefined ? startOffset + position.character : Math.min(endOffset, startOffset + position.character), true);
const node = jsonc_parser_1.findNodeAtOffset(ast, endOffset === void 0 ? startOffset + position.character : Math.min(endOffset, startOffset + position.character), true);
if (node === undefined) {

@@ -13,0 +13,0 @@ return;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jsonc_parser_1 = require("jsonc-parser");
exports.getLocationForJsonPath = ({ lineMap, ast }, path) => {
const node = jsonc_parser_1.findNodeAtLocation(ast, path);
if (node === undefined || node.range === undefined) {
exports.getLocationForJsonPath = ({ lineMap, ast }, path, closest = false) => {
const node = findNodeAtPath(ast, path, closest);
if (node === void 0 || node.range === void 0) {
return;

@@ -11,2 +10,25 @@ }

};
function findNodeAtPath(node, path, closest) {
pathLoop: for (const segment of path) {
if (typeof segment === 'string') {
if (node.type !== 'object' || !Array.isArray(node.children)) {
return closest ? node : void 0;
}
for (const propertyNode of node.children) {
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment) {
node = propertyNode.children[1];
continue pathLoop;
}
}
return closest ? node : void 0;
}
else {
if (node.type !== 'array' || segment < 0 || !Array.isArray(node.children) || segment >= node.children.length) {
return closest ? node : void 0;
}
node = node.children[segment];
}
}
return node;
}
//# sourceMappingURL=getLocationForJsonPath.js.map
{
"name": "@stoplight/json",
"version": "2.0.1",
"version": "2.1.0",
"description": "Useful functions when working with JSON.",

@@ -5,0 +5,0 @@ "keywords": [

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

catch (e) {
return undefined;
return void 0;
}

@@ -19,0 +19,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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