# maudite

> streaming templates using template literals

Latest version **1.3.0** (published 2016-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install maudite
pnpm add maudite
yarn add maudite
bun add maudite
```

## 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.3.0 |
| Published | 2016-06-01 |
| First published | 2016-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Bryan English |
| Maintainers | bengl |
| Keywords | stream, template, literal, buffer |

## Links

- npm: https://www.npmjs.com/package/maudite
- Repository: https://github.com/bengl/maudite
- Homepage: https://github.com/bengl/maudite#readme
- Issues: https://github.com/bengl/maudite/issues
- npm.io page: https://npm.io/package/maudite

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2016-06-01
- 1.2.0 — 2016-05-24
- 1.1.0 — 2016-05-20
- 1.0.0 — 2016-05-19

## README

# maudite

**maudite** *(moe-DEET)* is a templating system using template literals. It returns
a stream of buffers, or a string, for sending the resulting data to its
destination.

`maudite` is [pretty quick](benchmarks/README.md)

## Usage

A single function is exported, which acts as a template tag. This tag returns a
function taking in a context object, which is then passed to any functions that
are inlined into the template literal.

```js
const m = require('maudite');
const template = m`Hello, ${c=>c.name}!\n`;
template({name: 'World'}).pipe(process.stdout);

// Hello, World!
```

Your inlined functions can return a buffer or a string or another template, and
these will be sent to the stream. This means you can do any kind of conditional
logic you want to determine what to render.

As a shortcut, you can simply put a property name (as a string that's parsed
with [`deep-access`](https://www.npmjs.com/package/deep-access)) for the context object, rather than a function accessing it.

```js
const m = require('maudite');
const template = m`Hello, ${'name'}!\n`;
template({name: 'World'}).pipe(process.stdout);

// Hello, World!
```

You can also use the special `m.each` function to iterate over arrays in your
context object.

```js
const m = require('maudite');
const template = m`Hello,${m.each('things', m` Thing ${c=>c.name}`)}!\n`;
template({
  things: [
    {name: '1'},
    {name: '2'}
  ]
}).pipe(process.stdout);

// Hello, Thing 1 Thing 2!
```

The first argument to `m.each` is a context accessor string (see **Accessing
Properties**, below), giving the property that is an array to iterate over. The
next argument is a template to apply to each element of the array.

To return a compiled and ready-to-go string, rather than a stream, just call the
`asString` function on the template, passing in the context object.

```js
const m = require('maudite');
const template = m`Hello, ${'name'}!\n`;
console.log(template.asString({name: 'World'}));

// Hello, World!
```

### Accessing properties

For both inline values (like `${'foo'}`) and for the first argument to `m.each`,
strings can be used to access properties of the context object. These are
dot-separated strings that are compatible with their usage in [`deep-access`][].

In addition, you can use the `@` symbol to refer to the current context object.

Here's an example, where the context object passed in is the string `'World':

```js
const m = require('maudite');
const template = m`Hello, ${'@'}!\n`;
console.log(template.asString('World'));


// Hello, World!
```

## License

See LICENSE.txt

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