escapes strings for use in JavaScript string literals while generating the shortest possible valid ASCII-only output.
.ShOPTIONS
.Bl-ohang-offset
.ItSy"-s, --single-quotes"
Escape any occurrences of ' in the input string as \\', so that the output can be used in a JavaScript string literal wrapped in single quotes.
.ItSy"-d, --double-quotes"
Escape any occurrences of " in the input string as \\", so that the output can be used in a JavaScript string literal wrapped in double quotes.
.ItSy"-w, --wrap"
Make sure the output is a valid JavaScript string literal wrapped in quotes. The type of quotes can be specified using the
.Ar-s|--single-quotes
or
.Ar-d|--double-quotes
settings.
.ItSy"-6, --es6"
Escape any astral Unicode symbols using ECMAScript 6 Unicode code point escape sequences.
.ItSy"-e, --escape-everything"
Escape all the symbols in the output, even printable ASCII symbols.
.ItSy"-j, --json"
Make sure the output is valid JSON. Hexadecimal character escape sequences and the \\v or \\0 escape sequences will not be used. Setting this flag enables the
.Ar-d|--double-quotes
and
.Ar-w|--wrap
settings.
.ItSy"-o, --object"
Treat the input as a JavaScript object rather than a string. Accepted values are flat arrays containing only string values, and flat objects containing only string values.
.ItSy"-p, --pretty"
Pretty-print the output for objects, using whitespace to make it more readable. Setting this flag enables the
.ItSy"-l, --lowercase-hex"
Use lowercase for alphabetical hexadecimal digits in escape sequences.
.Ar-o|--object
setting.
.ItSy"-v, --version"
Print jsesc's version.
.ItSy"-h, --help"
Show the help screen.
.El
.ShEXITSTATUS
The
.Nmjsesc
utility exits with one of the following values:
.Pp
.Bl-tag-widthflag-compact
.ItLi0
.Nm
successfully escaped the given string and printed the result.
.ItLi1
.Nm
wasn't instructed to escape anything (for example, the
.Ar--help
flag was set); or, an error occurred.
.El
.ShEXAMPLES
.Bl-ohang-offset
.ItSy"jsesc 'foo bar baz'"
Print an escaped version of the given string.
.ItSyecho\'foobarbaz'\|\jsesc
Print an escaped version of the string that gets piped in.
.El
.ShBUGS
jsesc's bug tracker is located at <https://github.com/mathiasbynens/jsesc/issues>.