The Core category includes Files TransformScript's general-purpose functions: higher-order functions, math, logging, identifiers, and the general string and coercion-adjacent helpers that apply beyond strings. You can call each in prefix form fn(x, …) or in postfix/UFCS form x fn(…).
These are the most-used functions in the language. The higher-order ones (map, filter, reduce, groupBy, orderBy, and similar) take lambdas — write them either as explicit (x) -> … functions or with the $ / $$ / $$$ positional shorthand. See Functions and Lambdas for the calling conventions and how $ expands.
There is no pipe operator in TransformScript. To thread a value through a transform, use then(value, lambda) (see Conditionals and Threading below).
| Function | Signature | Description | Example |
|---|
map | (:array?, :lambda) | Transforms each element. Lambda receives (value, index). Returns null for a null input. | map([1, 2, 3], $ * 2) → [2, 4, 6] |
flatMap | (:array, :lambda) | Maps then flattens one level. A null lambda result contributes nothing. | flatMap([1, 2], (x) -> [x, x]) → [1, 1, 2, 2] |
mapObject | (:object?, :lambda) | Maps each entry to a new object and merges the results. Lambda receives (value, key, index) and must return an Object. | mapObject({a: 1, b: 2}, (v, k) -> {(k): v * 10}) → {"a": 10, "b": 20} |
pluck | (:collection, :lambda) | Projects a collection into an array by applying the lambda to each item. Lambda receives (value, key, index). | pluck({a: 1, b: 2}, (v, k) -> k) → ["a", "b"] |
reduce | (:array, :lambda, :any?) | Folds the array. Lambda receives (item, accumulator). Without a seed, the first element is the initial accumulator. | reduce([1, 2, 3, 4], (x, acc) -> x + acc, 0) → 10 |
scan | (:array, :lambda, :any?) | Like reduce, but returns every intermediate accumulator (a running fold). | scan([1, 2, 3, 4], (x, acc) -> x + acc) → [1, 3, 6, 10] |
| Function | Signature | Description | Example |
|---|
filter | (:array, :lambda) | Keeps elements where the predicate is truthy. Lambda receives (item, index). | filter([1, 2, 3, 4], $ > 2) → [3, 4] |
filterObject | (:object, :lambda) | Keeps entries where the predicate is truthy. Lambda receives (value, key, index). | filterObject({a: 1, b: 2, c: 3}, (v) -> v > 1) → {"b": 2, "c": 3} |
find | (:any, :any) | On an Array/Object, returns the first value matching the lambda. On a String, returns the [start, end] index range of the substring (or [-1, -1]). | find([10, 20, 30], (x) -> x == 20) → 20 |
distinctBy | (:array, :lambda) | De-duplicates, keeping the first element per distinct key. Lambda receives (value, index). | distinctBy([{id: 1}, {id: 1}, {id: 2}], (x) -> x.id) → [{"id": 1}, {"id": 2}] |
find's criterion is passed through the :any slot, so the $ shorthand will not auto-wrap into a lambda here — use an explicit (x) -> … for the Array/Object form.
| Function | Signature | Description | Example |
|---|
groupBy | (:collection, :lambda) | Groups items into an object keyed by the lambda result (keys are stringified). | groupBy([1, 2, 3, 4], (x) -> mod(x, 2)) → {"1": [1, 3], "0": [2, 4]} |
orderBy | (:collection, :lambda) | Sorts an Array (or an Object by value) ascending by the lambda's sort key. | orderBy([3, 1, 2], $) → [1, 2, 3] |
| Function | Signature | Description | Example |
|---|
sum | (:collection, :lambda?) | Sums numeric values; an optional lambda selects what to sum. | sum([1, 2, 3, 4]) → 10 |
avg | (:collection, :lambda?) | Mean of numeric values (returns 0 for an empty collection). | avg([1, 2, 3, 4]) → 2.5 |
max | (:array) | Largest element. | max([3, 1, 4, 1, 5]) → 5 |
min | (:array) | Smallest element. | min([3, 1, 4]) → 1 |
maxBy | (:array, :lambda) | Element with the largest lambda value. | maxBy([{n: 1}, {n: 5}, {n: 3}], (x) -> x.n) → {"n": 5} |
minBy | (:array, :lambda) | Element with the smallest lambda value. | minBy([{n: 1}, {n: 5}], (x) -> x.n) → {"n": 1} |
abs | (:number) | Absolute value. | abs(-5) → 5 |
ceil | (:number, :number?) | Rounds up; optional precision (decimal places). | ceil(4.2) → 5 |
floor | (:number, :number?) | Rounds down; optional precision. | floor(4.8) → 4 |
round | (:number, :number?) | Rounds to nearest; optional precision (default 0). | round(3.14159, 2) → 3.14 |
pow | (:number, :number) | Exponentiation (base to the power exponent). | pow(2, 10) → 1024 |
sqrt | (:number) | Square root (raises on a negative input). | sqrt(16) → 4.0 |
mod | (:number, :number) | Modulo (remainder). | mod(10, 3) → 1 |
| Function | Signature | Description | Example |
|---|
keysOf | (:any) | The object's keys as an array. | keysOf({a: 1, b: 2}) → ["a", "b"] |
valuesOf | (:any) | The object's values as an array. | valuesOf({a: 1, b: 2}) → [1, 2] |
namesOf | (:object?) | The object's keys, each coerced to a string. | namesOf({a: 1, b: 2}) → ["a", "b"] |
entriesOf | (:object?) | An array of {key, value, attributes} records, one per entry. | entriesOf({a: 1}) → [{"key": "a", "value": 1, "attributes": {}}] |
| Function | Signature | Description | Example |
|---|
upper | (:string?) | Uppercases the string (null-safe). | upper("hello") → "HELLO" |
lower | (:string?) | Lowercases the string (null-safe). | lower("HELLO") → "hello" |
trim | (:string?) | Strips leading/trailing whitespace (null-safe). | trim(" hello ") → "hello" |
replace | (:string, :string, :string) | Literal replacement of every occurrence of the search string. | replace("a.b.c", ".", "-") → "a-b-c" |
matches | (:string, :string) | True if the regex pattern is found in the string. | matches("abc123", "[a-z]+[0-9]+") → true |
match | (:string, :string) | Returns the regex match (full match plus capture groups) as an array, else []. Note: match is also a language keyword, so the builtin is not reachable by name from script source — prefer matches (and capture groups via selectors). | (see note) |
contains | (:any, :any) | Substring test for strings; membership test for arrays; key test for objects. | contains("hello world", "world") → true |
startsWith | (:string, :string) | True if the string begins with the prefix. | startsWith("hello", "he") → true |
endsWith | (:string, :string) | True if the string ends with the suffix. | endsWith("report.csv", ".csv") → true |
splitBy | (:string, :string) | Splits a string on a delimiter into an array. | splitBy("a,b,c", ",") → ["a", "b", "c"] |
joinBy | (:any, :string) | Joins an array into a string with a separator (elements stringified). | joinBy([1, 2, 3], "-") → "1-2-3" |
urlEncode | (:string) | URL-encodes the string (spaces become +). | urlEncode("a b&c") → "a+b%26c" |
urlDecode | (:string) | Decodes a URL-encoded string. | urlDecode("a%20b%26c") → "a b&c" |
DataWeave tip: TransformScript replace is literal (no regex), unlike DataWeave's regex replace. For regex deletion or replacement, use the Strings helpers remove and replaceAll. Also, matches here is an unanchored "found anywhere" test (e.g. matches("abc123xyz", "[0-9]+") → true), whereas DataWeave's matches requires the pattern to match the entire string.
| Function | Signature | Description | Example |
|---|
isEmpty | (:any) | True for null or an empty Array/Object/String. | isEmpty([]) → true |
isBlank | (:any) | True for null or a whitespace-only string. | isBlank(" ") → true |
isEven | (:any) | True if the integer is even (raises on a non-integer). | isEven(4) → true |
isOdd | (:any) | True if the integer is odd. | isOdd(3) → true |
isInteger | (:any) | True if the number has no fractional part. | isInteger(5) → true |
isDecimal | (:any) | True if the number has a fractional part. | isDecimal(4.5) → true |
isLeapYear | (:any) | True if the date's year is a leap year (expects a temporal value). | isLeapYear(toDate("2024-02-01")) → true |
| Function | Signature | Description | Example |
|---|
ifEmpty | (:any, :any) | Returns the fallback when the value is blank (null/empty), else the value. | ifEmpty("", "fallback") → "fallback" |
onNull | (:any, :lambda) | Returns the value unless it's null, in which case it calls the zero-arg lambda. | onNull(null, () -> "default") → "default" |
then | (:any, :lambda) | Threads a value into a lambda (the value-piping idiom). Short-circuits to null if the value is null. | then("hello", (x) -> upper(x)) → "HELLO" |
with | (:lambda, :lambda) | Calls the first lambda, passing the second lambda to it as its argument. | with((replacer) -> replacer(5), (x) -> x * 2) → 10 |
All logging functions write to the log and return their value argument unchanged, so they drop cleanly into a then(…) chain. The prefix is optional.
| Function | Signature | Description | Example |
|---|
log | (:string?, :any) | Logs at info level, returns the value. | log("value", 42) → 42 (logs value: 42) |
logDebug | (:string?, :any) | Logs at debug level. | logDebug("dbg", 1) → 1 |
logInfo | (:string?, :any) | Logs at info level. | logInfo("info", "msg") → "msg" |
logWarn | (:string?, :any) | Logs at warn level. | logWarn("warn", 3) → 3 |
logError | (:string?, :any) | Logs at error level. | logError("err", 2) → 2 |
logWith | (:string, :string?, :any) | Logs at a named level (debug/info/warn/error). | logWith("warn", "label", 99) → 99 |
These produce a different result on each call, so the outputs below are representative only.
| Function | Signature | Description | Example |
|---|
now | () | The current time (zone-aware UTC). | now() → e.g. 2026-06-30 16:08:23 UTC |
uuid | () | A random v4 UUID string. | uuid() → e.g. "b4949875-89bb-49f0-b6f9-56d817115ab2" |
random | () | A random float in [0, 1). | random() → e.g. 0.4479 |
randomInt | (:number) | A random integer in [0, upperBound) (upper bound must be greater than 0). | randomInt(100) → e.g. 39 |
| Function | Signature | Description | Example |
|---|
flatten | (:array) | Recursively flattens nested arrays into one flat array. | flatten([[1, 2], [3, 4]]) → [1, 2, 3, 4] |
zip | (:array, :array) | Pairs elements of two arrays positionally. | zip([1, 2, 3], ["a", "b", "c"]) → [[1, "a"], [2, "b"], [3, "c"]] |
unzip | (:array) | Transposes an array of equal-length tuples (the inverse of zip). | unzip([[1, "a"], [2, "b"]]) → [[1, 2], ["a", "b"]] |
sizeOf | (:any) | Length of an Array, Object, or String (null for null). | sizeOf("hello") → 5 |
indexOf | (:any, :any) | First index of an element (Array) or substring (String); -1 if absent. | indexOf([10, 20, 30], 20) → 1 |
lastIndexOf | (:any, :any) | Last index of an element or substring; -1 if absent. | lastIndexOf([1, 2, 1], 1) → 2 |
typeOf | (:any) | The runtime type name of a value. | typeOf([1, 2]) → "Array" |
daysBetween | (:any, :any) | Whole days from the first date to the second (expects temporal values). | daysBetween(toDate("2024-01-01"), toDate("2024-01-10")) → 9 |