A small library for parsing a string into a tree.
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.
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 | [] |
An example of ignore inside is this.
parse('[', ']', { ignoreInside: '"' }).do('This is ["my custom [string]"]')
// ➡ [ 'This is ', '"my custom [string]"' ]
See license in LICENSE.