Skip to content

mikemaccana/dynamic-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ES6 Dynamic Templates

Build Status

Simple dynamic ES6 templates

Actual real ES6 templates. Just dynamic.

Why would I want to make ES6 templates dynamically?

Because you have a whole bunch of templates, and don't want to write a function for every possible template string. The purpose of the module is that variables are resolved later, which makes it easier to do dynamic templating. This is surprisingly tricky as this for TemplateStrings is a bit weird.

Changes since version 1

Version 1 used eval, requiring you to sanitise user input before use. While that's a commopn expectation for web development, the new version uses a regex based approach while keeping the same API.

Usage

Load the module:

const fillTemplate = require('es6-dynamic-template');

Use it (use regular quotes, not backticks, for template string):

const greeting = fillTemplate('Hi ${firstName}', {firstName: 'Joe'});

Returns:

'Hi Joe'

Tests

mocha

Issues

Everything works, AFAIK, if it doesn't, send a PR rather than complaining otherwise I will mock you.

About

Simple dynamic ES6 templates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published