Arrow keys: ← previous · → next 29 of 35
@nodedk/template
0.3.2 stable

template#

An HTML template tag that joins arrays and omits optional values.

Install#

npm i @nodedk/template

Usage#

var { html } = require('@nodedk/template')

var items = ['One', 'Two']
var page = html`
  <ul>
    ${items.map((item) => html`<li>${item}</li>`)}
  </ul>
`

console.log(page)

API#

html(strings, ...values)#

Use as a tagged template: html`...` . strings is the template's string array; each interpolated value follows as an argument. Returns a string synchronously.

  • Arrays are joined with newlines.
  • null, undefined, true, and false become empty strings.
  • Other values are converted to strings.
  • Text is inserted as provided; escape dynamic plain text before interpolation.
var { html } = require('@nodedk/template')

console.log(html`<p>${false}</p>`) // <p></p>
console.log(html`<p>${0}</p>`) // <p>0</p>
console.log(html`${['one', 'two']}`) // 'one\ntwo'

Created by Vidar Eldøy