JS Native Template
Installation
yarn add js-native-template
Examples
Basic
const createParser = require('js-native-template');
const parse = createParser();
(async () => {
const result = await parse('Sum: 1 + 1 = ${1+1}');
})();
With custom methods
const createParser = require('js-native-template');
const methods = {
echo: (x) => x,
asyncEcho: async (x) => x
}
const parse = createParser(methods);
(async () => {
const result = await parse('Echoes: ${echo("foo").toUpperCase()} ${asyncEcho("bar")}');
)();
Catch errors
const createParser = require('js-native-template');
const parse = createParser();
(async () => {
try {
const result = await parse('Throw error: ${nonExisting}');
} catch(err){
}
})();