Skip to content

`{{ obj.name }}` parser in JavaScript with `async` view & render support.

License

Notifications You must be signed in to change notification settings

vikiboss/mustacheee

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mustacheee

Fork from mustache.js, add async render support.

Have no test yet, use it at your own risk.

Usage

import mustache from 'mustachee'

const template = 'Hello {{name}}, {{asyncValue}}, {{#asyncRender}}asyncRender{{/asyncRender}}'

const view = {
  name: 'John',
  // async value
  asyncValue: async () => {
    return Promise.resolve('async value')
  },
  asyncRender: () => {
    // custom async render function
    return (text, render) => {
      return new Promise(resolve => {
        setTimeout(async () => {
          resolve('async-'   (await render(text))   '-async')
        }, 1000)
      })
    }
  }
}

// 1 second later: Hello John, async value, async-asyncRender-async
mustache.render(template, view).then(output => {
  console.log(output)
})

// or in async function:
// const output = await mustache.render(template, view)

License

MIT

About

`{{ obj.name }}` parser in JavaScript with `async` view & render support.

Resources

License

Stars

Watchers

Forks

Languages

  • JavaScript 58.4%
  • TypeScript 41.6%