js

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var False = NewBool(false)
View Source
var True = NewBool(true)

Functions

func Bundle

func Bundle(name string, url string) error

Bundle downloads the JS from the given url or local file and bundles it as a go file.

func Imports

func Imports() map[string]string

Imports returns a map of js imports.

func NewImport

func NewImport(path string, data string)

NewImport creates a new import that can be used with the #import macro.

func Require

func Require(path string, contents string) seed.Option

Require js script.

func Return

func Return(v AnyValue) func(q Ctx)

Return returns the value from the current function.

func Scripts

func Scripts(root seed.Seed) map[string]string

Scripts returns the external scripts needed by this seed.

Types

type AnyArray

type AnyArray interface {
	AnyValue
	GetArray() Array
}

AnyArray is anything that can retrieve a string.

type AnyBool

type AnyBool AnyValue

AnyBool is anything that can retrieve a bool.

type AnyFunction

type AnyFunction interface {
	AnyValue
	GetFunction() Function
}

type AnyNumber

type AnyNumber interface {
	AnyValue
	GetNumber() Number
}

AnyNumber is anything that can retrieve a number.

type AnyObject

type AnyObject interface {
	AnyValue
	GetObject() Object
}

AnyObject is anything that can retrieve a string.

type AnyPromise

type AnyPromise interface {
	AnyValue
	GetPromise() Promise
}

AnyPromise is anything that can return a promise.

type AnyScript

type AnyScript interface {
	AnyFunction
	GetScript() Script
}

type AnySet

type AnySet interface {
	AnyValue
	GetSet() Set
}

AnySet is anything that can retrieve a string.

type AnyString

type AnyString interface {
	AnyValue
	GetString() String
}

AnyString is anything that can retrieve a string.

type AnyValue

type AnyValue interface {
	GetValue() Value
	GetBool() Bool
}

AnyValue is anything that can produce a js value.

type Array

type Array struct {
	Value
}

func (Array) GetArray

func (a Array) GetArray() Array

GetArray impliments AnyArray.

func (Array) Index

func (a Array) Index(i AnyNumber) Value

Index returns the value inside the array at the given index.

type Bool

type Bool struct {
	Value
}

Bool is a javascript boolean.

func NewBool

func NewBool(literal bool) Bool

NewBool returns a new javascript boolean from a Go literal.

func Truthy

func Truthy(v AnyValue) Bool

Truthy returns a boolean from any value.

func (Bool) And

func (b Bool) And(other Bool) Bool

And returns true if both bools are true.

func (Bool) GetBool

func (b Bool) GetBool() Bool

GetBool impliments AnyBool.

func (Bool) If

func (b Bool) If(returns AnyValue) Else

func (Bool) Not

func (b Bool) Not() Bool

Not returns not bool.

func (Bool) Or

func (b Bool) Or(other Bool) Bool

Or returns true if either bools are true.

type Ctx

type Ctx func(interface{})

Ctx is a script context.

func NewCtx

func NewCtx(w io.Writer, seeds ...seed.Seed) Ctx

NewCtx returns a new ctx that writes a script to the given writer. This function takes an optional number of seeds, any options passed to this context will be applied to the given seeds.

func (Ctx) Await

func (q Ctx) Await(v AnyValue)

func (Ctx) Bool

func (Ctx) Bool(literal bool) Bool

Bool is shorthand for NewBool.

func (Ctx) Flush

func (q Ctx) Flush()

func (Ctx) If

func (q Ctx) If(condition AnyBool, do Script) ElseIfChain

func (Ctx) Number

func (Ctx) Number(literal float64) Number

Number is shorthand for NewNumber.

func (Ctx) Return

func (q Ctx) Return(v AnyValue)

Return returns the value from the current function.

func (Ctx) Run

func (q Ctx) Run(fname AnyFunction, args ...AnyValue)

Run runs the given function expression with the given arguments.

func (Ctx) String

func (Ctx) String(literal string) String

String is shorthand for NewString.

func (Ctx) Unique

func (Ctx) Unique() string

Unique returns a unique string suitable for variable names.

func (Ctx) Write

func (q Ctx) Write(b []byte) (int, error)

type Element

type Element struct {
	Value
}

Element is the most general base class from which all element objects (i.e. objects that represent elements) in a Document inherit. It only has methods and properties common to all kinds of elements. More specific classes inherit from Element. For example, the HTMLElement interface is the base interface for HTML elements, while the SVGElement interface is the basis for all SVG elements. Most functionality is specified further down the class hierarchy.

func (Element) RequestFullscreen

func (element Element) RequestFullscreen() Script

RequestFullscreen requests that the user agent switch from full-screen mode back to windowed mode.

type Else

type Else struct {
	// contains filtered or unexported fields
}

func (Else) Else

func (e Else) Else(returns AnyValue) Value

type ElseIfChain

type ElseIfChain struct {
	// contains filtered or unexported fields
}

func (ElseIfChain) Else

func (e ElseIfChain) Else(do Script)

type Function

type Function struct {
	Value
}

func Func

func Func(name string) Function

func NewFunction

func NewFunction(do Script, args ...string) Function

func NewNormalFunction

func NewNormalFunction(do Script, args ...string) Function

func (Function) Call

