# @trenskow/parse

> A small library for parsing a string into a tree.

Latest version **0.1.55** (published 2026-08-03) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install @trenskow/parse
pnpm add @trenskow/parse
yarn add @trenskow/parse
bun add @trenskow/parse
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.55 |
| Published | 2026-08-03 |
| First published | 2022-05-02 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kristian Trenskow |
| Maintainers | trenskow |
| Keywords | parse, string, nested |

## Links

- npm: https://www.npmjs.com/package/@trenskow/parse
- Repository: https://github.com/trenskow/parse
- Homepage: https://github.com/trenskow/parse#readme
- Issues: https://github.com/trenskow/parse/issues
- npm.io page: https://npm.io/package/@trenskow/parse

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.1.55 (latest) — 2026-08-03
- 0.1.54 — 2026-07-27
- 0.1.53 — 2026-07-13
- 0.1.52 — 2026-07-02
- 0.1.51 — 2026-06-25
- 0.1.50 — 2026-06-08
- 0.1.49 — 2026-05-28
- 0.1.48 — 2026-05-19
- 0.1.47 — 2026-05-04
- 0.1.46 — 2026-03-28
- 0.1.45 — 2026-02-14
- 0.1.44 — 2026-02-01
- 0.1.43 — 2026-01-06
- 0.1.42 — 2025-12-31
- 0.1.41 — 2025-12-17
- … 41 more at https://npm.io/package/@trenskow/parse/versions

## README

@trenskow/parse
----

A small library for parsing a string into a tree.

# Usage

Below is an example on how to use the library.

````javascript
import parse from '@trenskow/parse';

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

The above example will return the following structure

````javascript
[
    '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](#ignoreInside)). | String or Array of String | `[]`          |

### `ignoreInside`

An example of ignore inside is this.

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

# License

See license in LICENSE.

---
_Source: https://npm.io/package/@trenskow/parse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
