1.0.3 • Published 1 year ago

jsonlit v1.0.3

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

JSON template literal tag

Template literal tag function that escapes arguments as JSON values. Zero dependency. Supports both ESM and CJS.

jlit uses JSON.stringify() to escape the template literal's arguments.

Usage:

import {jlit} from 'jlit'

jlit`string:  ${'double quote "'}`
jlit`number:  ${1337}`
jlit`boolean: ${true} & ${false}`
jlit`null:    ${null}`
jlit`array:   ${['double quote "', null, 1337]}`
jlit`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:

jlit`text ${value}`

Is essentialy this:

`text ${JSON.stringify(value)}`
1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago