Created
March 22, 2026 18:39
-
-
Save blopa/daa60139ac799069af61f1c7a81767aa to your computer and use it in GitHub Desktop.
Code for post "Musclo: Redesign do acompanhamento nutricional e por que a assinatura do seu app de fitness é uma enganação"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // utils/usdaMapper.ts | |
| export function mapUSDAFoodToUnified(food: USDAFood): UnifiedFoodResult { | |
| const nutrients = food.foodNutrients; | |
| // USDA usa códigos numéricos de nutrientes — 1008/208 é energia, 1003/203 é proteína, etc. | |
| const calories = mapUSDANutritient(nutrients, '1008') ?? mapUSDANutritient(nutrients, '208'); | |
| const protein = mapUSDANutritient(nutrients, '1003') ?? mapUSDANutritient(nutrients, '203'); | |
| const carbs = mapUSDANutritient(nutrients, '1005') ?? mapUSDANutritient(nutrients, '205'); | |
| const fat = mapUSDANutritient(nutrients, '1004') ?? mapUSDANutritient(nutrients, '204'); | |
| const fiber = mapUSDANutritient(nutrients, '1079') ?? mapUSDANutritient(nutrients, '291'); | |
| return { | |
| id: String(food.fdcId), | |
| name: food.description, | |
| brand: food.brandOwner, | |
| calories: calories !== undefined ? Math.round(calories) : undefined, | |
| protein, carbs, fat, fiber, | |
| source: 'usda', | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment