Get unlimited public & private packages + team-based management with npm Teams.Learn more »

language-strings

1.2.3 • Public • Published

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

Keywords

none

Install

npm i language-strings

DownloadsWeekly Downloads

20

Version

1.2.3

License

WTFPL

Unpacked Size

4.53 kB

Total Files

12

Last publish

Collaborators

  • avatar