escape_js_string_single

Function escape_js_string_single 

Source
pub fn escape_js_string_single(s: &str) -> String
Expand description

Escape a string for use in a single-quoted JavaScript string literal.

Returns a single-quoted JavaScript string with proper escaping. This is useful when you need to embed a string in JavaScript that uses single quotes (e.g., in template literals or when double quotes are used for HTML attributes).

ยงExample

use viewpoint_js_core::escape_js_string_single;

assert_eq!(escape_js_string_single("hello"), "'hello'");
assert_eq!(escape_js_string_single("it's fine"), r"'it\'s fine'");
assert_eq!(escape_js_string_single(r#"say "hi""#), r#"'say "hi"'"#);