Files
Inventory/frontend/app/shared/utils/apiHelpers.ts
Matthieu 974a4a0781 refactor : merge Inventory_frontend submodule into frontend/ directory
Merges the full git history of Inventory_frontend into the monorepo
under frontend/. Removes the submodule in favor of a unified repo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:17:57 +02:00

17 lines
624 B
TypeScript

/**
* Shared API response helpers.
*
* Extracted from 10+ composables/components that each had an identical local
* copy of extractCollection (parsing hydra:member / member / data / array).
*/
export function extractCollection<T = any>(payload: unknown): T[] {
if (Array.isArray(payload)) return payload as T[]
const p = payload as Record<string, unknown> | null
if (Array.isArray(p?.member)) return p!.member as T[]
if (Array.isArray(p?.['hydra:member'])) return p!['hydra:member'] as T[]
if (Array.isArray(p?.items)) return p!.items as T[]
if (Array.isArray(p?.data)) return p!.data as T[]
return []
}