# freemarker-parser

> Freemarker Parser is a javascript implementation of the Freemarker

Latest version **1.2.1** (published 2021-01-22) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2021-01-22 |
| First published | 2017-09-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 0 |
| Unpacked size | 228.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Armano |
| Maintainers | armano |
| Keywords | freemarker, parser, js, ast, ftl |

## Links

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

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.2.1 (latest) — 2021-01-22
- 1.2.0 — 2021-01-22
- 1.1.6 — 2018-10-31
- 1.1.5 — 2018-10-28
- 1.1.4 — 2018-10-26
- 1.1.3 — 2018-10-23
- 1.1.1 — 2018-10-22
- 1.1.0 — 2018-10-22
- 1.0.1 — 2018-10-22
- 1.0.0 — 2017-09-07

## README

# freemarker-parser

[![Codecov](https://img.shields.io/codecov/c/github/armano2/freemarker-parser.svg)](https://codecov.io/gh/armano2/freemarker-parser/tree/master)
[![License](https://img.shields.io/github/license/armano2/freemarker-parser.svg)](https://github.com/armano2/freemarker-parser/blob/master/LICENSE.md)
[![npm](https://img.shields.io/npm/v/freemarker-parser.svg)](https://www.npmjs.com/package/freemarker-parser)

Freemarker Parser is a javascript implementation of the Freemarker (https://freemarker.apache.org).

This project contains **experimental version** of parser ftl to ast tree

## Installation

You can install `freemarker-parser` using [npm](https://npmjs.com):

```bash
$ npm install freemarker-parser --save-dev
```

## Usage

Require `freemarker-parser` inside of your JavaScript:

### Parser

```ftl
<#assign f=1>

<#if f gt 0>
  ${f} > 0
<#else>
  ${f} < 0
</#if>
```

```ts
const freemarker = require('freemarker-parser');

const parser = new freemarker.Parser();
const data = parser.parse(template);

console.log(data.ast);
console.log(data.tokens);
```

### Parser (bracket style)

```ftl
[#assign f=1]

[#if f gt 0]
  ${f} > 0
[#else]
  ${f} < 0
[/#if]
```

```ts
const freemarker = require('freemarker-parser');

const parser = new freemarker.Parser();
const data = parser.parse(template, {
  useSquareTags: true,
  parseLocation: true,
});

console.log(data.ast);
console.log(data.tokens);
```

## Currently supported:

- interpolations `${foo}`
  - methods, i.e. `${avg(3, 5)}`
- executing macro
- directives https://freemarker.apache.org/docs/ref_directives.html:
  - [`#attempt`](https://freemarker.apache.org/docs/ref_directive_attempt.html)
    - `#recover`
  - [`#assign`](https://freemarker.apache.org/docs/ref_directive_assign.html)
  - [`#global`](https://freemarker.apache.org/docs/ref_directive_global.html)
  - [`#local`](https://freemarker.apache.org/docs/ref_directive_local.html)
  - [`#if`](https://freemarker.apache.org/docs/ref_directive_if.html)
    - `#elseif`
    - `#else`
  - [`#list`](https://freemarker.apache.org/docs/ref_directive_list.html)
    - `#else`
    - `#break`
    - `#continue`
    - `#items`
  - [`#include`](https://freemarker.apache.org/docs/ref_directive_include.html)
  - [`#import`](https://freemarker.apache.org/docs/ref_directive_import.html)
  - [`#macro`](https://freemarker.apache.org/docs/ref_directive_macro.html)
  - [`#switch`](https://freemarker.apache.org/docs/ref_directive_switch.html)
    - `#case`
    - `#default`
    - `#break`
  - [`#compress`](https://freemarker.apache.org/docs/ref_directive_compress.html)
  - [`#function`](https://freemarker.apache.org/docs/ref_directive_function.html)
    - `#return`
  - [`#parse`](https://freemarker.apache.org/docs/ref_directive_parse.html) - [`#noparse`](https://freemarker.apache.org/docs/ref_directive_noparse.html)
  - [`#stop`](https://freemarker.apache.org/docs/ref_directive_stop.html)
  - [`#setting`](https://freemarker.apache.org/docs/ref_directive_setting.html)
  - [`#lt`](https://freemarker.apache.org/docs/ref_directive_lt.html)
  - [`#t`](https://freemarker.apache.org/docs/ref_directive_t.html)
  - [`#nt`](https://freemarker.apache.org/docs/ref_directive_nt.html)
  - [`#rt`](https://freemarker.apache.org/docs/ref_directive_rt.html)
  - [`#flush`](https://freemarker.apache.org/docs/ref_directive_flush.html)
  - [`#escape`](https://freemarker.apache.org/docs/ref_directive_escape.html)
    - `#noescape`
  - [`#autoesc`](https://freemarker.apache.org/docs/ref_directive_autoesc.html)
  - [`#noautoesc`](https://freemarker.apache.org/docs/ref_directive_noautoesc.html)
  - [`#outputformat`](https://freemarker.apache.org/docs/ref_directive_outputformat.html)
  - [`#ftl`](https://freemarker.apache.org/docs/ref_directive_ftl.html)
- comments `<#-- -->`
- built-ins:
  - `?toUpperCase`
  - `?toLowerCase`
  - `?capitalize`
  - `?length`
  - `?string("yes", "no")`
- support default values, i.e. `${user!"Anonymous"}`

## TODO:

- directives:
  - `#fallback`
  - `#nested`
  - `#recurse`
  - `#visit`

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