# template-filters

> Collection of filters to use in any templating engine like Nunjucks, Liquid, Handlebars etc

Latest version **0.2.3** (published 2020-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install template-filters
pnpm add template-filters
yarn add template-filters
bun add template-filters
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2020-09-12 |
| First published | 2020-06-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Oscar Otero |
| Maintainers | oscarotero |
| Keywords | filters, templates, nunjucks, className, attributes, markdown |

## Links

- npm: https://www.npmjs.com/package/template-filters
- npm.io page: https://npm.io/package/template-filters

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.2.3 (latest) — 2020-09-12
- 0.2.2 — 2020-06-28
- 0.2.1 — 2020-06-28
- 0.2.0 — 2020-06-15
- 0.1.0 — 2020-06-15

## README

# template-filters

Collection of generic filters to use in any template engine like Nunjucks, Liquid, Handlebars, ejs etc.
**Zero dependencies**

## Install

```sh
npm i template-filters --save-dev
```

Add filters to, for example, a [11ty](https://www.11ty.dev/docs/filters/) static site:

```js
eleventyConfig.addFilter('attributes', require('template-filters/attributes'));
```

### className

To generate classNames attributes:

```njk
<div class="{{ ['foo', {bar: true}] | className }}">
```

Render to:

```njk
<div class="foo bar">
```

### attributes

To generate html attributes:

```njk
<div {{ { hidden: true, class: ['foo', 'bar']} | attributes }}">
```

Render to:

```njk
<div hidden class="foo bar">
```

Use arguments to filter attributes:

```njk
<div {{ { hidden: true, name: 'foo', id: 'bar'} | attributes('hidden', 'id') | safe }}">
```

Render to:

```njk
<div hidden id="bar">
```

### markdown

A wrapper of [markdown-it](https://github.com/markdown-it/markdown-it) to markdownify texts.

```js
const markdownFilter = require('template-filters/markdown');
const MarkdownIt = require('markdown-it');

const markdown = markdownFilter(new MarkdownIt());

markdown('Hello **world**');
```

```njk
{{ 'Hello **world**' | markdown | safe }}
```

Render to:

```njk
<p>Hello <strong>world</strong></p>
```

Set true to render an inline version

```njk
<h1>{{ 'Hello **world**' | markdown(true) | safe }}</h1>
```

Render to:

```njk
<h1>Hello <strong>world</strong></h1>
```

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