Create template strings that are lazy and reusable.
npm install lazy-template> Create template strings that are lazy and reusable.
``js
const lazy = require('lazy-template')
// Create a lazy template string.
const greet = lazyHello ${0}. How is ${1}?
// Use the returned function to compile.
greet([ 'Earth', 'the weather' ])
// => 'Hello Earth. How is the weather?'
greet([ 'Mars', 'Jamen' ])
// => 'Hello Mars. How is Jamen?'
`
This module is built with pixie. You can use array indexes or object keys for the points. Or just provide a different compile function all together.
`sh`
$ npm install --save lazy-template
Create a lazy template string. Returns a compile function, which when called returns the concatenated string.
`javascriptHello ${0}. How are ${1}?
// Using array indexes:
const compile = lazy
// Using object keys:
const compile = lazyHello ${'world'}. How is ${'thing'}?`
Compile the "lazy string" using some data. Returns resulting string.
- data (Array|Object): Data to use in your template.Function
- compile (): A custom function to replace pixie.compile
`jsHello ${0}.
const compile = lazy
compile([ 'Earth' ])
// => 'Hello Earth.'
const compile = lazyHello ${'world'}.
compile({ world: 'Mars' });
// => 'Hello Mars.'
const compile = lazyHello ${0}. How is ${1}?template
compile([ 'Pluto', 'Jamen' ], function (template, data) {
// Compile and data``
// Return result
})
MIT © Jamen Marz