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 { 
getDataIsArray
} 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
/**
 * 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,
): {
  data: any[]
  isArray: boolean
}
ArgumentTypeDescription
contextH

Released under the MIT License.