func (f Function) Call(args ...AnyValue) Value

func (Function) GetFunction

func (f Function) GetFunction() Function

GetFunction impliments AnyFunction.

func (Function) Run

func (f Function) Run(args ...AnyValue) Script

type NewArray

type NewArray []AnyValue

func (NewArray) GetArray

func (literal NewArray) GetArray() Array

func (NewArray) GetBool

func (literal NewArray) GetBool() Bool

func (NewArray) GetValue

func (literal NewArray) GetValue() Value

func (NewArray) String

func (array NewArray) String() string

type NewObject

type NewObject map[string]AnyValue

func (NewObject) GetBool

func (literal NewObject) GetBool() Bool

func (NewObject) GetObject

func (literal NewObject) GetObject() Object

func (NewObject) GetValue

func (literal NewObject) GetValue() Value

type Number

type Number struct {
	Value
}

Number is a javascript number.

func NewNumber

func NewNumber(literal float64) Number

NewNumber returns a new javascript number from a Go literal.

func (Number) DivideBy

func (n Number) DivideBy(b AnyNumber) Number

DivideBy returns n/b

func (Number) GetNumber

func (n Number) GetNumber() Number

GetNumber impliments AnyNumber.

func (Number) Minus

func (n Number) Minus(b AnyNumber) Number

Minus returns the two numbers subtracted together.

func (Number) ModBy

func (n Number) ModBy(b AnyNumber) Number

ModBy returns n%b

func (Number) Plus

func (n Number) Plus(b AnyNumber) Number

Plus returns the two numbers added together.

func (Number) ToString

func (n Number) ToString() String

ToString returns the number as a string.

type Object

type Object struct {
	Value
}

func (Object) Get

func (o Object) Get(property AnyString) Value

Get gets the JavaScript property p of value v.

func (Object) GetObject

func (o Object) GetObject() Object

GetObject impliments AnyObject.

func (Object) Set

func (o Object) Set(property AnyString, value AnyValue) Script

Set a property of this object.

type Promise

type Promise struct {
	Value
}

Promise is a js promise.

type Script

type Script func(Ctx)

Script is any js script.

func Append

func Append(a, b AnyScript) Script

func If

func If(condition AnyBool, do Script) Script

func Run

func Run(fname AnyFunction, args ...AnyValue) Script

Run runs the given function expression with the given arguments.

func Throw

func Throw(v AnyValue) Script

func Try

func Try(s Script) Script

func (Script) Append

func (s Script) Append(next Script) Script

Append appends two scripts to return a new script.

func (Script) Catch

func (s Script) Catch(do Script, e ...string) Script

func (Script) Else

func (s Script) Else(do Script) Script

func (Script) GetBool

func (s Script) GetBool() Bool

func (Script) GetFunction

func (s Script) GetFunction() Function

func (Script) GetScript

func (s Script) GetScript() Script

func (Script) GetValue

func (s Script) GetValue() Value

type Set

type Set struct {
	Value
}

Set is a javascript Set.

type String

type String struct {
	Value
}

String is a javascript string.

func NewString

func NewString(literal string) String

NewString returns a new javascript string from a Go literal.

func (String) Equals

func (s String) Equals(b AnyString) Bool

Equals returns true if the two strings are equal.

func (String) GetString

func (s String) GetString() String

GetString impliments AnyString.

func (String) Includes

func (s String) Includes(b AnyString) Bool

Includes determines whether one string may be found within another string, returning true or false as appropriate.

func (String) Plus

func (s String) Plus(b AnyString) String

Plus returns the two strings joined together.

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value is any js value.

func Await

func Await(v AnyValue) Value

func Call

func Call(fname AnyFunction, args ...AnyValue) Value

Call calls the given function expressionw with the given arguments.

func Global

func Global() Value

Global returns the JavaScript global object, usually "window" or "global".

func New

func New(class AnyValue, args ...AnyValue) Value

New is equivalant to calling 'new Class(args...)' in js.

func NewValue

func NewValue(format string, args ...AnyValue) Value

NewValue allows you to create a js value from a raw string.

func Null

func Null() Value

Null returns the JavaScript value "null".

func Undefined

func Undefined() Value

Undefined returns the JavaScript value "undefined".

func ValueOf

func ValueOf(literal interface{}) Value

func (Value) Call

func (v Value) Call(method string, args ...AnyValue) Value

Call calls the method on the given value.

func (Value) Equals

func (v Value) Equals(other Value) Bool

Equals returns true if the two value are equal.

func (Value) Get

func (v Value) Get(property string) Value

Get gets the JavaScript property p of value v.

func (Value) GetBool

func (v Value) GetBool() Bool

GetBool impliments AnyBool.

func (Value) GetValue

func (v Value) GetValue() Value

GetValue impliments AnyValue.

func (Value) Index

func (v Value) Index(i int) Value

Index gets the JavaScript index i of value v.

func (Value) Run

func (v Value) Run(method string, args ...AnyValue) Script

Run runs the method on the given value.

func (Value) Set

func (v Value) Set(property string, value AnyValue) Script

Set sets the JavaScript property p of value v to ValueOf(x).

func (Value) String

func (v Value) String() string

String returns the raw value.

func (Value) Var

func (v Value) Var(q Ctx) Value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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