jsesc.1 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. .Dd October 25, 2013
  2. .Dt jsesc 1
  3. .Sh NAME
  4. .Nm jsesc
  5. .Nd escape strings for use in JavaScript string literals
  6. .Sh SYNOPSIS
  7. .Nm
  8. .Op Fl s | -single-quotes Ar string
  9. .br
  10. .Op Fl d | -double-quotes Ar string
  11. .br
  12. .Op Fl w | -wrap Ar string
  13. .br
  14. .Op Fl 6 | -es6 Ar string
  15. .br
  16. .Op Fl e | -escape-everything Ar string
  17. .br
  18. .Op Fl j | -json Ar string
  19. .br
  20. .Op Fl p | -object Ar string
  21. .br
  22. .Op Fl p | -pretty Ar string
  23. .br
  24. .Op Fl v | -version
  25. .br
  26. .Op Fl h | -help
  27. .Sh DESCRIPTION
  28. .Nm
  29. escapes strings for use in JavaScript string literals while generating the shortest possible valid ASCII-only output.
  30. .Sh OPTIONS
  31. .Bl -ohang -offset
  32. .It Sy "-s, --single-quotes"
  33. Escape any occurences of ' in the input string as \\', so that the output can be used in a JavaScript string literal wrapped in single quotes.
  34. .It Sy "-d, --double-quotes"
  35. Escape any occurences of " in the input string as \\", so that the output can be used in a JavaScript string literal wrapped in double quotes.
  36. .It Sy "-w, --wrap"
  37. Make sure the output is a valid JavaScript string literal wrapped in quotes. The type of quotes can be specified using the
  38. .Ar -s | --single-quotes
  39. or
  40. .Ar -d | --double-quotes
  41. settings.
  42. .It Sy "-6, --es6"
  43. Escape any astral Unicode symbols using ECMAScript 6 Unicode code point escape sequences.
  44. .It Sy "-e, --escape-everything"
  45. Escape all the symbols in the output, even printable ASCII symbols.
  46. .It Sy "-j, --json"
  47. 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
  48. .Ar -d | --double-quotes
  49. and
  50. .Ar -w | --wrap
  51. settings.
  52. .It Sy "-o, --object"
  53. 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.
  54. .It Sy "-p, --pretty"
  55. Pretty-print the output for objects, using whitespace to make it more readable. Setting this flag enables the
  56. .Ar -o | --object
  57. setting.
  58. .It Sy "-v, --version"
  59. Print jsesc's version.
  60. .It Sy "-h, --help"
  61. Show the help screen.
  62. .El
  63. .Sh EXIT STATUS
  64. The
  65. .Nm jsesc
  66. utility exits with one of the following values:
  67. .Pp
  68. .Bl -tag -width flag -compact
  69. .It Li 0
  70. .Nm
  71. successfully escaped the given string and printed the result.
  72. .It Li 1
  73. .Nm
  74. wasn't instructed to escape anything (for example, the
  75. .Ar --help
  76. flag was set); or, an error occurred.
  77. .El
  78. .Sh EXAMPLES
  79. .Bl -ohang -offset
  80. .It Sy "jsesc 'foo bar baz'"
  81. Print an escaped version of the given string.
  82. .It Sy echo\ 'foo bar baz'\ |\ jsesc
  83. Print an escaped version of the string that gets piped in.
  84. .El
  85. .Sh BUGS
  86. jsesc's bug tracker is located at <https://github.com/mathiasbynens/jsesc/issues>.
  87. .Sh AUTHOR
  88. Mathias Bynens <http://mathiasbynens.be/>
  89. .Sh WWW
  90. <http://mths.be/jsesc>