All files / app/src/shared/helpers iri.helpers.ts

21.42% Statements 3/14
33.33% Branches 1/3
50% Functions 1/2
21.42% Lines 3/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191x   1x 20x                              
export const extractIds = (filePaths: string[]): string[] => filePaths.map(path => path.split('/').pop() as string)
 
export const getFieldIdsFromCollection = <T>(field: keyof T, collection?: T[]): string[] => {
  if (!collection?.length) return []
 
  const dataIRIs = (collection as T[]).reduce<string[]>((acc, item) => {
    const value = item?.[field]
 
    if (Array.isArray(value)) {
      acc = [...acc, ...extractIds(value)]
    } else if (typeof value === 'string') {
      acc.push(...extractIds([value]))
    }
    return acc
  }, [])
 
  return dataIRIs
}