language-strings
v1.2.3
Published
Automatically escape strings for several languages using ES6 template literals
Downloads
7
Readme
Language Strings
Interpolate safely in several languages using ES6 template literals.
const strings = require('language-strings')
strings.html`<div>${unsafeValue}</div>`
strings.shell`echo ${unsafeValue} | xargs...`
strings.css`content: "${unsafeValue}"`
strings.css`background: url(data:image/svg+xml,${svg})`
strings.url`/foo/bar/${valueWithMaybeSlashes}`
You can also require the functions individually to save space if you're writing frontend code.
const html = require('language-strings/html')
html`<span>${unsafeValue}</span>`
You can mark unsafe values that are to be put directly into the string by using require('language-strings').unsafe
or require('language-strings/unsafe')()
const html = require('language-strings/html')
const unsafe = require('language-strings/unsafe')
html`<title>${"hello world"}</title><body>${unsafe(userInput)}</body>`