json-tag
v1.0.0
Published
Tagged template literal that escapes arguments as JSON
Downloads
2
Maintainers
Readme
json-tag
Tagged template literal that escapes arguments as JSON values
json-tag uses JSON.stringify()
to escape the template literal's arguments.
Usage:
import json from 'json-tag'
json`string: ${ 'double quote "' }`
json`number: ${ 1337 }`
json`boolean: ${ true } & ${ false }`
json`null: ${ null }`
json`array: ${ ['double quote "', null, 1337] }`
json`object: ${ { doubleQuote: '"', doubleNumber: 1.337e+3 } }`
You will get the following strings:
string: "double quote \""
number: 1337
boolean: true & false
null: null
array: ["double quote \"",null,1337]
object: {"doubleQuote":"\"","doubleNumber":1337}
It works as follows, this:
json`text ${value}`
Is essentialy this:
`text ${JSON.stringify(value)}`