js-string-escape
Escape a string for use as a JavaScript string literal body.
Escapes the characters that aren't valid inside a single- or double-quoted JavaScript string
literal: ", ', \, and the line terminators \n, \r, U+2028, and U+2029.
Everything else passes through unchanged. A faithful Rust port of the
js-string-escape npm package.
- Zero dependencies,
#![no_std] - Differential-tested against the reference
js-string-escapeimplementation
Install
[]
= "0.1"
Usage
use js_string_escape;
assert_eq!;
assert_eq!;
// Tabs, other control characters, and non-ASCII pass through:
assert_eq!;
For richer escaping (ASCII-only output, JSON mode, backtick quotes, …) see
jsesc.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of MIT or Apache-2.0 at your option.