# twig-parser

> This tool transforms a twig template to AST

Latest version **0.2.2** (published 2023-05-06) · Mozilla Public License 2.0 license · 0 weekly downloads

## Install

```sh
npm install twig-parser
pnpm add twig-parser
yarn add twig-parser
bun add twig-parser
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2023-05-06 |
| First published | 2023-05-02 |
| Weekly downloads | 0 |
| License | Mozilla Public License 2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 156.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Stanislav Romanov |
| Maintainers | kaermorchen |

## Links

- npm: https://www.npmjs.com/package/twig-parser
- Repository: https://github.com/kaermorchen/twig-parser
- Homepage: https://github.com/kaermorchen/twig-parser#readme
- Issues: https://github.com/kaermorchen/twig-parser/issues
- npm.io page: https://npm.io/package/twig-parser

## Dependencies (1)

- [chevrotain](https://npm.io/package/chevrotain.md) ^10.5.0

## Recent versions

- 0.2.2 (latest) — 2023-05-06
- 0.2.1 — 2023-05-04
- 0.2.0 — 2023-05-04
- 0.1.0 — 2023-05-02

## README

# Twig Parser

This tool transforms a twig template to AST. It uses [chevrotain](https://chevrotain.io) under the hood.

## How to use it
```js
import { parse } from 'twig-parser';

const twig = `
  {% set foo = range(0, 3) %}

  {% for i in foo %}
      {{ i }},
  {% endfor %}
`

const { ast, tokens, errors } = parse(twig);
```

## Notes
1. [Whitespace trimming](https://twig.symfony.com/doc/3.x/templates.html#whitespace-control) is not supported
1. The body of the verbatim tag is parsed as a regular template

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