jlib

package
v0.0.0-...-3a454c3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package jlib implements the JSONata function library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(v1, v2 reflect.Value) (interface{}, error)

Append (golint)

func Average

func Average(v reflect.Value) (float64, error)

Average returns the mean of an array of numbers. If the array is empty, Average returns 0 and an undefined error.

func Base64Decode

func Base64Decode(s string) (string, error)

Base64Decode returns the string represented by a base 64 string.

func Base64Encode

func Base64Encode(s string) (string, error)

Base64Encode returns the base 64 encoding of a string.

func Boolean

func Boolean(v reflect.Value) bool

Boolean (golint)

func Contains

func Contains(s string, pattern StringCallable) (bool, error)

Contains returns true if the source string matches a given pattern. The pattern can be a string or a regular expression.

func Count

func Count(v reflect.Value) int

Count (golint)

func DecodeURL

func DecodeURL(s string) (string, error)

DecodeURL decodes a Uniform Resource Locator (URL) See https://docs.jsonata.org/string-functions#decodeurl and https://docs.jsonata.org/string-functions#decodeurlcomponent

func Distinct

func Distinct(v reflect.Value) interface{}

Distinct returns the values passed in with any duplicates removed.

func Each

func Each(obj reflect.Value, fn jtypes.Callable) (interface{}, error)

Each applies the function fn to each name/value pair in the object obj and returns the results in an array. The order of the items in the array is undefined.

obj must be a map or a struct. If it is a struct, any unexported fields are ignored.

fn must be a Callable that takes one, two or three arguments. The first argument is the value of a name/value pair. The second and third arguments, if applicable, are the value and the source object respectively.

func EncodeURL

func EncodeURL(s string) (string, error)

EncodeURL decodes a Uniform Resource Locator (URL) See https://docs.jsonata.org/string-functions#encodeurl

func EncodeURLComponent

func EncodeURLComponent(s string) (string, error)

EncodeURLComponent decodes a component of a Uniform Resource Locator (URL) and https://docs.jsonata.org/string-functions#encodeurlcomponent

func Exists

func Exists(v reflect.Value) bool

Exists (golint)

func Filter

func Filter(v reflect.Value, f jtypes.Callable) (interface{}, error)

Filter (golint)

func FormatBase

func FormatBase(value float64, base jtypes.OptionalFloat64) (string, error)

FormatBase returns the string representation of a number in the optional base argument. If specified, the base must be between 2 and 36. By default, FormatBase uses base 10.

func FormatNumber

func FormatNumber(value float64, picture string, options jtypes.OptionalValue) (string, error)

FormatNumber converts a number to a string, formatted according to the given picture string. See the XPath function format-number for the syntax of the picture string.

https://www.w3.org/TR/xpath-functions-31/#formatting-numbers

The optional third argument defines various formatting options such as the decimal separator and grouping separator. See the XPath documentation for details.

https://www.w3.org/TR/xpath-functions-31/#defining-decimal-format

func FromMillis

func FromMillis(ms int64, picture jtypes.OptionalString, tz jtypes.OptionalString) (string, error)

FromMillis (golint)

func Join

func Join(values reflect.Value, separator jtypes.OptionalString) (string, error)

Join concatenates an array of strings into a single string. The optional second parameter is a separator inserted between each pair of values.

func Keys

func Keys(obj reflect.Value) (interface{}, error)

Keys returns an array of the names in the object obj. The order of the returned items is undefined.

obj must be a map, a struct or an array. If obj is a map, its keys must be of type string. If obj is a struct, any unexported fields are ignored. And if obj is an array, Keys returns the unique set of names from each object in the array.

func Map

func Map(v reflect.Value, f jtypes.Callable) (interface{}, error)

Map (golint)

func Match

func Match(s string, pattern jtypes.Callable, limit jtypes.OptionalInt) ([]map[string]interface{}, error)

Match returns an array of objects describing matches of a regular expression in the source string. Each object in the array has the following fields:

match - the substring matched by the regex
index - the starting offset of this match
groups - any captured groups for this match

The optional third argument specifies the maximum number of matches to return. By default, Match returns all matches.

func Max

func Max(v reflect.Value) (float64, error)

Max returns the largest value in an array of numbers. If the array is empty, Max returns 0 and an undefined error.

func Merge

func Merge(objs reflect.Value) (interface{}, error)

Merge merges an array of objects into a single object that contains all of the name/value pairs from the array objects. If a name appears multiple times, values from objects later in the array override those from earlier.

objs must be an array of maps or structs. Maps must have keys of type string. Unexported struct fields are ignored.

func Min

func Min(v reflect.Value) (float64, error)

Min returns the smallest value in an array of numbers. If the array is empty, Min returns 0 and an undefined error.

func Not

func Not(v reflect.Value) bool

Not (golint)

func Number

func Number(value StringNumberBool) (float64, error)

Number converts values to numbers. Numeric values are returned unchanged. Strings in legal JSON number format are converted to the number they represent. Boooleans are converted to 0 or 1. All other types trigger an error.

func ObjMerge

func ObjMerge(i1, i2 interface{}) interface{}

ObjMerge - merge two map[string]interface{} objects together - if they have unique keys

func Pad

func Pad(s string, width int, chars jtypes.OptionalString) string

Pad returns a string padded to the specified number of characters. If the width is greater than zero, the string is padded to the right. If the width is less than zero, the string is padded to the left. The optional third argument specifies the characters used for padding. The default padding character is a space.

func Power

func Power(x, y float64) (float64, error)

