@stoplight/json
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51461
521