Skip to main content

Crate js_sys

Crate js_sys 

Source
Expand description

Bindings to JavaScript’s standard, built-in objects, including their methods and properties.

This does not include any Web, Node, or any other JS environment APIs. Only the things that are guaranteed to exist in the global scope by the ECMAScript standard.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects

§A Note About camelCase, snake_case, and Naming Conventions

JavaScript’s global objects use camelCase naming conventions for functions and methods, but Rust style is to use snake_case. These bindings expose the Rust style snake_case name. Additionally, acronyms within a method name are all lower case, where as in JavaScript they are all upper case. For example, decodeURI in JavaScript is exposed as decode_uri in these bindings.

§A Note About toString and to_js_string

JavaScript’s toString() method is exposed as to_js_string() in these bindings to avoid confusion with Rust’s ToString trait and its to_string() method. This allows types to implement both the Rust Display trait (which provides to_string() via ToString) and still expose the JavaScript toString() functionality.

Re-exports§

pub use wasm_bindgen;

Modules§

Atomics
The Atomics object provides atomic operations as static methods. They are used with SharedArrayBuffer objects.
Intl
JSON
The JSON object contains methods for parsing JavaScript Object Notation (JSON) and converting values to JSON. It can’t be called or constructed, and aside from its two method properties, it has no interesting functionality of its own.
Math
Reflect
WebAssembly

Structs§

Array
ArrayBuffer
ArrayBufferOptions
ArrayIntoIter
Iterator returned by Array::into_iter
ArrayIter
Iterator returned by Array::iter
ArrayTuple
AsyncGenerator
AsyncIterator
Any object that conforms to the JS async iterator protocol. For example, something returned by myObject[Symbol.asyncIterator]().
BigInt
BigInt64Array
BigUint64Array
Boolean
DataView
Date
Error
EvalError
Float32Array
Float64Array
Function
Function represents any generic Function in JS, by treating all arguments as JsValue.
Generator
Int8Array
Int16Array
Int32Array
IntoIter
An iterator over the JS Symbol.iterator iteration protocol.
Iter
An iterator over the JS Symbol.iterator iteration protocol.
Iterator
Any object that conforms to the JS iterator protocol. For example, something returned by myArray[Symbol.iterator]().
IteratorNext
The result of calling next() on a JS iterator.
JsOption
A nullable JS value of type T.
JsString
Map
Null
The JavaScript null value.
Number
Object
Promise
The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.
PromiseState
The PromiseState object represents the the status of the promise, as used in allSettled.
PropertyDescriptor
Proxy
RangeError
The RangeError object indicates an error when a value is not in the set or range of allowed values.
ReferenceError
The ReferenceError object represents an error when a non-existent variable is referenced.
RegExp
RegExpMatchArray
The result array from RegExp.exec() or String.matchAll().
Set
SharedArrayBuffer
Symbol
SyntaxError
A SyntaxError is thrown when the JavaScript engine encounters tokens or token order that does not conform to the syntax of the language when parsing code.
TryFromIntError
The error type returned when a checked integral type conversion fails.
TypeError
The TypeError object represents an error when a value is not of the expected type.
Uint8Array
Uint8ClampedArray
Uint16Array
Uint32Array
Undefined
The JavaScript undefined value.
UriError
The URIError object represents an error when a global URI handling function was used in a wrong way.
WeakMap
WeakRef
WeakSet

Traits§

AsyncIterable
Trait for types known to implement the iterator protocol on Symbol.asyncIterator
FunctionIntoClosure
Iterable
Trait for JavaScript types that implement the iterable protocol via Symbol.iterator.
JsArgs
Trait for argument tuples that can call or bind a Function<T>.
JsFunction
JsFunction1
JsFunction2
JsFunction3
JsFunction4
JsFunction5
JsFunction6
JsFunction7
JsFunction8
JsGeneric
A convenience trait for types that erase to JsValue.
JsTuple
Base trait for tuple types.
JsTuple1
JsTuple2
JsTuple3
JsTuple4
JsTuple5
JsTuple6
JsTuple7
JsTuple8
Promising
Marker trait for types which represent Resolution or Promise<Resolution>.
TypedArray

Functions§

decode_uri
The decodeURI() function decodes a Uniform Resource Identifier (URI) previously created by encodeURI or by a similar routine.
decode_uri_component
The decodeURIComponent() function decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.
encode_uri
The encodeURI() function encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two “surrogate” characters).
encode_uri_component
The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two “surrogate” characters).
escape
The escape() function computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.
eval
The eval() function evaluates JavaScript code represented as a string.
global
Returns a handle to the global scope object.
is_finite
The global isFinite() function determines whether the passed value is a finite number. If needed, the parameter is first converted to a number.
parse_float
The parseFloat() function parses an argument and returns a floating point number, or NaN on error.
parse_int
The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems), or NaN on error.
try_iter
Create an iterator over val using the JS iteration protocol and Symbol.iterator.
unescape
The unescape() function computes a new string in which hexadecimal escape sequences are replaced with the character that it represents. The escape sequences might be introduced by a function like escape. Usually, decodeURI or decodeURIComponent are preferred over unescape.

Attribute Macros§

wasm_bindgen
A list of all the attributes can be found here: https://wasm-bindgen.github.io/wasm-bindgen/reference/attributes/index.html