Skip to content

Transformers

Transformers are functions that modify the data or result of a Feathers service call. They can be used to apply transformations such as trimming strings, converting dates, or omitting fields from the data or result.

Built-in Transformers

TransformerDescription
lowercase

Transforms the specified fields of an item to lowercase.

omit

Omit the specified fields from an item.

parseDate

Parses the specified fields of an item into Date objects.

pick

Picks the specified fields from an item.

setNow

Sets the specified fields of an item to the current date and time.

trim

Trims the specified fields of an item.

Hooks that are meant to be used with transformers:

HookDescription
transformData

Transforms each item in context.data using the provided transformer function. The transformer receives each item and can mutate it in place or return a new object. Commonly used with built-in transformers like lowercase, trim, or setNow.

transformQuery

Transforms context.params.query using the provided transformer function. The transformer receives the current query and can return a modified version. Useful for normalizing, sanitizing, or enriching queries before they hit the database.

transformResult

Transforms each item in context.result using the provided transformer function. The transformer receives each item and can mutate it in place or return a new object. Optionally operates on context.dispatch via the dispatch option.

Utilities that are meant to be used with transformers:

UtilityDescription
mutateData

Applies a transformer function to each item in context.data, updating it in place. If the transformer returns a new object, it replaces the original item. Correctly handles both single-item and array data, preserving the original shape.

mutateResult

Applies a transformer function to each item in context.result (and optionally context.dispatch). Handles paginated results, single items, and arrays transparently. Use the dispatch option to control whether result, dispatch, or both are transformed.

Released under the MIT License.