customfuncs

package
v0.0.0-...-54282bc Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

OmniV10CustomFuncs contains all custom funcs supported by omniparser '1.0'.

View Source
var OmniV10OnlyCustomFuncs = map[string]customfuncs.CustomFuncType{

	"containsPattern":             ContainsPattern,
	"dateTimeToRfc3339":           customfuncs.DateTimeToRFC3339,
	"dateTimeWithLayoutToRfc3339": customfuncs.DateTimeLayoutToRFC3339,
	"epochToDateTimeRfc3339":      customfuncs.EpochToDateTimeRFC3339,
	"eval":                        Eval,
	"external":                    External,
	"floor":                       Floor,
	"ifElse":                      IfElse,
	"isEmpty":                     IsEmpty,
	"replace":                     Replace,
	"retrieveBySplit":             RetrieveBySplit,
	"rowSkip":                     RowSkip,
	"rsubstring":                  RSubstring,
	"splitIntoJsonArray":          SplitIntoJSONArray,
	"strEqualAny":                 StrEqualAny,
	"substring":                   Substring,
	"switch":                      SwitchFunc,
	"switchByPattern":             SwitchByPattern,
}

OmniV10OnlyCustomFuncs contains omniparser '1.0' specific custom funcs.

Functions

func ContainsPattern

func ContainsPattern(_ *transformctx.Ctx, regexPattern string, strs ...string) (string, error)

ContainsPattern checks if any of 'strs' matches the given regex pattern, returns "true" if yes, and "false" if no.

func Eval

func Eval(_ *transformctx.Ctx, exprStr string, args ...string) (string, error)

Eval evaluates a given expression with input params and return the result in string. For supported expression formats and operators, check: https://github.com/Knetic/govaluate/blob/master/MANUAL.md

func External

func External(ctx *transformctx.Ctx, name string) (string, error)

External looks up an external property value by name and fails if not found.

func Floor

func Floor(_ *transformctx.Ctx, valueStr, decimalPlaces string) (string, error)

Floor parses 'valueStr' in as a float64 and then floors/truncates it to the specified decimal places.

func IfElse

func IfElse(_ *transformctx.Ctx, conditionsAndValues ...string) (string, error)

IfElse does a 'if-elseif-elseif-...-else' pattern check and returns the value that meets the condition. Note 'conditionsAndValues' must be of odd length, each of the even values is a condition value and it should be a boolean string and each of the odd values is a value to be returned, should its corresponding condition value is "true".

func IsEmpty

func IsEmpty(_ *transformctx.Ctx, str string) (string, error)

IsEmpty returns "true" if 'str' is empty; false if 'str' isn't. Note blank string (with whitespace only) is not considered empty.

func RSubstring

func RSubstring(ctx *transformctx.Ctx, str, startIndex, lengthStr string) (string, error)

RSubstring extracts a part of a 'str' from 'startIndex' from the right end of the string with length equal to 'lengthStr'. 'startIndex' must be [0, len). 'lengthStr' can be '-1', in which case RSubstring will return all the remaining characters (towards the head) of 'str' starting from 'startIndex' from the right. Or 'lengthStr' can be >= 0, in which case RSubstring will only return 'lengthStr' number characters of 'str' starting from 'startIndex' from the right.

func Replace

func Replace(_ *transformctx.Ctx, s, regexStr, replStr string) (string, error)

Replace replaces in 's' all the substrings that matches 'regexStr' with 'replStr'.

func RetrieveBySplit

func RetrieveBySplit(_ *transformctx.Ctx, str, sep, indexStr string) (string, error)

RetrieveBySplit splits a 'str' by 'sep' and returns the 'indexStr'-th part. Note 'indexStr' is 0-based.

func RowSkip

func RowSkip(_ *transformctx.Ctx, value, skipRegex string) (string, error)

RowSkip checks if a 'value' matches 'skipRegex' pattern, and return a special error code NonErrorRecordSkipped to indicate to omniparser '1.0' to skip processing a record, if the pattern matches.

func SplitIntoJSONArray

func SplitIntoJSONArray(_ *transformctx.Ctx, s, sep string, trim ...string) (string, error)

SplitIntoJSONArray splits an 's' by 'sep' and returns the resulting array of parts in a JSON string. An optional 'trim' argument can be specified to tell the function to space trim each part or not.

func StrEqualAny

func StrEqualAny(_ *transformctx.Ctx, s string, others ...string) (string, error)

StrEqualAny returns true if the 's' is equal to any of the strings specified by 'others'. If 'others' is empty or none of its strings is equal to 's', then "false" is returned.

func Substring

func Substring(_ *transformctx.Ctx, str, startIndex, lengthStr string) (string, error)

Substring extracts a part of a 'str' from 'startIndex' with 'lengthStr'. 'startIndex' must be [0, len). 'lengthStr' can be '-1', in which case Substring will return all the remaining characters of 'str' starting from 'startIndex'. Or 'lengthStr' can be >= 0, in which case Substring will only return 'lengthStr' number characters of 'str' starting from 'startIndex'.

func SwitchByPattern

func SwitchByPattern(_ *transformctx.Ctx, value string, patternsAndValues ...string) (string, error)

SwitchByPattern tests a value against a number of patterns (by regex pattern match) and returns the matched value; if nothing matches, the last default value is returned.

func SwitchFunc

func SwitchFunc(ctx *transformctx.Ctx, value string, casesAndValues ...string) (string, error)

SwitchFunc tests a 'value' against a number of cases (by string literal comparison) and returns the matched value; if nothing matches, the last default value is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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