js

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package js runs the flow format's JavaScript: ${...} expressions, runScript files and evalScript, with these semantics:

  • each evaluation runs as (function(){ return eval(src) })() in strict mode;
  • before each evaluation, globals other than the permanent ones are deleted and the current env variables are injected as string globals;
  • undeclared names read as undefined (so ${X || 'default'} works);
  • output, tb (also as `maestro`, for Maestro flows), json, http, faker, relativePoint and console persist;
  • setTimeout, setInterval, clearTimeout and clearInterval exist: an evaluation runs its timers after its own code, before it returns (see timers.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Display

func Display(v goja.Value) string

Display renders a value the way the reference JavaScript engine's toString does: strings raw, objects in display form ({a: 1}, [1, 2]), not JSON.

func RandomCity

func RandomCity() string

func RandomColor

func RandomColor() string

func RandomCountry

func RandomCountry() string

func RandomEmail

func RandomEmail() string

func RandomNumber

func RandomNumber(length int) string

RandomNumber is a number with `length` digits (no leading zero).

func RandomPersonName

func RandomPersonName() string

func RandomText

func RandomText(length int) string

RandomText is `length` random lowercase letters.

func Truthy

func Truthy(s string) bool

Truthy is the format's rule for a condition's `true:` value after interpolation.

Types

type Engine

type Engine struct {

	// Log receives console.log lines from scripts whose Scope has no Log of its own.
	Log func(string)

	// ScriptDir is where http multipartForm filePath resolves; set by runScript.
	ScriptDir string
	// contains filtered or unexported fields
}

Engine is one flow run's JavaScript context. It is safe for concurrent use: multi-device flows share one engine (and so one `output`) across devices.

func New

func New(platform string) *Engine

func (*Engine) Eval

func (e *Engine) Eval(src string, sc *Scope) (goja.Value, error)

Eval evaluates one expression or script and returns its value.

func (*Engine) Interpolate

func (e *Engine) Interpolate(s string, sc *Scope) (string, error)

Interpolate replaces every ${...} in s with its evaluated value, using the format's rule: the expression runs to the last "}" before the next "$" (it cannot contain "$"), and \${...} is kept literally (without the backslash).

func (*Engine) Output

func (e *Engine) Output() map[string]any

Output returns the `output` object exported to Go values (for reports and agents).

func (*Engine) RunScript

func (e *Engine) RunScript(src, dir string, sc *Scope) error

RunScript runs a runScript file's source (its result is ignored).

type Error

type Error struct{ Msg string }

Error is a JavaScript error. It is fatal even for optional commands.

func (*Error) Error

func (e *Error) Error() string

type Scope

type Scope struct {
	Env        map[string]string
	Platform   string
	CopiedText *string
	// Log receives this evaluation's console.log lines (nil: the engine's Log).
	Log func(string)
}

Scope is what one evaluation sees: the device's env variables, its platform and its clipboard. Multi-device flows share one Engine (one `output`) with a Scope per device.

Jump to

Keyboard shortcuts

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