Skip to content

Commit

Permalink
fix food and add meal
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBresson committed Apr 16, 2021
1 parent 1b02c05 commit c89435e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "carbon-footprint",
"version": "1.5.1",
"version": "1.5.2",
"description": "Calculate your carbon footprint. Food, transport, purchases, fashion, electricity and digital activities like streaming.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { getInternetUsageCarbonImpact } from './internet';
import { streaming, StreamingType } from './streaming';
import { purchase, PurchaseType } from './purchase';
import { fashion, FashionType } from './fashion';
import { meal, MealType } from './meal';

export {
meal,
MealType,
food,
FoodType,
transport,
Expand Down
14 changes: 14 additions & 0 deletions src/meal/__tests__/meal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { keys, map } from 'ramda';
import { meal, MealType } from '../';

test('All meal keys should contain a valid number', () => {
const foodKeys = keys(meal);
map((item: number) => expect(typeof foodKeys[item]).toBe('number'));
});

test('Number of default exports equals number of enums', () => {
const enumsCount = Object.keys(MealType).length;
const defaultExportsCount = Object.keys(meal).length;

expect(defaultExportsCount).toEqual(enumsCount);
});
4 changes: 4 additions & 0 deletions src/meal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import meal from './meal';
import { MealType } from './meal.enum';

export { meal, MealType };
8 changes: 8 additions & 0 deletions src/meal/meal.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum MealType {
highMeat = 'highMeat',
mediumMeat = 'mediumMeat',
lowMeat = 'lowMeat',
pescetarian = 'pescetarian',
vegetarian = 'vegetarian',
vegan = 'vegan',
}
21 changes: 21 additions & 0 deletions src/meal/meal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Unit: kgCO2eq per meal */

/* https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4372775/ */
/* Mean greenhouse gas emissions per 2,000 kcal */
/* https://globalnews.ca/news/3615212/this-is-what-your-breakfast-lunch-and-dinner-calories-actually-look-like/ */
/* Human get around 600 calories per meal */
const highMeat = (7.19 * 600) / 2000;
const mediumMeat = (5.63 * 600) / 2000;
const lowMeat = (4.67 * 600) / 2000;
const pescetarian = (3.91 * 600) / 2000;
const vegetarian = (3.81 * 600) / 2000;
const vegan = (2.89 * 600) / 2000;

export default {
highMeat,
mediumMeat,
lowMeat,
pescetarian,
vegetarian,
vegan,
};

0 comments on commit c89435e

Please sign in to comment.