jsutil

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: MIT Imports: 5 Imported by: 0

README

go-jsutil

Go Reference

  • go-jsutil is a set of utilities for Go programs that communicate with JavaScript via syscall/js.
    • This package is a separated version of JavaScript-related utilities developed in syumai/workers.

Installation

go get github.com/syumai/go-jsutil

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayFrom

func ArrayFrom(v js.Value) js.Value

ArrayFrom calls Array.from to given argument and returns result Array.

func AwaitPromise

func AwaitPromise(promiseVal js.Value) (js.Value, error)

func ConvertReadableStreamToReadCloser

func ConvertReadableStreamToReadCloser(stream js.Value) io.ReadCloser

ConvertReadableStreamToReadCloser converts ReadableStream to io.ReadCloser.

func ConvertReaderToReadableStream

func ConvertReaderToReadableStream(reader io.ReadCloser) js.Value

ConvertReaderToReadableStream converts io.ReadCloser to ReadableStream.

func DateToTime

func DateToTime(v js.Value) (time.Time, error)

DateToTime converts JavaScript side's Data object into time.Time.

func Error

func Error(msg string) js.Value

func Errorf

func Errorf(format string, args ...any) js.Value

func MaybeDate

func MaybeDate(v js.Value) (time.Time, error)

MaybeDate returns time.Time value of given JavaScript Date value or returns nil if the value is undefined.

func MaybeInt

func MaybeInt(v js.Value) int

MaybeInt returns int value of given JavaScript value or returns nil if the value is undefined.

func MaybeString

func MaybeString(v js.Value) string

MaybeString returns string value of given JavaScript value or returns nil if the value is undefined.

func NewObject

func NewObject() js.Value

func NewPromise

func NewPromise(fn js.Func) js.Value

func NewUint8Array

func NewUint8Array(size int) js.Value

func StrRecordToMap

func StrRecordToMap(v js.Value) map[string]string

StrRecordToMap converts JavaScript side's Record<string, string> into map[string]string.

func TimeToDate

func TimeToDate(t time.Time) js.Value

TimeToDate converts Go side's time.Time into Date object.

Types

type RawJSBodyGetter

type RawJSBodyGetter interface {
	GetRawJSBody() js.Value
}

type RawJSBodyWriter

type RawJSBodyWriter interface {
	WriteRawJSBody(body js.Value)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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