fake-template

Replicate template literals' behaviour with normal strings

Usage no npm install needed!

<script type="module">
  import fakeTemplate from 'https://cdn.skypack.dev/fake-template';
</script>

README

fake-template

Who needs real templates anyway?

Installation

npm i fake-template --save

Usage

const template = require('fake-template')
const gloriousMissive = template('Dear ${name}, we found the perfect ${title} job in ${location} for you!')
console.log(gloriousMissive({ name: 'Joanna', title: 'Cosmonaut', location: 'London' }))

This is equivalent to

const name = 'Joanna', title = 'Cosmonaut', location = 'London'
console.log(`Dear ${name}, we found the perfect ${title} job in ${location} for you!`)

Contributions

Bug reports highly appreciated

PRs super welcome

TODO

For completeness' sake it would be good to support raw_strings.

Better error messages would be great as well.

Tests

Tests live in the index file in the shape of a bunch of asserts.

Tests get removed automatically at postinstall using sed.

License

MIT