Skip to content

All functions ​

The full standard library — 51 functions, every one with a typed signature the compiler enforces (TF2007 for unknown names, TF2008 for wrong arguments). This index is generated from the same definitions the compiler and the runtime use, so it cannot drift. Need more? Bring your own functions.

51 / 51 functions
stringConversion
string(value: unknown): string

Converts any value to its string representation (JSON for objects and arrays).

lengthInspect
length(value: string): number

Number of characters in the string.

containsInspect
contains(value: string, substring: string): boolean

True if the string contains the given substring.

matchesInspect
matches(value: string, pattern: string): boolean

True if the string matches the regular expression `pattern`.

upperCase & whitespace
upper(value: string): string

Uppercases the string.

lowerCase & whitespace
lower(value: string): string

Lowercases the string.

trimCase & whitespace
trim(value: string): string

Removes leading and trailing whitespace.

padCase & whitespace
pad(value: string, width: number, char?: string): string

Pads to `width` with `char` (default space); a negative width pads on the left.

substringTransform
substring(value: string, start: number, length?: number): string

Extracts `length` characters from `start`; a negative start counts from the end.

splitTransform
split(value: string, separator: string, limit?: number): string[]

Splits on a separator, optionally keeping only the first `limit` parts.

replaceTransform
replace(value: string, pattern: string, replacement: string): string

Replaces every occurrence of `pattern` with `replacement`.

base64encodeEncoding
base64encode(value: string): string

Encodes the string to Base64 (UTF-8 safe).

base64decodeEncoding
base64decode(value: string): string

Decodes a Base64 string (UTF-8 safe).

encodeUrlEncoding
encodeUrl(value: string): string

Encodes a full URL (`encodeURI`).

decodeUrlEncoding
decodeUrl(value: string): string

Decodes a full URL (`decodeURI`).

encodeUrlComponentEncoding
encodeUrlComponent(value: string): string

Encodes a URL component (`encodeURIComponent`).

decodeUrlComponentEncoding
decodeUrlComponent(value: string): string

Decodes a URL component (`decodeURIComponent`).

numberConversion
number(value: string | number | boolean): number

Parses strings and booleans into a number (`undefined` if not parseable).

formatBaseConversion
formatBase(value: number, radix?: number): string

Renders an integer in the given radix (2–36, default 10).

floorRounding
floor(value: number): number

Rounds down to the nearest integer.

ceilRounding
ceil(value: number): number

Rounds up to the nearest integer.

roundRounding
round(value: number, precision?: number): number

Rounds to `precision` digits, half-to-even like JSONata.

absMath
abs(value: number): number

Absolute value.

powerMath
power(base: number, exponent: number): number

`base` raised to `exponent`.

sqrtMath
sqrt(value: number): number

Square root (`undefined` for negative input).

randomRandom
random(): number

Pseudo-random number in [0, 1).

sumAggregation
sum(items: number[]): number

Sum of the numbers (0 for an empty array).

maxAggregation
max(items: number[]): number

Largest number (`undefined` for an empty array).

minAggregation
min(items: number[]): number

Smallest number (`undefined` for an empty array).

averageAggregation
average(items: number[]): number

Arithmetic mean (`undefined` for an empty array).

booleanBooleans
boolean(value: unknown): boolean

JSONata truthiness: `""`, `0`, `[]` and `{}` are false.

notBooleans
not(value: unknown): boolean

Negated JSONata truthiness.

existsBooleans
exists(value: unknown): boolean

True unless the value is `undefined` (`null` exists).

countMeasure
count(items: unknown[]): number

Number of elements.

joinCombine
join(items: string[], separator?: string): string

Concatenates the strings with a separator (default `""`).

appendCombine
append(first: unknown[], second: unknown[]): unknown[]

Concatenates two arrays.

zipCombine
zip(first: unknown[], second: unknown[]): unknown[][]

Pairs elements by index, truncated to the shorter array.

sortReorder
sort(items: string[] | number[]): string[] | number[]

Sorts in natural ascending order; the result keeps the input type.

reverseReorder
reverse(items: unknown[]): unknown[]

Reverses the order; the result keeps the input type.

shuffleReorder
shuffle(items: unknown[]): unknown[]

Random permutation; keeps the input type.

distinctDedupe
distinct(items: unknown[]): unknown[]

Removes duplicates (deep equality for objects); keeps the input type.

keysObjects
keys(value: object): string[]

Property names (merged across elements for an array of objects).

valuesObjects
values(value: object): unknown[]

Property values, typed as the union of the object's field types.

lookupObjects
lookup(value: object, key: string): unknown

Value of the given key (mapped over an array of objects).

mergeObjects
merge(objects: object[]): object

Merges an array of objects left to right.

spreadObjects
spread(value: object): object[]

Splits an object into an array of single-property objects.

typeObjects
type(value: unknown): string

`"string" | "number" | "boolean" | "null" | "array" | "object" | "undefined"`.

nowDate & time
now(): string

Current timestamp, ISO 8601.

millisDate & time
millis(): number

Current timestamp, milliseconds since the epoch.

fromMillisDate & time
fromMillis(millis: number): string

Epoch milliseconds → ISO 8601 string.

toMillisDate & time
toMillis(timestamp: string): number

ISO 8601 (or any parseable date) string → epoch milliseconds.

Released under the MIT License.