parseWithPointers: Parses YAML into JSON and also returns diagnostics as well as full ast with line information.
// basic example of parseWithPointersimport { parseWithPointers } from"@stoplight/yaml";
const result = parseWithPointers("foo: bar");
console.log(result.data); // => the {foo: "bar"} JS object
// basic example of getJsonPathForPosition and getLocationForJsonPathimport { getJsonPathForPosition, getLocationForJsonPath, parseWithPointers } from"@stoplight/yaml";
const result = parseWithPointers(`hello: world
address:
street: 123`
);
const path = getJsonPathForPosition(result, { line: 2, character: 7 }); // line and character are 0-basedconsole.log(path); // -> ["address", "street"];const position = getLocationForJsonPath(result, ['address']);
console.log(position.range.start); // { line: 1, character: 8 } line and character are 0-basedconsole.log(position.range.end); // { line: 2, character: 15 } line and character are 0-based
Contributing
Clone repo.
Create / checkout feature/{name}, chore/{name}, or fix/{name} branch.
Install deps: yarn.
Make your changes.
Run tests: yarn test.prod.
Stage relevant files to git.
Commit: yarn commit. NOTE: Commits that don't follow the conventional format will be rejected. yarn commit creates this format for you, or you can put it together manually and then do a regular git commit.
A performant way to find the appropriate line for the given position.
This is key to making the yaml line mapping performant.