Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aleclarson/mini-hb
Tiny handlebars engine (made with TypeScript)
https://github.com/aleclarson/mini-hb
handlebars mustache rendering templates templating
Last synced: 13 days ago
JSON representation
Tiny handlebars engine (made with TypeScript)
- Host: GitHub
- URL: https://github.com/aleclarson/mini-hb
- Owner: aleclarson
- License: mit
- Created: 2018-11-14T20:25:13.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-05T16:46:36.000Z (about 6 years ago)
- Last Synced: 2025-01-03T19:05:53.118Z (19 days ago)
- Topics: handlebars, mustache, rendering, templates, templating
- Language: TypeScript
- Homepage:
- Size: 32.2 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mini-hb
[![npm](https://img.shields.io/npm/v/mini-hb.svg)](https://www.npmjs.com/package/mini-hb)
[![Build status](https://travis-ci.org/aleclarson/mini-hb.svg?branch=master)](https://travis-ci.org/aleclarson/mini-hb)
[![Coverage status](https://coveralls.io/repos/github/aleclarson/mini-hb/badge.svg?branch=master)](https://coveralls.io/github/aleclarson/mini-hb?branch=master)
[![Bundle size](https://badgen.net/bundlephobia/min/mini-hb)](https://bundlephobia.com/result?p=mini-hb)
[![Install size](https://packagephobia.now.sh/badge?p=mini-hb)](https://packagephobia.now.sh/result?p=mini-hb)
[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/alecdotbiz)TypeScript successor to [mini-handlebars](https://www.npmjs.com/package/mini-handlebars)
## Features
- [~4kB](https://bundlephobia.com/result?p=mini-hb) minified (compared to [~70kB](https://bundlephobia.com/result?p=handlebars) minified [handlebars](http://npmjs.com/package/handlebars))
- [~18kB](https://packagephobia.now.sh/result?p=mini-hb) install size (compared to [~5.8MB](https://packagephobia.now.sh/result?p=handlebars) with [handlebars](http://npmjs.com/package/handlebars))
- tiny API
- template pre-parsing
- "parse then render" in one call
- no batteries included (blocks are just local functions)
- syntax/context plugin system **(coming later)**
- 100% test coverage## Usage
```ts
import {hb} from 'mini-hb'// Use an object literal to provide variables/functions to templates.
let context = {
foo: 'foo',
test(template, context) {
// `template` is what your block contains.
// `context` is the context your block has access to.
// The return value is coerced to a string (but undefined is ignored).
return hb(template, context)
},
}// Render a template.
let template = '{{ foo }}{{ bar }}'
let result = hb(template, context)// Bind a template to `hb`
let render = hb.bind(template)
result = render(context) // "foo"// Bind a context to `hb`
render = hb.bind(context)
result = render(template) // "foo"// Bind many contexts to `hb`
render = hb.bind(context, { bar: 'bar' }, { foo: '' })
result = render(template) // "bar"// Merge contexts into a new context. (null and undefined are skipped)
context = hb(context, { bar: 'bar' }, cond ? { foo: true } : null)
```See [the tests](/spec) for more details.