1.0.0 • Published 6 years ago

iter-stache v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

tokenstache

A tiny tokenizer for handlebars variables

Table of Contents

Install

This project uses node and npm. Go check them out if you don't have them locally installed.

npm install --save tokenstache

Then with a module bundler like webpack or rollup, use as you would anything else:

import { tokenize } from 'tokenstache'

The UMD build is also available on unpkg:

<script src="//unpkg.com/tokenstache/dist/tokenstache.umd.js"></script>

You can find the library on window.tokenstache.

Usage

import { tokenize } from 'tokenstache'
let arr = tokenize(`hello {{user}}`, {user: `jim`});  // outputs: [`hello `, `jim`]

API

Table of Contents

tokenize

Tokenizes a string that contains handlebars and tries to resolve it

Parameters

  • template String The template containing one or more {{variableNames}} every variable
  • view (Object | Function) An object or function that will resolve the values for every variable names that is used in the template. If it's omitted, it'll be set to an empty object essentially removing all {{varName}}s in the template. (optional, default {})

Examples

let arr = tokenize(`hello {{user}}`, {user: `jim`});  // outputs: [`hello `, `jim`]

Returns Array Template where its variable names replaced with corresponding values.

Reporting Issues

Found a problem? Want a new feature? First of all see if your issue or idea has already been reported. If don't, just open a new clear and descriptive issue.

License

MIT License © Cyrus Venn Casada