@trenskow/parse

0.1.19 • Public • Published

@trenskow/parse

A small library for parsing a string into a tree.

Usage

Below is an example on how to use the library.

import parse from '@trenskow/parse';

parse('${', '}', { /* options */ }).do('This ${is ${my ${nested ${string}}}}');

The above example will return the following structure

[
    'This ', [
        'is ', [
            'my ', [
                'nested ',
                'string'
            ]
        ]
    ]
]

One caveat: opening and closing token cannot be the same.

Options

The following options are available.

Name Description Type Default value
maxDepth Do not parse under a certain depth. Number Infinity
ignoreInside A string (or array of strings) indicating characters at which to ignore parsing in between (see example below). String or Array of String []

ignoreInside

An example of ignore inside is this.

parse('[', ']', { ignoreInside: '"' }).do('This is ["my custom [string]"]')
// ➡ [ 'This is ', '"my custom [string]"' ]

License

See license in LICENSE.

Readme

Keywords

Package Sidebar

Install

npm i @trenskow/parse

Weekly Downloads

0

Version

0.1.19

License

BSD-2-Clause

Unpacked Size

13.1 kB

Total Files

8

Last publish

Collaborators

  • trenskow