Recipes: Math
Signature
Section titled “Signature”sum(items: list)
Description
Section titled “Description”Returns the sum of all items in the list.
Example
Section titled “Example”>>> sum([1, 2, 3, 5, 8])19Signature
Section titled “Signature”avg(items: list)
Description
Section titled “Description”Returns the average of all items in the list.
Example
Section titled “Example”>>> avg([1, 2, 3, 5, 8])3.8Signature
Section titled “Signature”round(value: number, precision: number)
Description
Section titled “Description”Returns the value rounded to the specified precision.
Example
Section titled “Example”>>> round(3.1415, 2)3.14Signature
Section titled “Signature”floor(value: number, precision: number)
Description
Section titled “Description”Returns the value rounded down to the specified precision.
Example
Section titled “Example”>>> floor(3.1415, 2)3.14Signature
Section titled “Signature”ceil(value: number, precision: number)
Description
Section titled “Description”Returns the value rounded up to the specified precision.
Example
Section titled “Example”>>> ceil(3.1415, 2)3.15Signature
Section titled “Signature”max(items: list)
Description
Section titled “Description”Returns the maximum of all items in the list.
Example
Section titled “Example”>>> max([1, 2, 3, 5, 8])8Signature
Section titled “Signature”min(items: list)
Description
Section titled “Description”Returns the minimum of all items in the list.
Example
Section titled “Example”>>> min([1, 2, 3, 5, 8])1Signature
Section titled “Signature”sin(value: number, precision: number)
Description
Section titled “Description”Returns the sine of the value as a number between -1 and 1.
Example
Section titled “Example”>>> sin(30, 5)0.500Signature
Section titled “Signature”cos(value: number, precision: number)
Example
Section titled “Example”>>> cos(30, 5)0.866Signature
Section titled “Signature”exp(value: number, precision: number)
Example
Section titled “Example”>>> exp(1, 5)2.718Signature
Section titled “Signature”pow(value: number, exponent: number)
Example
Section titled “Example”>>> pow(2, 3)8Signature
Section titled “Signature”sqrt(value: number, precision: number)
Example
Section titled “Example”>>> sqrt(9, 5)3.0000Signature
Section titled “Signature”abs(value: number)
Example
Section titled “Example”>>> abs(-3)3vector
Section titled “vector”Signature
Section titled “Signature”vector(values: list)
Example
Section titled “Example”>>> vector([[1, 2, 3]])Vector { [[1, 2, 3]]}Signature
Section titled “Signature”rand(start: number, end: number)
Example
Section titled “Example”>>> rand(1, 10)6String
Section titled “String”Signature
Section titled “Signature”len(value: string)
Example
Section titled “Example”>>> len("hello")5substr
Section titled “substr”Signature
Section titled “Signature”substr(value: string, start: number, end: number)
Example
Section titled “Example”>>> substr("hello", 1, 3)ellcontains
Section titled “contains”Signature
Section titled “Signature”contains(value: string, search: string)
Example
Section titled “Example”>>> contains("hello", "ell")truetoUpperCase
Section titled “toUpperCase”Signature
Section titled “Signature”toUpperCase(value: string)
Example
Section titled “Example”>>> toUpperCase("hello")HELLOrandom.password(minLength, maxLength)
Section titled “random.password(minLength, maxLength)”Signature
Section titled “Signature”random.password(minLength: number, maxLength: number)
Example
Section titled “Example”>>> random.password(6, 8)cR9mVzp6Object
Section titled “Object”Signature
Section titled “Signature”len(value: object)
Example
Section titled “Example”>>> len({"hello": "world", "foo": "bar"})2contains
Section titled “contains”Signature
Section titled “Signature”contains(value: object, key: string)
Example
Section titled “Example”>>> contains({"hello": "world", "foo": "bar"}, "hello")trueSignature
Section titled “Signature”list(value: object)
Example
Section titled “Example”>>> list([{"hello": "world", "foo": "bar"}])ListWrapper([{"hello": "world", "foo": "bar"}])relation
Section titled “relation”Returns a new object with only the required keys for storing relations.
Signature
Section titled “Signature”relation(value: object)
Example
Section titled “Example”>>> relation({"id": 4, "module_id": 12, "hello": "world", "foo": "bar"}){"id": 4, "module_id": 12}Signature
Section titled “Signature”join(glue: string, pieces: list)
Example
Section titled “Example”>>> join(', ', ['a', 'b', 'c', 'd'])'a, b, c, d'Signature
Section titled “Signature”today()
Example
Section titled “Example”>>> today()2018-09-12Signature
Section titled “Signature”now()
Example
Section titled “Example”>>> now()2018-09-12T13:22:02-05:00Signature
Section titled “Signature”date(value: string, timezone: string)
Example
Section titled “Example”>>> date('2018-06-19')Date { date: 2018-09-12 00:00:00.0 UTC (+00:00)}duration
Section titled “duration”Signature
Section titled “Signature”duration(value: string)
Example
Section titled “Example”>>> duration("1h30m")90muser -> User
Section titled “user -> User”Returns the current user from local store. The user gets updated on every refresh.
Signature
Section titled “Signature”user()
Example
Section titled “Example”>>> user()User { id: 4, module_id: 1, email: "steffen@brezel.io", name: "Steffen"}hasRole
Section titled “hasRole”Signature
Section titled “Signature”hasRole(role: string)
Example
Section titled “Example”>>> hasRole("ROLE_ADMIN")truehasAbility
Section titled “hasAbility”Returns whether the current user has a role ability, either built-in like api_keys or declared by the system.
Also available as user().hasAbility(ability) in the API.
Signature
Section titled “Signature”hasAbility(ability: string)
Example
Section titled “Example”>>> hasAbility("export_pdf")truejson.decode
Section titled “json.decode”Signature
Section titled “Signature”json.decode(value: string)
Example
Section titled “Example”>>> json.decode("[1, 2, 3]")[1, 2, 3]json.encode
Section titled “json.encode”Signature
Section titled “Signature”json.encode(value: string)
Example
Section titled “Example”>>> json.encode("[1, 2, 3]")[1, 2, 3]regex.quote
Section titled “regex.quote”Signature
Section titled “Signature”regex.quote(value: string, delimiter: string)
Example
Section titled “Example”>>> regex.quote("-=hello world=-", "/")\\-=hello\\ world\\=-regex.matchAll
Section titled “regex.matchAll”Signature
Section titled “Signature”regex.matchAll(pattern: string, subject: string)
Example
Section titled “Example”>>> regex.matchAll("hello (\\w+)", "hello world")[ { "0": "hello world", "1": "world" }]