js

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT Imports: 7 Imported by: 0

Documentation

Overview

Package js provides facilities based on the Otto VM for parsing and executing javascript expressions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(expr string, parameters interface{}, assets JavascriptAssets) (bool, error)

Evaluate evaluates the javascript expression with parameters applied. If scripts is non-nil, then the scripts will be evaluated in the expression's runtime context before the expression is evaluated.

func MatchEntities

func MatchEntities(expressions []string, entities []interface{}) ([]bool, error)

MatchEntities compiles the expressions supplied, and applies each one of them to each entity supplied. On the first match, success is recorded and the evaluator moves on to the next entity. A slice of bools is returned that is the same length as the slice of entities supplied, indicating match success or failure.

Errors are reported by logging only, with the log level determined by the severity of the error. Syntax and type errors are reported at error level, while attribute lookup errors are reported at debug level.

If the function cannot set up a javascript VM, or has issues setting vars, then the function returns a nil slice and a non-nil error.

func ParseExpressions

func ParseExpressions(expressions []string) error

ParseExpressions parses each JS expression and returns the first error that is encountered, or nil.

Types

type EntityFilterResult

type EntityFilterResult struct {
	Value bool
	Err   error
}

EntityFilterResult is returned by EvaluateEntityFilters

type JavascriptAssets

type JavascriptAssets interface {
	Key() string
	Scripts() (map[string]io.ReadCloser, error)
}

type SyntaxError

type SyntaxError string

SyntaxError is returned when a javascript expression could not be parsed.

func NewSyntaxError

func NewSyntaxError(err string, args ...interface{}) SyntaxError

NewSyntaxError creates a new SyntaxError.

func (SyntaxError) Error

func (s SyntaxError) Error() string

Jump to

Keyboard shortcuts

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