yaml-doc-query
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

yaml-doc-query

lookup values along with their position in yaml documents

install

npm i yaml-doc-query
# yarn add yaml-doc-query

use

import { parseDocument } from 'yaml';
import { yamlDocQuery } from 'yaml-doc-query';

const yamlSource = `
one: 1
two:
 - three: 4
 - five: 5
`;
const document = parseDocument(yamlSource);
const $doc = yamlDocQuery(document);

/* use object access syntax to navigate into the document
   and end your query with () to get value and range from that node */
expect($doc.two[1].five()).toEqual({ value: 5, range: [34, 35, 36] });

/* pass source to get position instead of range */
expect(yamlDocQuery(document, yamlSource).two[0]()).toEqual({
  value: { three: 4 },
  position: { start: { line: 4, column: 3 }, end: { line: 5, column: 0 } },
});

/* receive undefined for non-existent nodes */
expect($doc.this.does.not.exist()).toEqual(undefined);

Package Sidebar

Install

npm i yaml-doc-query

Weekly Downloads

2

Version

0.2.1

License

MIT

Unpacked Size

13.6 kB

Total Files

7

Last publish

Collaborators

  • xiphe