jsc

package
v2.9.4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var BASE64 = true

Wether to encode and decode bytes using base64.

View Source
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 IsArray

func IsArray(value js.Value) bool

func IsDataView

func IsDataView(value js.Value) bool

func IsSlice

func IsSlice(value js.Value) bool

func IsTypedArray

func IsTypedArray(value js.Value) bool

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

func MustValuesOf(f ...interface{}) []js.Value

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 Scan added in v2.1.9

func Scan(src js.Value, dst interface{}) error

func ValueOf

func ValueOf(f interface{}) (js.Value, error)

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

func ValuesOf(f ...interface{}) ([]js.Value, error)

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.

Types

type ObjectConstraints

type ObjectConstraints interface {
	string | int | int8 | int16 | int32 | int64 |
		uint | uint8 | uint16 | uint32 | uint64 |
		float64 | float32 | bool | js.Value |
		[]byte | []interface{} | map[string]interface{} | interface{}
}

Convert a js.Value to a map[string]T.

Jump to

Keyboard shortcuts

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