npm install js-string-escape
jsStringEscape =console// => "Quotes (\", \'), newlines (\n), etc."
In other words, given any string
s, the following invariants hold:
=== s=== s
eval expressions are safe with untrusted strings
Non-strings will be cast to strings.
This library has been checked against ECMAScript 5.1 and tested against all Unicode code points.
Note that the returned string is not necessarily valid JSON, since JSON
disallows control characters, and
\' is illegal in JSON.