Language
Builtin Functions
Reference for the standard library shipped with Nodora
Nodora ships with two kinds of built-in functions.
Namespaced functions live under a namespace such as strings,
math, or time, and are called with the ns::name(...) form:
upper = strings::upper(input.name)
ts = time::now()
Core functions have no namespace. You call them by their bare name:
n = len(input.items)
ok = is_defined(input.user)
total = sum(input.amounts)
The complete list is below, grouped by namespace.
You can list namespaces and functions from the CLI:
nodora registry # list namespaces
nodora registry math # describe one namespace
Useful predicates and aggregates.
| Signature | Description |
|---|
int(x: any) -> number | Integer part of a number. |
len(value: string|array<any>|object) -> number | Length of a string, array, or object. |
is_defined(value: any) -> bool | True if value is not undefined. |
is_empty(arr: array<any>) -> bool | True if the array has no elements. |
is_number(value: any) -> bool | True if value is a number. |
is_string(value: any) -> bool | True if value is a string. |
is_bool(value: any) -> bool | True if value is a bool. |
is_array(value: any) -> bool | True if value is an array. |
is_object(value: any) -> bool | True if value is an object. |
sprintf(fmt: string, args: array<any>?) -> string | Format a string. |
some(arr: array<any>, fx: |any| -> bool) -> bool | Any element satisfies the predicate. |
every(arr: array<any>, fx: |any| -> bool) -> bool | All elements satisfy the predicate. |
min(value: array<number>|array<string>) -> number|string | Minimum element of an array. |
max(value: array<number>|array<string>) -> number|string | Maximum element of an array. |
sum(arr: array<number>) -> number | Sum of numeric elements. |
product(arr: array<number>) -> number | Product of numeric elements. |
| Signature | Description |
|---|
arrays::concat(x: array<any>, y: array<any>) -> array<any> | Concatenate two arrays. |
arrays::flatten(arr: array<any>) -> array<any> | Recursively flatten nested arrays. |
arrays::reverse(arr: array<any>) -> array<any> | Reverse element order. |
arrays::slice(arr: array<any>, start: number, stop: number?) -> array<any> | Sub-array [start, stop). stop defaults to length. |
arrays::zip(x: array<any>, y: array<any>, strict: bool?) -> array<array<any>> | Pair elements. strict requires equal length. |
arrays::find_index(arr: array<any>, fx: |any| -> bool) -> number | Index of first match, or -1. |
arrays::group_by(arr: array<any>, fx: |any| -> any) -> object | Group elements by key function result. |
| Signature | Description |
|---|
strings::concat(delim: string, arr: array<string>) -> string | Join with delimiter. |
strings::contains(str: string, substr: string) -> bool | Substring check. |
strings::starts_with(str: string, prefix: string) -> bool | True if string begins with prefix. |
strings::ends_with(str: string, suffix: string) -> bool | True if string ends with suffix. |
strings::lower(str: string) -> string | Lowercase. |
strings::upper(str: string) -> string | Uppercase. |
strings::trim(str: string, cutset: string) -> string | Trim characters from both ends. |
strings::trim_start(str: string, cutset: string) -> string | Removes leading characters. |
strings::trim_end(str: string, cutset: string) -> string | Removes trailing characters. |
strings::split(str: string, delim: string) -> array<string> | Splits a string into parts using a delimiter. |
strings::replace(str: string, old: string, new: string) -> string | Replace all occurrences. |
strings::is_alpha(str: string) -> bool | Non-empty, alphabetic only. |
strings::is_alnum(str: string) -> bool | Non-empty, alphanumeric only. |
strings::min_length(arr: array<string>) -> number | Length of the shortest element. |
strings::max_length(arr: array<string>) -> number | Length of the longest element. |
| Signature | Description |
|---|
math::abs(x: number) -> number | Absolute value. |
math::round(x: number) -> number | Round to nearest integer. |
math::ceil(x: number) -> number | Round up. |
math::floor(x: number) -> number | Round down. |
math::min(x: number, y: number) -> number | Min of two numbers. |
math::max(x: number, y: number) -> number | Max of two numbers. |
math::clamp(x: number, min: number, max: number) -> number | Clamp into [min, max]. |
| Signature | Description |
|---|
objects::get(obj: object, key: string, default: any) -> any | Lookup with default. |
objects::keys(obj: object) -> array<string> | Sorted keys. |
objects::values(obj: object) -> array<any> | Values, ordered by sorted keys. |
objects::filter(obj: object, keys: array<string>) -> object | Keep only the listed keys. |
objects::remove(obj: object, keys: array<string>) -> object | Remove the listed keys. |
objects::union(obj1: object, obj2: object) -> object | Merge; obj2 wins on conflict. |
objects::is_subset(super: object, sub: object) -> bool | True if every entry in sub is in super. |
| Signature | Description |
|---|
json::is_valid(str: string) -> bool | Returns true if str is valid JSON. |
json::marshal(x: any) -> string | Serialize a value to JSON. |
json::unmarshal(str: string) -> any | Parse a JSON string. |
| Signature | Description |
|---|
conv::atoi(str: string) -> number | Parse an integer. |
conv::atof(str: string) -> number | Parse a floating-point value. |
Timestamps are integers in milliseconds since the Unix epoch (UTC).
| Signature | Description |
|---|
time::now() -> number | Current timestamp in ms. |
time::add(ts: number, duration: string) -> number | Add a duration like "5m", "1h30m", "2d". |
time::sub(ts: number, duration: string) -> number | Subtract a duration. |
time::add_units(ts: number, n: number, unit: string?) -> number | Add n of ms|s|m|h|d|w. Defaults to ms. |
time::sub_units(ts: number, n: number, unit: string?) -> number | Same, subtracting. |
time::start_of(ts: number, unit: string) -> number | Start of hour|day|week|month|year (UTC). |
time::end_of(ts: number, unit: string) -> number | End of hour|day|week|month|year (UTC). |
time::parse_rfc3339(value: string) -> number | Parse RFC3339 to ms. |
time::format_rfc3339(ts: number) -> string | Format ms as RFC3339. |
| Signature | Description |
|---|
crypto::sha1(str: string) -> string | SHA-1 hex digest. |
crypto::sha256(str: string) -> string | SHA-256 hex digest. |
crypto::hmac_sha256(key: string, msg: string) -> string | HMAC-SHA256 hex digest. |
| Signature | Description |
|---|
base64::encode(str: string) -> string | Standard base64 encode. |
base64::decode(str: string) -> string | Standard base64 decode. |
base64::is_valid(str: string) -> bool | Validate base64 input. |
base64url::encode(str: string) -> string | URL-safe base64 encode. |
base64url::decode(str: string) -> string | URL-safe base64 decode. |
base64url::is_valid(str: string) -> bool | Validate URL-safe base64 input. |
| Signature | Description |
|---|
semver::is_valid(version: string) -> bool | True if version is a valid SemVer string. |
semver::canonical(version: string) -> string | Canonical form of a SemVer string. |
semver::compare(v: string, w: string) -> number | -1, 0, or 1. |
| Signature | Description |
|---|
uuid::is_valid(str: string) -> bool | Validate a UUID. |
| Signature | Description |
|---|
glob::matches(pattern: string, subj: string) -> bool | Match subj against a glob pattern. |