Skip to content

Commit

Permalink
Ignore blank lines in multi-line input
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeboone02 committed Feb 12, 2021
1 parent 7f0a113 commit c9d8fed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ it('works', () => {
]);
expect(
parseIngredient(`2/3 cup sugar
1 tsp baking powder`)
).toEqual([
{
quantity: 0.667,
quantity2: null,
unitOfMeasure: 'cup',
description: 'sugar',
isGroupHeader: false,
},
{
quantity: 1,
quantity2: null,
unitOfMeasure: 'tsp',
description: 'baking powder',
isGroupHeader: false,
},
]);
expect(
parseIngredient(`2/3 cup sugar
1 tsp baking powder`)
).toEqual([
{
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ const UOM_LIST = [
];

const parseIngredient = (ingText: string): Ingredient[] => {
const arrRaw = ingText.split('\n').map(ing => ing.trim());
const arrRaw = ingText
.replace(/\n{2,}/g, '\n')
.split('\n')
.map(ing => ing.trim());
const arrIngs = [];
const arrRawLen = arrRaw.length;

Expand Down

0 comments on commit c9d8fed

Please sign in to comment.