Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time. Cannot retrieve contributors at this time
25 lines (20 sloc) 523 Bytes
const assert = require('assert')
module.exports = maxstache
// Minimalist mustache template replacement
// (str, obj) -> null
function maxstache (str, ctx) {
ctx = ctx || {}
assert.equal(typeof str, 'string')
assert.equal(typeof ctx, 'object')
const tokens = str.split(/\{\{|\}\}/)
const res = tokens.map(parse(ctx))
return res.join('')
}
// parse a token
// obj -> (str, num) -> str
function parse (ctx) {
return function parse (token, i) {
if (i % 2 === 0) return token
return ctx[token]
}
}
You can’t perform that action at this time.