tagged-template-literals
v1.0.1
Published
Tagged ES6 template helper
Downloads
1,327
Readme
Tagged Template Literals
Tagged Template Literals is a base library to make your packages simpler. See the usage for example usage.
Installation
npm install --save tagged-template-literals
API
function taggedTemplateLiterals(
values: Array<string>,
strings: Array<string>,
callback: ?((param: string) => string)
): string
module.exports = taggedTemplateLiterals
Examples
import tag from 'tagged-template-literals'
import escape from 'escape-html'
import trim from 'cool-trim'
function escapeHTML(strings, ...values) {
if (strings && strings.raw) {
throw new Error('Only template strings are supported')
}
return tag(strings, values, escape)
}
const dangerous = '<script></script>'
const escaped = trim(escapeHTML`
Hello there <div>
${dangerous}
</div>
`)
console.log(escaped === `
Hello there <div>
<script></script>
</div>
`) // true
License
This project is licensed under the terms of MIT License, see the LICENSE file for more info