omitPaths
Returns a copy of object without the given paths. Paths may be nested ('user.email'), in which case the objects on the way are copied so the source keeps its key; untouched branches stay shared by reference. Arrays and class instances on the path are copied too — nothing here writes into what it was handed.
Each entry of paths is one path, and a segment array is one nested path — the same reading as in getPath/hasPath/setPath.
import { omitPaths } from 'feathers-utils/helpers';Example
import { omitPaths } from 'feathers-utils/helpers'
omitPaths({ id: 1, user: { email: '[email protected]', name: 'a' } }, ['user.email'])
// => { id: 1, user: { name: 'a' } }Type declaration
Show Type Declarations
/**
* Returns a copy of `object` without the given paths. Paths may be nested
* (`'user.email'`), in which case the objects on the way are copied so the
* source keeps its key; untouched branches stay shared by reference. Arrays and
* class instances on the path are copied too — nothing here writes into what it
* was handed.
*
* Each entry of `paths` is one path, and a segment array is one nested path —
* the same reading as in `getPath`/`hasPath`/`setPath`.
*
* @example
* ```ts
*
*
* omitPaths({ id: 1, user: { email: '[email protected]', name: 'a' } }, ['user.email'])
* // => { id: 1, user: { name: 'a' } }
* ```
*
* @see https://utils.feathersjs.com/helpers/omit-paths.html
*/
export declare const omitPaths: <T extends Record<PropertyKey, any>>(
object: T | null | undefined,
paths: readonly PropertyPath[],
) => Partial<T>| Argument | Type | Description |
|---|---|---|
| object | T | null | undefined | |
| paths | readonly PropertyPath[] |
Coming from lodash
Given a nested path, _.omit deep-clones its whole input before deleting; omitPaths copies only the objects on the omitted paths. The result is the same, but untouched branches stay the same reference — cheaper, and safe for values compared by identity (params.connection, an ObjectId). Unlike _.omit, inherited enumerable properties are not copied into the result.
To omit fields of context.data or context.result inside a hook, prefer the omit transformer.
