# @sullivan/slim

> A tiny javascript template library

Latest version **0.0.2** (published 2019-07-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sullivan/slim
pnpm add @sullivan/slim
yarn add @sullivan/slim
bun add @sullivan/slim
```

## 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.0.2 |
| Published | 2019-07-23 |
| First published | 2019-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chris Sullivan |
| Maintainers | icarus-sullivan |
| Keywords | template, js, slim, tiny |

## Links

- npm: https://www.npmjs.com/package/@sullivan/slim
- Repository: https://github.com/icarus-sullivan/slim
- npm.io page: https://npm.io/package/@sullivan/slim

## Recent versions

- 0.0.2 (latest) — 2019-07-23
- 0.0.1 — 2019-07-14

## README

![npm version](https://img.shields.io/npm/v/@sullivan/slim.svg) ![npm license](https://img.shields.io/npm/l/@sullivan/slim.svg)
# @sullivan/slim 
A very slim js template library 


## Installation

```sh
npm install @sullivan/slim --save-dev
```
or
```sh
yarn add @sullivan/slim --dev
```

## Usage

Slim can be used in two ways, as a template literal or as a function. Arguments within double brackets are processed. NOTE: whitespace will be trimmed and is not preserved. 

```
const slim = require('@sullivan/slim');

const context = {
  greeting: 'Hello',
};

slim`{{greeting}}`(context); // Hello

slim('{{greeting}}')(context); // Hello
```

### Context
The context argument MUST be an object and can contain synchronous functions. 

##### Properties
Properties are scoped to the template and anything within the double brackets will be processed as javascript. 
```
const slim = require('@sullivan/slim');

const context = {
  x: 25,
  y: 75,
};

slim('{{ x + y }}')(context); // 100
```


##### Functions
Using functions can be invoked with the context object, or within the double bracket definition. 

Example:
```
const slim = require('@sullivan/slim');

const context = {
  numbers: [1, 2, 3],
  addNumbers: (ctx) => ctx.numbers.reduce((a, i) => a + i, 0),
  add: (p1, p2) => p1 + p2,
};


const rendered = slim`
  total: {{addNumbers}}
  manual: {{ add(3, 27) }}
`(context); 
//
//  total: 6
//  manual: 30
// 
```

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