Skip to content

getDataIsArray

utils
Source Code | Documentation

Normalizes context.data into an array for uniform processing. Returns { data, isArray } where data is always an array and isArray indicates whether the original value was already an array.

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

Example

ts
import { getDataIsArray } from 'feathers-utils/utils'

const { data, isArray } = getDataIsArray(context)
data.forEach(item => { /* process each item *\/ })

Type declaration

Show Type Declarations
ts
export type GetDataIsArrayReturn<H extends HookContext = HookContext> = {
  isArray: boolean
  data: DataSingleHookContext<H>[]
}
/**
 * Normalizes `context.data` into an array for uniform processing.
 * Returns `{ data, isArray }` where `data` is always an array and `isArray` indicates
 * whether the original value was already an array.
 *
 * @example
 * ```ts
 *
 *
 * const { data, isArray } = getDataIsArray(context)
 * data.forEach(item => { /* process each item *\/ })
 * ```
 *
 * @see https://utils.feathersjs.com/utils/get-data-is-array.html
 */
export declare function getDataIsArray<H extends HookContext = HookContext>(
  context: H,
): GetDataIsArrayReturn<H>
ArgumentTypeDescription
contextH

Released under the MIT License.