Skip to content

getResultIsArray

utils
Source Code | Documentation

Normalizes context.result (or context.dispatch) into an array for uniform processing. Handles paginated results by extracting the data array. Returns { result, isArray, key } where key indicates whether 'result' or 'dispatch' was used.

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

Example

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

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

Type declaration

Show Type Declarations
ts
type GetResultIsArrayOptions = {
  dispatch?: boolean
}
/**
 * Normalizes `context.result` (or `context.dispatch`) into an array for uniform processing.
 * Handles paginated results by extracting the `data` array. Returns `{ result, isArray, key }`
 * where `key` indicates whether `'result'` or `'dispatch'` was used.
 *
 * @example
 * ```ts
 *
 *
 * const { result, isArray } = getResultIsArray(context)
 * result.forEach(item => { /* process each item *\/ })
 * ```
 *
 * @see https://utils.feathersjs.com/utils/get-result-is-array.html
 */
export declare function getResultIsArray<H extends HookContext = HookContext>(
  context: H,
  options?: GetResultIsArrayOptions,
): {
  isArray: boolean
  result: any[]
  key: "dispatch" | "result"
}
ArgumentTypeDescription
contextH
optionsGetResultIsArrayOptions

Released under the MIT License.