joyent-portal/packages/pseudo-yaml-ast
Sérgio Ramos e2c0845145 chore: publish
- cloudapi-gql@1.0.4
 - joyent-cp-frontend@1.1.0
 - joyent-cp-gql-mock-server@1.0.4
 - joyent-cp-gql-schema@1.0.4
 - joyent-cp-rdb-bootstrap@1.0.4
 - normalized-styled-components@1.0.5
 - pseudo-json-ast@1.0.6
 - pseudo-yaml-ast@1.0.6
 - remcalc@1.0.5
 - rnd-id@1.0.5
 - styled-is@1.0.7
 - joyent-ui-toolkit@1.1.0
 - unitcalc@1.0.5
2017-05-25 16:07:31 +01:00
..
src chore: initial lerna setup 2017-05-25 10:56:50 +01:00
test chore: initial lerna setup 2017-05-25 10:56:50 +01:00
.babelrc chore: initial lerna setup 2017-05-25 10:56:50 +01:00
.eslintignore chore: initial lerna setup 2017-05-25 10:56:50 +01:00
.eslintrc chore: initial lerna setup 2017-05-25 10:56:50 +01:00
.tern-project chore: initial lerna setup 2017-05-25 10:56:50 +01:00
CHANGELOG.md chore: publish 2017-05-25 16:07:31 +01:00
package.json chore: publish 2017-05-25 16:07:31 +01:00
README.md chore: initial lerna setup 2017-05-25 10:56:50 +01:00
yarn.lock chore: update dependencies 2017-05-25 13:47:44 +01:00

pseudo-yaml-ast

License: MPL 2.0 npm standard-readme compliant

Parse a YAML string into an object with location properties.

Table of Contents

Install

yarn add --dev pseudo-yaml-ast

Usage

import yamlAST, { loc } from 'pseudo-yaml-ast';
import assert from 'assert';

const ast = yamlAST(`
  obj:
    arr:
    - nums:
      - 1
      - 2
      - 3
      strs1:
      - '1'
      - '2'
      - '3'
    str: '1'
    num: 1
`);

assert.deepEqual(Object.keys(ast), ['obj']);
assert.deepEqual(ast[loc].start.line, 2);
assert.deepEqual(ast[loc].end.line, 14);

assert.deepEqual(Object.keys(ast.obj), ['arr', 'str', 'num']);
assert.deepEqual(ast.obj[loc].start.line, 2);
assert.deepEqual(ast.obj[loc].end.line, 13);

assert.deepEqual(ast.obj.str[loc].start.line, 12);
assert.deepEqual(ast.obj.str[loc].end.line, 12);
assert.deepEqual(ast.obj.num[loc].start.line, 13);
assert.deepEqual(ast.obj.num[loc].end.line, 13);
assert.deepEqual(ast.obj.arr[0][loc].start.line, 4);
assert.deepEqual(ast.obj.arr[0][loc].end.line, 12);

assert.deepEqual(Object.keys(ast.obj.arr[0]), ['nums', 'strs1']);
assert.deepEqual(ast.obj.arr[0].nums[loc].start.line, 4);
assert.deepEqual(ast.obj.arr[0].nums[loc].end.line, 8);
assert.deepEqual(ast.obj.arr[0].strs1[loc].start.line, 8);
assert.deepEqual(ast.obj.arr[0].strs1[loc].end.line, 12);

License

MPL-2.0