Documentation ¶
Index ¶
- Variables
- func Abs(env utils.Environment, num types.XNumber) types.XValue
- func And(env utils.Environment, args ...types.XValue) types.XValue
- func Array(env utils.Environment, args ...types.XValue) types.XValue
- func Char(env utils.Environment, num types.XNumber) types.XValue
- func Clean(env utils.Environment, str types.XString) types.XValue
- func Code(env utils.Environment, str types.XString) types.XValue
- func Date(env utils.Environment, str types.XString) types.XValue
- func DateAdd(env utils.Environment, args ...types.XValue) types.XValue
- func DateDiff(env utils.Environment, args ...types.XValue) types.XValue
- func DateFromParts(env utils.Environment, args ...types.XValue) types.XValue
- func Default(env utils.Environment, test types.XValue, def types.XValue) types.XValue
- func Field(env utils.Environment, args ...types.XValue) types.XValue
- func FormatDate(env utils.Environment, args ...types.XValue) types.XValue
- func FormatNum(env utils.Environment, args ...types.XValue) types.XValue
- func FormatURN(env utils.Environment, args ...types.XValue) types.XValue
- func FromEpoch(env utils.Environment, num types.XNumber) types.XValue
- func If(env utils.Environment, test types.XValue, arg1 types.XValue, arg2 types.XValue) types.XValue
- func JSON(env utils.Environment, value types.XValue) types.XValue
- func Join(env utils.Environment, array types.XValue, delimiter types.XValue) types.XValue
- func Left(env utils.Environment, str types.XString, count int) types.XValue
- func LegacyAdd(env utils.Environment, arg1 types.XValue, arg2 types.XValue) types.XValue
- func Length(env utils.Environment, value types.XValue) types.XValue
- func Lower(env utils.Environment, str types.XString) types.XValue
- func Max(env utils.Environment, args ...types.XValue) types.XValue
- func Mean(env utils.Environment, args ...types.XValue) types.XValue
- func Min(env utils.Environment, args ...types.XValue) types.XValue
- func Mod(env utils.Environment, num1 types.XNumber, num2 types.XNumber) types.XValue
- func Now(env utils.Environment) types.XValue
- func Number(env utils.Environment, value types.XValue) types.XValue
- func Or(env utils.Environment, args ...types.XValue) types.XValue
- func ParseDate(env utils.Environment, args ...types.XValue) types.XValue
- func ParseJSON(env utils.Environment, str types.XString) types.XValue
- func Percent(env utils.Environment, num types.XNumber) types.XValue
- func Rand(env utils.Environment) types.XValue
- func RandBetween(env utils.Environment, min types.XNumber, max types.XNumber) types.XValue
- func ReadCode(env utils.Environment, val types.XString) types.XValue
- func RegisterXFunction(name string, function XFunction)
- func RemoveFirstWord(env utils.Environment, str types.XString) types.XValue
- func Repeat(env utils.Environment, str types.XString, count int) types.XValue
- func Replace(env utils.Environment, str types.XString, needle types.XString, ...) types.XValue
- func Right(env utils.Environment, str types.XString, count int) types.XValue
- func Round(env utils.Environment, num types.XNumber, places int) types.XValue
- func RoundDown(env utils.Environment, num types.XNumber, places int) types.XValue
- func RoundUp(env utils.Environment, num types.XNumber, places int) types.XValue
- func Split(env utils.Environment, s types.XString, sep types.XString) types.XValue
- func StringCmp(env utils.Environment, str1 types.XString, str2 types.XString) types.XValue
- func TZ(env utils.Environment, date types.XDate) types.XValue
- func TZOffset(env utils.Environment, date types.XDate) types.XValue
- func Title(env utils.Environment, str types.XString) types.XValue
- func ToEpoch(env utils.Environment, date types.XDate) types.XValue
- func Today(env utils.Environment) types.XValue
- func URLEncode(env utils.Environment, str types.XString) types.XValue
- func Upper(env utils.Environment, str types.XString) types.XValue
- func Weekday(env utils.Environment, date types.XDate) types.XValue
- func Word(env utils.Environment, str types.XString, index int) types.XValue
- func WordCount(env utils.Environment, str types.XString) types.XValue
- func WordSlice(env utils.Environment, args ...types.XValue) types.XValue
- type XFunction
- func ArgCountCheck(min int, max int, f XFunction) XFunction
- func NoArgFunction(f func(utils.Environment) types.XValue) XFunction
- func OneArgFunction(f func(utils.Environment, types.XValue) types.XValue) XFunction
- func OneDateFunction(f func(utils.Environment, types.XDate) types.XValue) XFunction
- func OneNumberAndOptionalIntegerFunction(f func(utils.Environment, types.XNumber, int) types.XValue, defaultVal int) XFunction
- func OneNumberFunction(f func(utils.Environment, types.XNumber) types.XValue) XFunction
- func OneStringFunction(f func(utils.Environment, types.XString) types.XValue) XFunction
- func StringAndDateFunction(f func(utils.Environment, types.XString, types.XDate) types.XValue) XFunction
- func StringAndIntegerFunction(f func(utils.Environment, types.XString, int) types.XValue) XFunction
- func StringAndNumberFunction(f func(utils.Environment, types.XString, types.XNumber) types.XValue) XFunction
- func ThreeArgFunction(...) XFunction
- func ThreeStringFunction(...) XFunction
- func TwoArgFunction(f func(utils.Environment, types.XValue, types.XValue) types.XValue) XFunction
- func TwoNumberFunction(f func(utils.Environment, types.XNumber, types.XNumber) types.XValue) XFunction
- func TwoStringFunction(f func(utils.Environment, types.XString, types.XString) types.XValue) XFunction
Constants ¶
This section is empty.
Variables ¶
var XFUNCTIONS = map[string]XFunction{ "and": And, "if": ThreeArgFunction(If), "or": Or, "length": OneArgFunction(Length), "default": TwoArgFunction(Default), "array": Array, "legacy_add": TwoArgFunction(LegacyAdd), "number": OneArgFunction(Number), "round": OneNumberAndOptionalIntegerFunction(Round, 0), "round_up": OneNumberAndOptionalIntegerFunction(RoundUp, 0), "round_down": OneNumberAndOptionalIntegerFunction(RoundDown, 0), "max": Max, "min": Min, "mean": Mean, "mod": TwoNumberFunction(Mod), "rand": NoArgFunction(Rand), "rand_between": TwoNumberFunction(RandBetween), "abs": OneNumberFunction(Abs), "format_num": FormatNum, "read_code": OneStringFunction(ReadCode), "json": OneArgFunction(JSON), "parse_json": OneStringFunction(ParseJSON), "url_encode": OneStringFunction(URLEncode), "char": OneNumberFunction(Char), "code": OneStringFunction(Code), "split": TwoStringFunction(Split), "join": TwoArgFunction(Join), "title": OneStringFunction(Title), "word": StringAndIntegerFunction(Word), "remove_first_word": OneStringFunction(RemoveFirstWord), "word_count": OneStringFunction(WordCount), "word_slice": ArgCountCheck(2, 3, WordSlice), "field": Field, "clean": OneStringFunction(Clean), "left": StringAndIntegerFunction(Left), "lower": OneStringFunction(Lower), "right": StringAndIntegerFunction(Right), "string_cmp": TwoStringFunction(StringCmp), "repeat": StringAndIntegerFunction(Repeat), "replace": ThreeStringFunction(Replace), "upper": OneStringFunction(Upper), "percent": OneNumberFunction(Percent), "format_date": FormatDate, "parse_date": ParseDate, "date": OneStringFunction(Date), "date_from_parts": DateFromParts, "date_diff": DateDiff, "date_add": DateAdd, "weekday": OneDateFunction(Weekday), "tz": OneDateFunction(TZ), "tz_offset": OneDateFunction(TZOffset), "today": NoArgFunction(Today), "now": NoArgFunction(Now), "from_epoch": OneNumberFunction(FromEpoch), "to_epoch": OneDateFunction(ToEpoch), "format_urn": FormatURN, }
XFUNCTIONS is our map of functions available in Excellent which aren't tests
Functions ¶
func Abs ¶
Abs returns the absolute value of `num`
@(abs(-10)) -> 10 @(abs(10.5)) -> 10.5 @(abs("foo")) -> ERROR
@function abs(num)
func And ¶
And returns whether all the passed in arguments are truthy
@(and(true)) -> true @(and(true, false, true)) -> false
@function and(tests...)
func Array ¶
Array takes a list of `values` and returns them as an array
@(array("a", "b", 356)[1]) -> b @(join(array("a", "b", "c"), "|")) -> a|b|c @(length(array())) -> 0 @(length(array("a", "b"))) -> 2
@function array(values...)
func Char ¶
Char returns the rune for the passed in codepoint, `num`, which may be unicode, this is the reverse of code
@(char(33)) -> ! @(char(128512)) -> 😀 @(char("foo")) -> ERROR
@function char(num)
func Clean ¶
Clean strips any leading or trailing whitespace from `string“
@(clean("\nfoo\t")) -> foo @(clean(" bar")) -> bar @(clean(123)) -> 123
@function clean(string)
func Code ¶
Code returns the numeric code for the first character in `string`, it is the inverse of char
@(code("a")) -> 97 @(code("abc")) -> 97 @(code("😀")) -> 128512 @(code("15")) -> 49 @(code(15)) -> 49 @(code("")) -> ERROR
@function code(string)
func Date ¶
Date turns `string` into a date according to the environment's settings
date will return an error if it is unable to convert the string to a date.
@(date("1979-07-18")) -> 1979-07-18T00:00:00.000000Z @(date("2010 05 10")) -> 2010-05-10T00:00:00.000000Z @(date("NOT DATE")) -> ERROR
@function date(string)
func DateAdd ¶
DateAdd calculates the date value arrived at by adding `offset` number of `unit` to the `date`
Valid durations are "Y" for years, "M" for months, "W" for weeks, "D" for days, "h" for hour, "m" for minutes, "s" for seconds
@(date_add("2017-01-15", 5, "D")) -> 2017-01-20T00:00:00.000000Z @(date_add("2017-01-15 10:45", 30, "m")) -> 2017-01-15T11:15:00.000000Z
@function date_add(date, offset, unit)
func DateDiff ¶
DateDiff returns the integer duration between `date1` and `date2` in the `unit` specified.
Valid durations are "Y" for years, "M" for months, "W" for weeks, "D" for days, "h" for hour, "m" for minutes, "s" for seconds
@(date_diff("2017-01-17", "2017-01-15", "D")) -> 2 @(date_diff("2017-01-17 10:50", "2017-01-17 12:30", "h")) -> -1 @(date_diff("2017-01-17", "2015-12-17", "Y")) -> 2
@function date_diff(date1, date2, unit)
func DateFromParts ¶
DateFromParts converts the passed in `year`, `month` and `day`
@(date_from_parts(2017, 1, 15)) -> 2017-01-15T00:00:00.000000Z @(date_from_parts(2017, 2, 31)) -> 2017-03-03T00:00:00.000000Z @(date_from_parts(2017, 13, 15)) -> ERROR
@function date_from_parts(year, month, day)
func Default ¶
Default takes two arguments, returning `test` if not an error or nil, otherwise returning `default`
@(default(undeclared.var, "default_value")) -> default_value @(default("10", "20")) -> 10 @(default(date("invalid-date"), "today")) -> today
@function default(test, default)
func Field ¶
Field splits `string` based on the passed in `delimiter` and returns the field at `offset`. When splitting with a space, the delimiter is considered to be all whitespace. (first field is 0)
@(field("a,b,c", 1, ",")) -> b @(field("a,,b,c", 1, ",")) -> @(field("a b c", 1, " ")) -> b @(field("a b c d", 1, " ")) -> @(field("a\t\tb\tc\td", 1, " ")) -> @(field("a,b,c", "foo", ",")) -> ERROR
@function field(string, offset, delimeter)
func FormatDate ¶
FormatDate turns `date` into a string according to the `format` specified and in the optional `timezone`.
The format string can consist of the following characters. The characters ' ', ':', ',', 'T', '-' and '_' are ignored. Any other character is an error.
* `YY` - last two digits of year 0-99 * `YYYY` - four digits of your 0000-9999 * `M` - month 1-12 * `MM` - month 01-12 * `D` - day of month, 1-31 * `DD` - day of month, zero padded 0-31 * `h` - hour of the day 1-12 * `hh` - hour of the day 01-12 * `tt` - twenty four hour of the day 01-23 * `m` - minute 0-59 * `mm` - minute 00-59 * `s` - second 0-59 * `ss` - second 00-59 * `fff` - milliseconds * `ffffff` - microseconds * `fffffffff` - nanoseconds * `aa` - am or pm * `AA` - AM or PM * `Z` - hour and minute offset from UTC, or Z for UTC * `ZZZ` - hour and minute offset from UTC
Timezone should be a location name as specified in the IANA Time Zone database, such as "America/Guayaquil" or "America/Los_Angeles". If not specified the timezone of your environment will be used. An error will be returned if the timezone is not recognized.
@(format_date("1979-07-18T15:00:00.000000Z")) -> 1979-07-18 15:00 @(format_date("1979-07-18T15:00:00.000000Z", "YYYY-MM-DD")) -> 1979-07-18 @(format_date("2010-05-10T19:50:00.000000Z", "YYYY M DD tt:mm")) -> 2010 5 10 19:50 @(format_date("2010-05-10T19:50:00.000000Z", "YYYY-MM-DD tt:mm AA", "America/Los_Angeles")) -> 2010-05-10 12:50 PM @(format_date("1979-07-18T15:00:00.000000Z", "YYYY")) -> 1979 @(format_date("1979-07-18T15:00:00.000000Z", "M")) -> 7 @(format_date("NOT DATE", "YYYY-MM-DD")) -> ERROR
@function format_date(date, format [,timezone])
func FormatNum ¶
FormatNum returns `num` formatted with the passed in number of decimal `places` and optional `commas` dividing thousands separators
@(format_num(31337)) -> 31,337.00 @(format_num(31337, 2)) -> 31,337.00 @(format_num(31337, 2, true)) -> 31,337.00 @(format_num(31337, 0, false)) -> 31337 @(format_num("foo", 2, false)) -> ERROR
@function format_num(num, places, commas)
func FormatURN ¶
FormatURN turns `urn` into a human friendly string
@(format_urn("tel:+250781234567")) -> 0781 234 567 @(format_urn("twitter:134252511151#billy_bob")) -> billy_bob @(format_urn(contact.urns)) -> (206) 555-1212 @(format_urn(contact.urns.2)) -> foo@bar.com @(format_urn(contact.urns.mailto)) -> foo@bar.com @(format_urn(contact.urns.mailto.0)) -> foo@bar.com @(format_urn(contact.urns.telegram)) -> @(format_urn("NOT URN")) -> ERROR
@function format_urn(urn)
func FromEpoch ¶
FromEpoch returns a new date created from `num` which represents number of nanoseconds since January 1st, 1970 GMT
@(from_epoch(1497286619000000000)) -> 2017-06-12T16:56:59.000000Z
@function from_epoch(num)
func If ¶
func If(env utils.Environment, test types.XValue, arg1 types.XValue, arg2 types.XValue) types.XValue
If evaluates the `test` argument, and if truthy returns `true_value`, if not returning `false_value`
If the first argument is an error that error is returned
@(if(1 = 1, "foo", "bar")) -> foo @(if("foo" > "bar", "foo", "bar")) -> ERROR
@function if(test, true_value, false_value)
func JSON ¶
JSON tries to return a JSON representation of `value`. An error is returned if there is no JSON representation of that object.
@(json("string")) -> "string" @(json(10)) -> 10 @(json(contact.uuid)) -> "5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f"
@function json(value)
func Join ¶
Join joins the passed in `array` of strings with the passed in `delimeter`
@(join(array("a", "b", "c"), "|")) -> a|b|c @(join(split("a.b.c", "."), " ")) -> a b c
@function join(array, delimiter)
func Left ¶
Left returns the `count` most left characters of the passed in `string`
@(left("hello", 2)) -> he @(left("hello", 7)) -> hello @(left("😀😃😄😁", 2)) -> 😀😃 @(left("hello", -1)) -> ERROR
@function left(string, count)
func LegacyAdd ¶
LegacyAdd simulates our old + operator, which operated differently based on whether one of the parameters was a date or not. If one is a date, then the other side is expected to be an integer with a number of days to add to the date, otherwise a normal decimal addition is attempted.
func Length ¶
Length returns the length of the passed in string or array.
length will return an error if it is passed an item which doesn't have length.
@(length("Hello")) -> 5 @(length("😀😃😄😁")) -> 4 @(length(array())) -> 0 @(length(array("a", "b", "c"))) -> 3 @(length(1234)) -> ERROR
@function length(value)
func Lower ¶
Lower lowercases the passed in `string`
@(lower("HellO")) -> hello @(lower("hello")) -> hello @(lower("123")) -> 123 @(lower("😀")) -> 😀
@function lower(string)
func Max ¶
Max takes a list of `values` and returns the greatest of them
@(max(1, 2)) -> 2 @(max(1, -1, 10)) -> 10 @(max(1, 10, "foo")) -> ERROR
@function max(values...)
func Mean ¶
Mean takes a list of `values` and returns the arithmetic mean of them
@(mean(1, 2)) -> 1.5 @(mean(1, 2, 6)) -> 3 @(mean(1, "foo")) -> ERROR
@function mean(values)
func Min ¶
Min takes a list of `values` and returns the smallest of them
@(min(1, 2)) -> 1 @(min(2, 2, -10)) -> -10 @(min(1, 2, "foo")) -> ERROR
@function min(values)
func Mod ¶
Mod returns the remainder of the division of `divident` by `divisor`
@(mod(5, 2)) -> 1 @(mod(4, 2)) -> 0 @(mod(5, "foo")) -> ERROR
@function mod(dividend, divisor)
func Now ¶
func Now(env utils.Environment) types.XValue
Now returns the current date and time in the environment timezone
@(now()) -> 2018-04-11T13:24:30.123456-05:00
@function now()
func Number ¶
Number tries to convert `value` to a number. An error is returned if the value can't be converted.
@(number(10)) -> 10 @(number("123.45000")) -> 123.45 @(number("what?")) -> ERROR
@function number(value)
func Or ¶
Or returns whether if any of the passed in arguments are truthy
@(or(true)) -> true @(or(true, false, true)) -> true
@function or(tests...)
func ParseDate ¶
ParseDate turns `string` into a date according to the `format` and optional `timezone` specified
The format string can consist of the following characters. The characters ' ', ':', ',', 'T', '-' and '_' are ignored. Any other character is an error.
* `YY` - last two digits of year 0-99 * `YYYY` - four digits of your 0000-9999 * `M` - month 1-12 * `MM` - month 01-12 * `D` - day of month, 1-31 * `DD` - day of month, zero padded 0-31 * `h` - hour of the day 1-12 * `hh` - hour of the day 01-12 * `tt` - twenty four hour of the day 01-23 * `m` - minute 0-59 * `mm` - minute 00-59 * `s` - second 0-59 * `ss` - second 00-59 * `fff` - milliseconds * `ffffff` - microseconds * `fffffffff` - nanoseconds * `aa` - am or pm * `AA` - AM or PM * `Z` - hour and minute offset from UTC, or Z for UTC * `ZZZ` - hour and minute offset from UTC
Timezone should be a location name as specified in the IANA Time Zone database, such as "America/Guayaquil" or "America/Los_Angeles". If not specified the timezone of your environment will be used. An error will be returned if the timezone is not recognized.
Note that fractional seconds will be parsed even without an explicit format identifier. You should only specify fractional seconds when you want to assert the number of places in the input format.
parse_date will return an error if it is unable to convert the string to a date.
@(parse_date("1979-07-18", "YYYY-MM-DD")) -> 1979-07-18T00:00:00.000000Z @(parse_date("2010 5 10", "YYYY M DD")) -> 2010-05-10T00:00:00.000000Z @(parse_date("2010 5 10 12:50", "YYYY M DD tt:mm", "America/Los_Angeles")) -> 2010-05-10T12:50:00.000000-07:00 @(parse_date("NOT DATE", "YYYY-MM-DD")) -> ERROR
@function parse_date(string, format [,timezone])
func ParseJSON ¶
ParseJSON tries to parse `string` as JSON, returning a fragment you can index into
If the passed in value is not JSON, then an error is returned
@(parse_json("[1,2,3,4]").2) -> 3 @(parse_json("invalid json")) -> ERROR
@function parse_json(string)
func Percent ¶
Percent converts `num` to a string represented as a percentage
@(percent(0.54234)) -> 54% @(percent(1.2)) -> 120% @(percent("foo")) -> ERROR
@function percent(num)
func Rand ¶
func Rand(env utils.Environment) types.XValue
Rand returns a single random number between [0.0-1.0).
@(rand()) -> 0.3849275689214193274523267973563633859157562255859375 @(rand()) -> 0.607552015674623913099594574305228888988494873046875
@function rand()
func RandBetween ¶
RandBetween a single random integer in the given inclusive range.
@(rand_between(1, 10)) -> 5 @(rand_between(1, 10)) -> 10
@function rand_between()
func ReadCode ¶
ReadCode converts `code` into something that can be read by IVR systems
ReadCode will split the numbers such as they are easier to understand. This includes splitting in 3s or 4s if appropriate.
@(read_code("1234")) -> 1 2 3 4 @(read_code("abc")) -> a b c @(read_code("abcdef")) -> a b c , d e f
@function read_code(code)
func RegisterXFunction ¶
RegisterXFunction registers a new function in Excellent
func RemoveFirstWord ¶
RemoveFirstWord removes the 1st word of `string`
@(remove_first_word("foo bar")) -> bar
@function remove_first_word(string)
func Repeat ¶
Repeat return `string` repeated `count` number of times
@(repeat("*", 8)) -> ******** @(repeat("*", "foo")) -> ERROR
@function repeat(string, count)
func Replace ¶
func Replace(env utils.Environment, str types.XString, needle types.XString, replacement types.XString) types.XValue
Replace replaces all occurrences of `needle` with `replacement` in `string`
@(replace("foo bar", "foo", "zap")) -> zap bar @(replace("foo bar", "baz", "zap")) -> foo bar
@function replace(string, needle, replacement)
func Right ¶
Right returns the `count` most right characters of the passed in `string`
@(right("hello", 2)) -> lo @(right("hello", 7)) -> hello @(right("😀😃😄😁", 2)) -> 😄😁 @(right("hello", -1)) -> ERROR
@function right(string, count)
func Round ¶
Round rounds `num` to the nearest value. You can optionally pass in the number of decimal places to round to as `places`.
If places < 0, it will round the integer part to the nearest 10^(-places).
@(round(12)) -> 12 @(round(12.141)) -> 12 @(round(12.6)) -> 13 @(round(12.141, 2)) -> 12.14 @(round(12.146, 2)) -> 12.15 @(round(12.146, -1)) -> 10 @(round("notnum", 2)) -> ERROR
@function round(num [,places])
func RoundDown ¶
RoundDown rounds `num` down to the nearest integer value. You can optionally pass in the number of decimal places to round to as `places`.
@(round_down(12)) -> 12 @(round_down(12.141)) -> 12 @(round_down(12.6)) -> 12 @(round_down(12.141, 2)) -> 12.14 @(round_down(12.146, 2)) -> 12.14 @(round_down("foo")) -> ERROR
@function round_down(num [,places])
func RoundUp ¶
RoundUp rounds `num` up to the nearest integer value. You can optionally pass in the number of decimal places to round to as `places`.
@(round_up(12)) -> 12 @(round_up(12.141)) -> 13 @(round_up(12.6)) -> 13 @(round_up(12.141, 2)) -> 12.15 @(round_up(12.146, 2)) -> 12.15 @(round_up("foo")) -> ERROR
@function round_up(num [,places])
func Split ¶
Split splits `string` based on the passed in `delimeter`
Empty values are removed from the returned list
@(split("a b c", " ")) -> ["a","b","c"] @(split("a", " ")) -> ["a"] @(split("abc..d", ".")) -> ["abc","d"] @(split("a.b.c.", ".")) -> ["a","b","c"] @(split("a && b && c", " && ")) -> ["a","b","c"]
@function split(string, delimiter)
func StringCmp ¶
StringCmp returns the comparison between the strings `str1` and `str2`. The return value will be -1 if str1 is smaller than str2, 0 if they are equal and 1 if str1 is greater than str2
@(string_cmp("abc", "abc")) -> 0 @(string_cmp("abc", "def")) -> -1 @(string_cmp("zzz", "aaa")) -> 1
@function string_cmp(str1, str2)
func TZ ¶
TZ returns the timezone for `date“
If not timezone information is present in the date, then the environment's timezone will be returned
@(tz("2017-01-15 02:15:18PM UTC")) -> UTC @(tz("2017-01-15 02:15:18PM")) -> UTC @(tz("2017-01-15")) -> UTC @(tz("foo")) -> ERROR
@function tz(date)
func TZOffset ¶
TZOffset returns the offset for the timezone as a string +/- HHMM for `date`
If no timezone information is present in the date, then the environment's timezone offset will be returned
@(tz_offset("2017-01-15 02:15:18PM UTC")) -> +0000 @(tz_offset("2017-01-15 02:15:18PM")) -> +0000 @(tz_offset("2017-01-15")) -> +0000 @(tz_offset("foo")) -> ERROR
@function tz_offset(date)
func Title ¶
Title titlecases the passed in `string`, capitalizing each word
@(title("foo")) -> Foo @(title("ryan lewis")) -> Ryan Lewis @(title(123)) -> 123
@function title(string)
func ToEpoch ¶
ToEpoch converts `date` to the number of nanoseconds since January 1st, 1970 GMT
@(to_epoch("2017-06-12T16:56:59.000000Z")) -> 1497286619000000000
@function to_epoch(date)
func Today ¶
func Today(env utils.Environment) types.XValue
Today returns the current date in the current timezone, time is set to midnight in the environment timezone
@(today()) -> 2018-04-11T00:00:00.000000Z
@function today()
func URLEncode ¶
URLEncode URL encodes `string` for use in a URL parameter
@(url_encode("two words")) -> two+words @(url_encode(10)) -> 10
@function url_encode(string)
func Upper ¶
Upper uppercases all characters in the passed `string`
@(upper("Asdf")) -> ASDF @(upper(123)) -> 123
@function upper(string)
func Weekday ¶
Weekday returns the day of the week for `date`, 0 is sunday, 1 is monday..
@(weekday("2017-01-15")) -> 0 @(weekday("foo")) -> ERROR
@function weekday(date)
func Word ¶
Word returns the word at the passed in `index` for the passed in `string`
@(word("bee cat dog", 0)) -> bee @(word("bee.cat,dog", 0)) -> bee @(word("bee.cat,dog", 1)) -> cat @(word("bee.cat,dog", 2)) -> dog @(word("bee.cat,dog", -1)) -> dog @(word("bee.cat,dog", -2)) -> cat
@function word(string, index)
func WordCount ¶
WordCount returns the number of words in `string`
@(word_count("foo bar")) -> 2 @(word_count(10)) -> 1 @(word_count("")) -> 0 @(word_count("😀😃😄😁")) -> 4
@function word_count(string)
func WordSlice ¶
WordSlice extracts a substring from `string` spanning from `start` up to but not-including `end`. (first word is 0). A negative end value means that all words after the start should be returned.
@(word_slice("bee cat dog", 0, 1)) -> bee @(word_slice("bee cat dog", 0, 2)) -> bee cat @(word_slice("bee cat dog", 1, -1)) -> cat dog @(word_slice("bee cat dog", 1)) -> cat dog @(word_slice("bee cat dog", 2, 3)) -> dog @(word_slice("bee cat dog", 3, 10)) ->
@function word_slice(string, start, end)
Types ¶
type XFunction ¶
XFunction defines the interface that Excellent functions must implement
func ArgCountCheck ¶
ArgCountCheck wraps an XFunction and checks the number of args
func NoArgFunction ¶
func NoArgFunction(f func(utils.Environment) types.XValue) XFunction
NoArgFunction creates an XFunction from a no-arg function
func OneArgFunction ¶
OneArgFunction creates an XFunction from a single-arg function
func OneDateFunction ¶
OneDateFunction creates an XFunction from a single number function
func OneNumberAndOptionalIntegerFunction ¶
func OneNumberAndOptionalIntegerFunction(f func(utils.Environment, types.XNumber, int) types.XValue, defaultVal int) XFunction
OneNumberAndOptionalIntegerFunction creates an XFunction from a function that takes a number and an optional integer
func OneNumberFunction ¶
OneNumberFunction creates an XFunction from a single number function
func OneStringFunction ¶
OneStringFunction creates an XFunction from a single string function
func StringAndDateFunction ¶
func StringAndDateFunction(f func(utils.Environment, types.XString, types.XDate) types.XValue) XFunction
StringAndDateFunction creates an XFunction from a function that takes a string and a date
func StringAndIntegerFunction ¶
StringAndIntegerFunction creates an XFunction from a function that takes a string and an integer
func StringAndNumberFunction ¶
func StringAndNumberFunction(f func(utils.Environment, types.XString, types.XNumber) types.XValue) XFunction
StringAndNumberFunction creates an XFunction from a function that takes a string and a number
func ThreeArgFunction ¶
func ThreeArgFunction(f func(utils.Environment, types.XValue, types.XValue, types.XValue) types.XValue) XFunction
ThreeArgFunction creates an XFunction from a three-arg function
func ThreeStringFunction ¶
func ThreeStringFunction(f func(utils.Environment, types.XString, types.XString, types.XString) types.XValue) XFunction
ThreeStringFunction creates an XFunction from a function that takes three strings
func TwoArgFunction ¶
TwoArgFunction creates an XFunction from a two-arg function