mathiasbynens / jsesc

Given some data, jsesc returns the shortest possible stringified & ASCII-safe representation of that data.
https://mths.be/jsesc
MIT License
718 stars 49 forks source link

feature: use backticks as string delimiter #65

Closed milahu closed 3 years ago

milahu commented 3 years ago

input

var s = "some 'thing' ${here}"

expected

`var s = "some 'thing' $\{here}"`

actual

'var s = "some \'thing\' ${here}"'

goal: minimize number of escapes

edit: i was looking for node's util.inspect(object)

var u = require('util')

console.log(u.inspect(`var s = "some 'thing' here"`, { depth: null }))
`var s = "some 'thing' here"`

console.log(u.inspect(`var s = "some 'thing' $\{here}"`, { depth: null }))
'var s = "some \'thing\' ${here}"'
mathiasbynens commented 3 years ago

https://github.com/mathiasbynens/jsesc#quotes

milahu commented 3 years ago

aah, sorry. i got distracted by the demo where the quotes option is not exposed