jex-block-parser

1.0.0 • Public • Published

jex-block-parser

Partition text based on indentation.

Build Status

Usage

const { parse } = require('jex-block-parser')
 
let input = `
hello
world
`
 
parse(input)
 
[ { scope: 'hello', children: [] },
  { scope: 'world', children: [] } ]

Deep

We don't care about blank lines or the type of indentation.

input = `
fruits
  apple
    gala
    pink lady
  pear
 
  cherry
    white
 
veggies
  kale
    red russian
 
  cabbage
  radish
`
 
parse(input)
 
[ { scope: 'fruits',
    children:
     [ { scope: '  apple',
         children:
          [ { scope: '    gala', children: [] },
            { scope: '    pink lady', children: [] } ] },
       { scope: '  pear', children: [] },
       { scope: '  cherry',
         children: [ { scope: '    white', children: [] } ] } ] },
  { scope: 'veggies',
    children:
     [ { scope: '  kale',
         children: [ { scope: '    red russian', children: [] } ] },
       { scope: '  cabbage', children: [] },
       { scope: '  radish', children: [] } ] } ]

Package Sidebar

Install

npm i jex-block-parser

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

4.45 kB

Total Files

3

Last publish

Collaborators

  • reergymerej