Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
parse-ingredient
Advanced tools
[![npm version](https://badge.fury.io/js/parse-ingredient.svg)](//npmjs.com/package/parse-ingredient) ![workflow status](https://github.com/jakeboone02/parse-ingredient/workflows/Continuous%20Integration/badge.svg) [![codecov.io](https://codecov.io/github
Parses a string, which can include mixed numbers or vulgar fractions (thanks to numeric-quantity), into an array of ingredient objects with the following signature:
interface Ingredient {
/**
* The primary quantity (the lower quantity in a range, if applicable)
*/
quantity: number;
/**
* The secondary quantity (the upper quantity in a range or `0` if not applicable)
*/
quantity2: number;
/**
* The unit of measure
*/
unitOfMeasure: string;
/**
* The description
*/
description: string;
/**
* Whether the "ingredient" is actually a group header, e.g. "For icing:"
*/
isGroupHeader: boolean;
}
For the isGroupHeader
attribute to be true
, the ingredient string must not start with a number, and must either start with 'For'
or end with ':'
.
This library pairs nicely with format-quantity which can display numeric values as imperial measurements (e.g. '1 1/2'
instead of 1.5
).
# npm
npm i parse-ingredient
# yarn
yarn add parse-ingredient
In the browser, available as a global function parseIngredient
. Remember to first include numeric-quantity
.
<script src="https://unpkg.com/numeric-quantity"></script>
<script src="https://unpkg.com/parse-ingredient"></script>
<script>
console.log(parseIngredient('1 1/2 cups sugar'));
/**
* [
* {
* quantity: 1.5,
* quantity2: null,
* unitOfMeasure: 'cups',
* description: 'sugar',
* isGroupHeader: false,
* }
* ]
*/
</script>
import parseIngredient from 'parse-ingredient';
console.log(parseIngredient('1-2 pears'));
/**
* [
* {
* quantity: 1,
* quantity2: 2,
* unitOfMeasure: null,
* description: 'pears',
* isGroupHeader: false,
* }
* ]
*/
console.log(
parseIngredient(
`2/3 cup flour
1 tsp baking powder`
)
);
/**
* [
* {
* quantity: 0.666,
* quantity2: null,
* unitOfMeasure: 'cup',
* description: 'flour',
* isGroupHeader: false,
* },
* {
* quantity: 1,
* quantity2: null,
* unitOfMeasure: 'tsp',
* description: 'baking powder',
* isGroupHeader: false,
* },
* ]
*/
console.log(parseIngredient('For cake:'));
/**
* [
* {
* quantity: null,
* quantity2: null,
* unitOfMeasure: null,
* description: 'For cake:',
* isGroupHeader: true,
* }
* ]
*/
[v0.1.2] - 2021-02-11
FAQs
Recipe ingredient parser with support for mixed numbers and vulgar fractions
The npm package parse-ingredient receives a total of 373 weekly downloads. As such, parse-ingredient popularity was classified as not popular.
We found that parse-ingredient demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.