Dead simple limited mustache compiler
npm install --save mustache-simple
- Support nested object map
- Two types of behavior. Full/Partial compile
compileAll
remove all unmatched mustachescompileMatch
don't touch unmatched mustaches. In case pre-preocess partiallyfalse
,null
will be ''undefined
is treated as unmatched- No filter, No escape
const mustache = require('mustache-simple')
const config = {
foo: 'bar',
hello: 'world',
users: {
bob: {
age: 23
}
}
}
const parser = mustache.compileMatch(config)
const res = parser('The foo is {{foo}}, hello {{hello}}\n Age of bob is {{users.bob.age}}')
// The foo is bar, hello world\n Age of bob is 23
You can give allowed list of words. Only they are compiled. others will not be changed at all
const parser2 = mustache.compileMatch(config, ['foo', 'users.bob.age'])
const res = parser('The foo is {{foo}}, hello {{hello}}\n Age of bob is {{users.bob.age}}')
// The foo is bar, hello {{hello}}\n Age of bob is 23