Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ingredient-math

brianbolnick2MIT0.1.2

Library for converting ingredients based on serving size changes

ingredient, math, recipe

readme

Ingredient Math

This library is for converting recipe ingredients based on a serving size factor.

Installation

yarn add ingredient-math

Example

import { convertIngredient } from 'ingredient-math';

const ingredient = "1 teaspoon sugar"
const servingsFactor(2)

> convertIngredient(ingredient, servingsFactor)
{
    quantity: "2",
    unit: "teaspoons"
    ingredient: "sugar"
}

It will also automatically calculate and convert units:

import { convertIngredient } from 'ingredient-math';

const ingredient = "1 teaspoon sugar"
const servingsFactor(3)

> convertIngredient(ingredient, servingsFactor)

{
    quantity: "3",
    unit: "tablespoons"
    ingredient: "sugar"
}