// The one nutrient key of the catalogue (20 FD-02a, FD-08 schema rule): every nutrient column of food.food_version carries the // FAO/INFOODS tag of what it holds and its unit per 100 g or 100 ml. Each importer keeps one table from its own codes to // these columns (import/*.ts); the open tables (FD-57) publish this key with every set, so a row can be read by tag. // Carbohydrate has three tags, told apart by the version's carbohydrate_definition: total (CHOCDF, by difference), // available (CHOAVL, by difference) and available as monosaccharide equivalents (CHOAVLM, by analysis). export const infoodsColumns = { enerc_kcal: { tag: 'ENERC', unit: 'kcal' }, enerc_kj: { tag: 'ENERC', unit: 'kJ' }, procnt_g: { tag: 'PROCNT', unit: 'g' }, fat_g: { tag: 'FAT', unit: 'g' }, chocdf_g: { tag: 'CHOCDF', unit: 'g' }, fibtg_g: { tag: 'FIBTG', unit: 'g' }, sugar_g: { tag: 'SUGAR', unit: 'g' }, sugad_g: { tag: 'SUGAD', unit: 'g' }, fasat_g: { tag: 'FASAT', unit: 'g' }, na_mg: { tag: 'NA', unit: 'mg' }, chole_mg: { tag: 'CHOLE', unit: 'mg' }, k_mg: { tag: 'K', unit: 'mg' }, ca_mg: { tag: 'CA', unit: 'mg' }, fe_mg: { tag: 'FE', unit: 'mg' }, vitd_ug: { tag: 'VITD', unit: 'µg' }, alc_g: { tag: 'ALC', unit: 'g' }, caffn_mg: { tag: 'CAFFN', unit: 'mg' }, water_g: { tag: 'WATER', unit: 'g' }, polyl_g: { tag: 'POLYL', unit: 'g' }, } as const; export type InfoodsColumn = keyof typeof infoodsColumns; export const carbohydrateTags = { total: 'CHOCDF', available: 'CHOAVL', available_mono: 'CHOAVLM' } as const; export type CarbohydrateDefinition = keyof typeof carbohydrateTags; // The INFOODS tag of one value of a version: the column's tag, and for carbohydrate the tag its definition names. export function infoodsTag(column: InfoodsColumn, carbohydrateDefinition: CarbohydrateDefinition) { return column === 'chocdf_g' ? carbohydrateTags[carbohydrateDefinition] : infoodsColumns[column].tag; }