Have ideas to improve npm?Join in the discussion! »

    @fmvilas/pseudo-yaml-ast

    0.3.1 • Public • Published

    @fmvilas/pseudo-yaml-ast

    This project is a fork of pseudo-yaml-ast

    Parse a YAML string into an object with location properties.

    Table of Contents

    Install

    npm install @fmvilas/pseudo-yaml-ast
    

    Usage

    const { yamlAST, loc } = require('pseudo-yaml-ast');
    const assert = require('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

    Apache 2.0

    Install

    npm i @fmvilas/pseudo-yaml-ast

    DownloadsWeekly Downloads

    13,197

    Version

    0.3.1

    License

    Apache-2.0

    Unpacked Size

    42.8 kB

    Total Files

    16

    Last publish

    Collaborators

    • avatar