Nodora
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

Core

Useful predicates and aggregates.

SignatureDescription
int(x: any) -> numberInteger part of a number.
len(value: string|array<any>|object) -> numberLength of a string, array, or object.
is_defined(value: any) -> boolTrue if value is not undefined.
is_empty(arr: array<any>) -> boolTrue if the array has no elements.
is_number(value: any) -> boolTrue if value is a number.
is_string(value: any) -> boolTrue if value is a string.
is_bool(value: any) -> boolTrue if value is a bool.
is_array(value: any) -> boolTrue if value is an array.
is_object(value: any) -> boolTrue if value is an object.
sprintf(fmt: string, args: array<any>?) -> stringFormat a string.
some(arr: array<any>, fx: |any| -> bool) -> boolAny element satisfies the predicate.
every(arr: array<any>, fx: |any| -> bool) -> boolAll elements satisfy the predicate.
min(value: array<number>|array<string>) -> number|stringMinimum element of an array.
max(value: array<number>|array<string>) -> number|stringMaximum element of an array.
sum(arr: array<number>) -> numberSum of numeric elements.
product(arr: array<number>) -> numberProduct of numeric elements.
fallback(value: T, fb: T) -> TFall back to a default value if undefined.

arrays

SignatureDescription
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<T>) -> array<T>Reverse element order.
arrays::slice(arr: array<T>, start: number, stop: number?) -> array<T>Sub-array [start, stop). stop defaults to length.
arrays::unique(arr: array<T>) -> array<T>Remove duplicates, preserving first-seen order.
arrays::zip(x: array<any>, y: array<any>, strict: bool?) -> array<array<any>>Pair elements. strict requires equal length.
arrays::map(arr: array<T>, fx: |T| -> U) -> array<U>Transform each element using fx.
arrays::filter(arr: array<T>, fx: |T| -> bool) -> array<T>Keep only elements satisfying the predicate.
arrays::reduce(arr: array<T>, fx: |U, T| -> U, init: U) -> UFold to a single value, left to right.
arrays::find_index(arr: array<any>, fx: |any| -> bool) -> numberIndex of first match, or -1.
arrays::group_by(arr: array<any>, fx: |any| -> any) -> objectGroup elements by key function result.

strings

SignatureDescription
strings::concat(delim: string, arr: array<string>) -> stringJoin with delimiter.
strings::contains(str: string, substr: string) -> boolSubstring check.
strings::starts_with(str: string, prefix: string) -> boolTrue if string begins with prefix.
strings::ends_with(str: string, suffix: string) -> boolTrue if string ends with suffix.
strings::lower(str: string) -> stringLowercase.
strings::upper(str: string) -> stringUppercase.
strings::trim(str: string, cutset: string) -> stringTrim characters from both ends.
strings::trim_start(str: string, cutset: string) -> stringRemoves leading characters.
strings::trim_end(str: string, cutset: string) -> stringRemoves trailing characters.
strings::split(str: string, delim: string) -> array<string>Splits a string into parts using a delimiter.
strings::substring(str: string, start: number, stop: number?) -> stringSub-string [start, stop). stop defaults to length.
strings::replace(str: string, old: string, new: string) -> stringReplace all occurrences.
strings::is_alpha(str: string) -> boolNon-empty, alphabetic only.
strings::is_alnum(str: string) -> boolNon-empty, alphanumeric only.
strings::min_length(arr: array<string>) -> numberLength of the shortest element.
strings::max_length(arr: array<string>) -> numberLength of the longest element.

math

SignatureDescription
math::abs(x: number) -> numberAbsolute value.
math::round(x: number, decimals: number?) -> numberRound to nearest integer, or to decimals places.
math::ceil(x: number) -> numberRound up.
math::floor(x: number) -> numberRound down.
math::min(x: number, y: number) -> numberMin of two numbers.
math::max(x: number, y: number) -> numberMax of two numbers.
math::pow(x: number, y: number) -> numberx raised to the power of y.
math::sqrt(x: number) -> numberSquare root. Undefined for negatives.
math::clamp(x: number, min: number, max: number) -> numberClamp into [min, max].

objects

SignatureDescription
objects::get(obj: object, key: string, default: T) -> TLookup 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>) -> objectKeep only the listed keys.
objects::remove(obj: object, keys: array<string>) -> objectRemove the listed keys.
objects::union(obj1: object, obj2: object) -> objectMerge; obj2 wins on conflict.
objects::is_subset(super: object, sub: object) -> boolTrue if every entry in sub is in super.

json

SignatureDescription
json::is_valid(str: string) -> boolReturns true if str is valid JSON.
json::marshal(x: any) -> stringSerialize a value to JSON.
json::unmarshal(str: string) -> anyParse a JSON string.

conv

SignatureDescription
conv::atoi(str: string) -> numberParse an integer.
conv::atof(str: string) -> numberParse a floating-point value.
conv::to_string(x: union<number|bool|string>) -> stringConvert a number, bool, or string to a string.

time

Timestamps are integers in milliseconds since the Unix epoch (UTC).

SignatureDescription
time::now() -> numberCurrent timestamp in ms.
time::add(ts: number, duration: string) -> numberAdd a duration like "5m", "1h30m", "2d".
time::sub(ts: number, duration: string) -> numberSubtract a duration.
time::add_units(ts: number, n: number, unit: string?) -> numberAdd n of ms|s|m|h|d|w. Defaults to ms.
time::sub_units(ts: number, n: number, unit: string?) -> numberSame, subtracting.
time::start_of(ts: number, unit: string) -> numberStart of hour|day|week|month|year (UTC).
time::end_of(ts: number, unit: string) -> numberEnd of hour|day|week|month|year (UTC).
time::parse_rfc3339(value: string) -> numberParse RFC3339 to ms.
time::format_rfc3339(ts: number) -> stringFormat ms as RFC3339.

crypto

SignatureDescription
crypto::sha1(str: string) -> stringSHA-1 hex digest.
crypto::sha256(str: string) -> stringSHA-256 hex digest.
crypto::hmac_sha256(key: string, msg: string) -> stringHMAC-SHA256 hex digest.

base64 and base64url

SignatureDescription
base64::encode(str: string) -> stringStandard base64 encode.
base64::decode(str: string) -> stringStandard base64 decode.
base64::is_valid(str: string) -> boolValidate base64 input.
base64url::encode(str: string) -> stringURL-safe base64 encode.
base64url::decode(str: string) -> stringURL-safe base64 decode.
base64url::is_valid(str: string) -> boolValidate URL-safe base64 input.

semver

SignatureDescription
semver::is_valid(version: string) -> boolTrue if version is a valid SemVer string.
semver::canonical(version: string) -> stringCanonical form of a SemVer string.
semver::compare(v: string, w: string) -> number-1, 0, or 1.

uuid

SignatureDescription
uuid::is_valid(str: string) -> boolValidate a UUID.

glob

SignatureDescription
glob::matches(pattern: string, subj: string) -> boolMatch subj against a glob pattern.

On this page