Skip to main content

Module js

Module js 

Source
Expand description

JavaScript string and number built-ins that upstream code relies on.

Use these instead of Rust equivalents when porting: they differ in edge cases (parseInt("12px") is 12; " x\u{FEFF}".trim() removes the BOM; substring counts UTF-16 units).

Functionsยง

is_js_whitespace
JS WhiteSpace + LineTerminator, as used by String.prototype.trim.
js_parse_float
parseFloat(s). Returns NaN if no number prefix.
js_parse_int
parseInt(s) (radix 10). None is NaN. Saturates instead of losing precision past i64.
js_substring_from
s.substring(start) where start counts UTF-16 units.
js_trim
s.trim().
utf16_to_byte_offset
Byte offset of the units-th UTF-16 code unit in s (clamped to the end, and moved forward to a char boundary if it falls inside a surrogate pair).