Documentation ¶
Overview ¶
Package jlib implements the JSONata function library.
Index ¶
- Constants
- func Append(v1, v2 reflect.Value) (interface{}, error)
- func Average(v reflect.Value) (float64, error)
- func Base64Decode(s string) (string, error)
- func Base64Encode(s string) (string, error)
- func Boolean(v reflect.Value) bool
- func Contains(s string, pattern StringCallable) (bool, error)
- func Count(v reflect.Value) int
- func DecodeURL(s string) (string, error)
- func Distinct(v reflect.Value) interface{}
- func Each(obj reflect.Value, fn jtypes.Callable) (interface{}, error)
- func EncodeURL(s string) (string, error)
- func EncodeURLComponent(s string) (string, error)
- func Exists(v reflect.Value) bool
- func Filter(v reflect.Value, f jtypes.Callable) (interface{}, error)
- func FormatBase(value float64, base jtypes.OptionalFloat64) (string, error)
- func FormatNumber(value float64, picture string, options jtypes.OptionalValue) (string, error)
- func FromMillis(ms int64, picture jtypes.OptionalString, tz jtypes.OptionalString) (string, error)
- func Join(values reflect.Value, separator jtypes.OptionalString) (string, error)
- func Keys(obj reflect.Value) (interface{}, error)
- func Map(v reflect.Value, f jtypes.Callable) (interface{}, error)
- func Match(s string, pattern jtypes.Callable, limit jtypes.OptionalInt) ([]map[string]interface{}, error)
- func Max(v reflect.Value) (float64, error)
- func Merge(objs reflect.Value) (interface{}, error)
- func Min(v reflect.Value) (float64, error)
- func Not(v reflect.Value) bool
- func Number(value StringNumberBool) (float64, error)
- func ObjMerge(i1, i2 interface{}) interface{}
- func Pad(s string, width int, chars jtypes.OptionalString) string
- func Power(x, y float64) (float64, error)
- func Random() float64
- func Reduce(v reflect.Value, f jtypes.Callable, init jtypes.OptionalValue) (interface{}, error)
- func Replace(src string, pattern StringCallable, repl StringCallable, ...) (string, error)
- func Reverse(v reflect.Value) (interface{}, error)
- func Round(x float64, prec jtypes.OptionalInt) float64
- func Shuffle(v reflect.Value) interface{}
- func Sift(obj reflect.Value, fn jtypes.Callable) (interface{}, error)
- func SimpleJoin(v, v2 reflect.Value, field1, field2 string) (interface{}, error)
- func Single(v reflect.Value, f jtypes.Callable) (interface{}, error)
- func Sort(v reflect.Value, swap jtypes.OptionalCallable) (interface{}, error)
- func Split(s string, separator StringCallable, limit jtypes.OptionalInt) ([]string, error)
- func Spread(v reflect.Value) (interface{}, error)
- func Sqrt(x float64) (float64, error)
- func String(value interface{}) (string, error)
- func Substring(s string, start int, length jtypes.OptionalInt) string
- func SubstringAfter(s, substr string) string
- func SubstringBefore(s, substr string) string
- func Sum(v reflect.Value) (float64, error)
- func ToMillis(s string, picture jtypes.OptionalString, tz jtypes.OptionalString) (int64, error)
- func Trim(s string) string
- func TypeOf(x interface{}) (string, error)
- func Unescape(input string) (interface{}, error)
- func Zip(vs ...reflect.Value) (interface{}, error)
- type ErrType
- type Error
- type StringCallable
- type StringNumberBool
Constants ¶
const (
MST = "07:00"
)
Variables ¶
This section is empty.
Functions ¶
func Average ¶
Average returns the mean of an array of numbers. If the array is empty, Average returns 0 and an undefined error.
func Base64Decode ¶
Base64Decode returns the string represented by a base 64 string.
func Base64Encode ¶
Base64Encode returns the base 64 encoding of a string.
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 DecodeURL ¶
DecodeURL decodes a Uniform Resource Locator (URL) See https://docs.jsonata.org/string-functions#decodeurl and https://docs.jsonata.org/string-functions#decodeurlcomponent
func Each ¶
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 ¶
EncodeURL decodes a Uniform Resource Locator (URL) See https://docs.jsonata.org/string-functions#encodeurl
func EncodeURLComponent ¶
EncodeURLComponent decodes a component of a Uniform Resource Locator (URL) and https://docs.jsonata.org/string-functions#encodeurlcomponent
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 ¶
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 ¶
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 ¶
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 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 ¶
Max returns the largest value in an array of numbers. If the array is empty, Max returns 0 and an undefined error.
func Merge ¶
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 ¶
Min returns the smallest value in an array of numbers. If the array is empty, Min returns 0 and an undefined error.
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 ¶ added in v0.0.3
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 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 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 Sift ¶
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 ¶ added in v0.0.3
SimpleJoin - a multi-key multi-level full OR join - very simple and useful in certain circumstances
func Single ¶
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 Sqrt ¶
Sqrt returns the square root of a number. It returns an error if the number is less than zero.
func String ¶
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 ¶
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 ¶
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 ToMillis ¶
func ToMillis(s string, picture jtypes.OptionalString, tz jtypes.OptionalString) (int64, error)
ToMillis (golint)
func Trim ¶
Trim replaces consecutive whitespace characters in a string with a single space and trims spaces from the ends of the resulting string.
func TypeOf ¶
TypeOf implements the jsonata $type function that returns the data type of the argument
Types ¶
type StringCallable ¶
StringCallable (golint)
func (StringCallable) ValidTypes ¶
func (StringCallable) ValidTypes() []reflect.Type
ValidTypes (golint)
type StringNumberBool ¶
StringNumberBool (golint)
func (StringNumberBool) ValidTypes ¶
func (StringNumberBool) ValidTypes() []reflect.Type
ValidTypes (golint)