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: 4 months 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 (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-05T16:46:36.000Z (over 6 years ago)
- Last Synced: 2025-01-03T19:05:53.118Z (4 months 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
[](https://www.npmjs.com/package/mini-hb)
[](https://travis-ci.org/aleclarson/mini-hb)
[](https://coveralls.io/github/aleclarson/mini-hb?branch=master)
[](https://bundlephobia.com/result?p=mini-hb)
[](https://packagephobia.now.sh/result?p=mini-hb)
[](https://github.com/prettier/prettier)
[](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.