Whatever message this page gives is out now! Go check it out!

transform

Last update:
May 18, 2026
Applies a user-defined UDF transformation to each document in the Array. Use this method to clean text, enrich metadata, or filter documents before splitting.

Syntax

docService.transform(documents, transformer)

Parameters

Parameter
Type
Required
Description
documents
Array
Required
Array of document Structs as returned by load().
transformer
UDF / Closure
Required
Function with signature function(required Struct document) that returns a modified document Struct. The function may also return an Array to expand one document into multiple documents.

Returns

Returns an Array of transformed document Structs.

Example

cleaned = docService.transform(documents, function(required document) {
    // Strip extra whitespace and add processing timestamp
    document.text = reReplace(document.text, "\s+", " ", "ALL");
    document.metadata.processedAt = now();
    return document;
});

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page