Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
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.