Power returns x to the power of y.

func Random

func Random() float64

Random returns a random floating point number between 0 and 1.

func Reduce

func Reduce(v reflect.Value, f jtypes.Callable, init jtypes.OptionalValue) (interface{}, error)

Reduce (golint)

func Replace

func Replace(src string, pattern StringCallable, repl StringCallable, limit jtypes.OptionalInt) (string, error)

Replace returns a copy of the source string with zero or more instances of the given pattern replaced by the value provided. The pattern can be a string or a regular expression. The optional fourth argument specifies the maximum number of replacements to make. By default, all instances of pattern are replaced.

If pattern is a string, the replacement must also be a string. If pattern is a regular expression, the replacement can be a string or a Callable.

When replacing a regular expression with a string, the replacement string can refer to the matched value with $0 and any captured groups with $N, where N is the order of the submatch (e.g. $1 is the first submatch).

When replacing a regular expression with a Callable, the Callable must take a single argument and return a string. The argument is an object of the same form returned by Match.

func Reverse

func Reverse(v reflect.Value) (interface{}, error)

Reverse (golint)

func Round

func Round(x float64, prec jtypes.OptionalInt) float64

Round rounds its input to the number of decimal places given in the optional second parameter. By default, Round rounds to the nearest integer. A negative precision specifies which column to round to on the left hand side of the decimal place.

func Shuffle

func Shuffle(v reflect.Value) interface{}

Shuffle (golint)

func Sift

func Sift(obj reflect.Value, fn jtypes.Callable) (interface{}, error)

Sift returns a map containing name/value pairs from the object obj that satisfy the predicate function fn.

obj must be a map or a struct. If it is a map, the keys must be of type string. If it is a struct, any unexported fields are ignored.

fn must be a Callable that takes one, two or three arguments. The first argument is the value of a name/value pair. The second and third arguments, if applicable, are the value and the source object respectively.

func SimpleJoin

func SimpleJoin(v, v2 reflect.Value, field1, field2 string) (interface{}, error)

SimpleJoin - a multi-key multi-level full OR join - very simple and useful in certain circumstances

func Single

func Single(v reflect.Value, f jtypes.Callable) (interface{}, error)

Single returns the one and only one value in the array parameter that satisfy the function predicate (i.e. function returns Boolean true when passed the value). Returns an error if the number of matching values is not exactly one. https://docs.jsonata.org/higher-order-functions#single

func Sort

func Sort(v reflect.Value, swap jtypes.OptionalCallable) (interface{}, error)

Sort (golint)

func Split

func Split(s string, separator StringCallable, limit jtypes.OptionalInt) ([]string, error)

Split returns an array of substrings generated by splitting a string on the provided separator. The separator can be a string or a regular expression.

If the separator is not present in the source string, Split returns a single-value array containing the source string. If the separator is an empty string, Split returns an array containing one element for each character in the source string.

The optional third argument specifies the maximum number of substrings to return. By default, Split returns all substrings.

func Spread

func Spread(v reflect.Value) (interface{}, error)

Spread (golint)

func Sqrt

func Sqrt(x float64) (float64, error)

Sqrt returns the square root of a number. It returns an error if the number is less than zero.

func String

func String(value interface{}) (string, error)

String converts a JSONata value to a string. Values that are already strings are returned unchanged. Functions return empty strings. All other types return their JSON representation.

func Substring

func Substring(s string, start int, length jtypes.OptionalInt) string

Substring returns the portion of a string starting at the given (zero-indexed) offset. Negative offsets count from the end of the string, e.g. a start position of -1 returns the last character. The optional third argument controls the maximum number of characters returned. By default, Substring returns all characters up to the end of the string.

func SubstringAfter

func SubstringAfter(s, substr string) string

SubstringAfter returns the portion of a string that follows the first occurrence of the given substring. If the substring is not present, SubstringAfter returns the full string.

func SubstringBefore

func SubstringBefore(s, substr string) string

SubstringBefore returns the portion of a string that precedes the first occurrence of the given substring. If the substring is not present, SubstringBefore returns the full string.

func Sum

func Sum(v reflect.Value) (float64, error)

Sum returns the total of an array of numbers. If the array is empty, Sum returns 0.

func ToMillis

func ToMillis(s string, picture jtypes.OptionalString, tz jtypes.OptionalString) (int64, error)

ToMillis (golint)

func Trim

func Trim(s string) string

Trim replaces consecutive whitespace characters in a string with a single space and trims spaces from the ends of the resulting string.

func TypeOf

func TypeOf(x interface{}) (string, error)

TypeOf implements the jsonata $type function that returns the data type of the argument

func Unescape

func Unescape(input string) (interface{}, error)

Unescape an escaped json string into JSON (once)

func Zip

func Zip(vs ...reflect.Value) (interface{}, error)

Zip (golint)

Types

type ErrType

type ErrType uint

ErrType (golint)

const (
	ErrNaNInf ErrType
)

ErrNanInf (golint)

type Error

type Error struct {
	Type ErrType
	Func string
}

Error (golint)

func (Error) Error

func (e Error) Error() string

Error (golint)

type StringCallable

type StringCallable reflect.Value

StringCallable (golint)

func (StringCallable) ValidTypes

func (StringCallable) ValidTypes() []reflect.Type

ValidTypes (golint)

type StringNumberBool

type StringNumberBool reflect.Value

StringNumberBool (golint)

func (StringNumberBool) ValidTypes

func (StringNumberBool) ValidTypes() []reflect.Type

ValidTypes (golint)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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