jsutil

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 3 Imported by: 0

README

JSUtil

Go Report Card Documentation GitHub issues license

A small vanilla-go library to provide type-safety and accelerate development in WASM environments.

Documentation

Index

Constants

This section is empty.

Variables

TruthyTypes is a set (slice) of all js.Type which can be treated as a boolean.

Functions

func AssertTypeEquals

func AssertTypeEquals(jsValue js.Value, jsType js.Type) error

AssertTypeEquals returns nil if a given JavaScript value conforms to the given type.

func AssertTypeOneOf

func AssertTypeOneOf(jsValue js.Value, jsTypes ...js.Type) error

AssertTypeOneOf returns nil if a given JavaScript value conforms to one the given types

func BytesToJs added in v1.0.0

func BytesToJs(data []byte) js.Value

JsToBytes converts a Go byte slice to a JavaScript Uint8Array.

func Get

func Get(expr string) (js.Value, error)

Get retrieves an expression from the global scope.

func GetBoolean

func GetBoolean(expr string) (bool, error)

GetBoolean retrieves a type-checked boolean from the global scope.

func GetFloat

func GetFloat(expr string) (float64, error)

GetFloat retrieves a type-checked float from the global scope.

func GetFromScope

func GetFromScope(scope js.Value, expr string) (js.Value, error)

GetFromScope retrieves an expression from the given scope.

func GetFunction added in v0.0.2

func GetFunction(expr string) (js.Value, error)

GetFunction retrieves a type-checked function from the global scope.

func GetInt

func GetInt(expr string) (int, error)

GetInt retrieves an type-checked integer from the global scope.

func GetString

func GetString(expr string) (string, error)

GetString retrieves a type-checked string from the global scope.

func GetTruthyBoolean

func GetTruthyBoolean(expr string) (bool, error)

GetTruthyBoolean retrieves a type-checked (truthy) boolean from the global scope.

func Invoke

func Invoke(fn js.Value, args ...any) (js.Value, error)

Invoke invokes a type-checked function with the given arguments.

func InvokeFunction

func InvokeFunction(expr string, args ...any) (js.Value, error)

InvokeFunction invokes a type-checked function from the global scope with the given arguments.

func JsCopyBytes added in v1.0.0

func JsCopyBytes(data js.Value, dst []byte) (int, error)

JsCopyBytes loads a Uint8Array or Uint8ClampedArray to a byte slice. It returns the number of bytes copied, which will be the minimum of the lengths of data and dst.

func JsToBytes added in v1.0.0

func JsToBytes(data js.Value) ([]byte, error)

JsToBytes converts a JavaScript Uint8Array or Uint8ClampedArray to a Go byte slice.

func SetGlobalProperties added in v1.0.0

func SetGlobalProperties(kv map[string]any)

SetGlobalProperties sets propreties on the global object.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL