Skip to content

parseDate ​

Category
Tags
Export size
min 1.72 kB · gzip 0.94 kB

Parses the specified fields of an item into Date objects.

ts
  import { 
parseDate
} from 'feathers-utils/transformers';

Example ​

ts
import { transformData, parseDate } from 'feathers-utils/transformers'

transformData(item => parseDate(item, ['startDate', 'endDate']))

Hooks for 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 a shallow copy of the query, which it can change in place (e.g. with lowercase) or replace by returning a new query. 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 for 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.

Type declaration ​

Show Type Declarations
ts
/**
 * Parses the specified fields of an item into Date objects.
 *
 * @example
 * ```ts
 *
 *
 * transformData(item => parseDate(item, ['startDate', 'endDate']))
 * ```
 *
 * @see https://utils.feathersjs.com/transformers/parse-date.html
 */
export declare function parseDate<T extends Record<string, any>>(
  item: T,
  fieldNames: MaybeArray<FieldKey<NoInfer<T>>>,
): void
ArgumentTypeDescription
itemT
fieldNamesMaybeArray<FieldKey<NoInfer<T>>>

Released under the MIT License.