Documentation ¶
Index ¶
- Constants
- Variables
- func Cast[T ObjectConstraints](value js.Value) (T, error)
- func IsArray(value js.Value) bool
- func IsDataView(value js.Value) bool
- func IsSlice(value js.Value) bool
- func IsTypedArray(value js.Value) bool
- func JSToSlice[T ObjectConstraints](arr js.Value) (array []T, errorCasting error)
- func MustValuesOf(f ...interface{}) []js.Value
- func MustValuesOfInterface(f ...interface{}) []interface{}
- func Scan(src js.Value, dst interface{}) error
- func ValueOf(f interface{}) (js.Value, error)
- func ValuesOf(f ...interface{}) ([]js.Value, error)
- func ValuesOfInterface(f ...interface{}) ([]interface{}, error)
- type ObjectConstraints
Constants ¶
const ( ErrUndefined errs.Error = "src is null or undefined" ErrNil errs.Error = "dst is nil" ErrNotPtr errs.Error = "dst is not a pointer" ErrNotValid errs.Error = "dst is not a pointer to a struct, map, or slice" ErrNotStruct errs.Error = "dst is not a pointer to a struct" ErrCannotSet errs.Error = "cannot set dst field" )
Variables ¶
var BASE64 = true
Wether to encode and decode bytes using base64.
var TINYGO bool
TINYGO is used to check if we are using tinygo as a compiler.
Functions ¶
func Cast ¶
func Cast[T ObjectConstraints](value js.Value) (T, error)
Cast a value to the correct type, return an error if the javascript value is not the correct type.
Supported types are:
- string (js.TypeString)
- int, int8, int16, int32, int64 (js.TypeNumber)
- uint, uint8, uint16, uint32, uint64 (js.TypeNumber)
- float32, float64 (js.TypeNumber)
- bool (js.TypeBoolean)
- js.Value (js.TypeObject)
- []byte (js.TypeObject)
- []interface{} (js.TypeObject)
- map[string]interface{} (js.TypeObject)
- interface{} (we don't know the type, but we can try to guess it.)
func IsDataView ¶
func IsTypedArray ¶
func JSToSlice ¶
func JSToSlice[T ObjectConstraints](arr js.Value) (array []T, errorCasting error)
Convert a js.Value array to a []interface{}.
func MustValuesOf ¶ added in v2.4.3
MustValuesOf will return the js.Value of the given values. This can be useful for inlining known-safe types.
func MustValuesOfInterface ¶ added in v2.4.8
func MustValuesOfInterface(f ...interface{}) []interface{}
MustValuesOfInterface will return the js.Value of the given values in an array of interface{}. This can be useful for inlining known-safe types.
This is a helper function, since js.(Value).Call or set will not take a slice of js.Value.
func ValueOf ¶
ValueOf will return the js.Value of the given value. It will return an error if the value is not supported.
func ValuesOf ¶ added in v2.4.3
ValuesOf will return the js.Value of the given values. It will return an error if interface{} of the value are not supported.
func ValuesOfInterface ¶ added in v2.4.8
func ValuesOfInterface(f ...interface{}) ([]interface{}, error)
ValuesOfInterface will return the js.Value of the given values in an array of interface{}. It will return an error if interface{} of the value are not supported.
This is a helper function, since js.(Value).Call or set will not take a slice of js.Value.