mutateData
utils
Source Code | DocumentationSee also: hooks/transformData transformers
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.
ts
import { mutateData } from 'feathers-utils/utils';Example
ts
import { mutateData } from 'feathers-utils/utils'
await mutateData(context, (item) => { item.name = item.name.trim() })Type declaration
Show Type Declarations
ts
/**
* 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.
*
* @example
* ```ts
*
*
* await mutateData(context, (item) => { item.name = item.name.trim() })
* ```
*
* @see https://utils.feathersjs.com/utils/mutate-data.html
*/
export declare function mutateData<H extends HookContext = HookContext>(
context: H,
transformer: TransformerFn<any, H>,
): Promisable<H>| Argument | Type | Description |
|---|---|---|
| context | H | |
| transformer | TransformerFn<any, H> |
