language-strings

Automatically escape strings for several languages using ES6 template literals

Usage no npm install needed!

<script type="module">
  import languageStrings from 'https://cdn.skypack.dev/language-strings';
</script>

README

Language Strings

Build Status Coverage Status

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>`