viewpoint-js-core 0.2.1

Core types for viewpoint-js macro
Documentation

Core types for the viewpoint-js macro.

This crate provides the [ToJsValue] trait used for interpolating Rust values into JavaScript code via the js! macro, as well as utilities for escaping strings for use in JavaScript.

Example

use viewpoint_js_core::{ToJsValue, escape_js_string, escape_for_css_attr};

// ToJsValue for interpolation
assert_eq!(42.to_js_value(), "42");
assert_eq!(true.to_js_value(), "true");
assert_eq!("hello".to_js_value(), r#""hello""#);

// Direct string escaping
assert_eq!(escape_js_string("hello"), r#""hello""#);

// CSS attribute selector escaping (for use inside JS strings)
assert_eq!(escape_for_css_attr("my-id"), r#"\"my-id\""#);