parse-ingredient
Advanced tools
Comparing version 0.2.4 to 0.3.0
## Change Log | ||
### v0.2.4 (2021-02-15) | ||
- [1391a0f](https://github.com/jakeboone02/parse-ingredient/commit/1391a0f9c2559550c3bed5474abd0cb9cd75e794) v0.2.4 (@jakeboone02) | ||
- [9929441](https://github.com/jakeboone02/parse-ingredient/commit/9929441c8701072124df2d620229aa16cfb65182) Add support for the word "to" to indicate a range (@jakeboone02) | ||
- [2dc25ec](https://github.com/jakeboone02/parse-ingredient/commit/2dc25ecaf05a4486d9a9ef496751f7e3720181d8) Add CHANGELOG.md (@jakeboone02) | ||
### v0.2.3 (2021-02-15) | ||
@@ -4,0 +9,0 @@ - [a14247c](https://github.com/jakeboone02/parse-ingredient/commit/a14247c1cf903eaff8b5c2d2f9f8a47fa4af6934) v0.2.3 (@jakeboone02) |
@@ -23,2 +23,5 @@ export interface Ingredient { | ||
} | ||
export interface ParseIngredientOptions { | ||
normalizeUOM?: boolean; | ||
} | ||
/** | ||
@@ -28,3 +31,3 @@ * Parses a string into an array of recipe ingredient objects | ||
*/ | ||
declare const parseIngredient: (ingText: string) => Ingredient[]; | ||
declare const parseIngredient: (ingText: string, options?: ParseIngredientOptions | undefined) => Ingredient[]; | ||
export default parseIngredient; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var UOM_LIST = ['cup', 'cups', 'c', 'c.', 'C', 'teaspoon', 'teaspoons', 'tsp', 'tsp.', 't', 'tablespoon', 'tablespoons', 'tbsp', 'tbsp.', 'T', 'ounce', 'ounces', 'oz', 'oz.', 'pint', 'pints', 'pt', 'pt.', 'pound', 'pounds', 'lb', 'lb.', 'lbs', 'lbs.', 'gram', 'grams', 'g', 'g.', 'kilogram', 'kilograms', 'kg', 'kg.', 'stick', 'sticks', 'inch', 'inches', 'in', 'in.', 'foot', 'feet', 'ft', 'ft.', 'quart', 'quarts', 'qt', 'qt.', 'liter', 'liters', 'l']; | ||
var UOM_LIST = [['cup', 'cups', 'c', 'c.', 'C'], ['teaspoon', 'teaspoons', 'tsp', 'tsp.', 't'], ['tablespoon', 'tablespoons', 'tbsp', 'tbsp.', 'T'], ['ounce', 'ounces', 'oz', 'oz.'], ['pint', 'pints', 'pt', 'pt.'], ['pound', 'pounds', 'lb', 'lb.', 'lbs', 'lbs.'], ['gram', 'grams', 'g', 'g.'], ['kilogram', 'kilograms', 'kg', 'kg.'], ['stick', 'sticks'], ['inch', 'inches', 'in', 'in.'], ['foot', 'feet', 'ft', 'ft.'], ['quart', 'quarts', 'qt', 'qt.'], ['liter', 'liters', 'l'], ['pinch', 'pinches'], ['piece', 'pieces', 'pcs', 'pcs.'], ['milligram', 'mg', 'mg.'], ['milliliter', 'ml', 'mL', 'ml.', 'mL.'], ['quart', 'quarts', 'qt', 'qt.', 'qts', 'qts.'], ['gallon', 'gallons', 'gal', 'gal.']]; | ||
/** | ||
@@ -37,3 +37,3 @@ * Removes falsy values from an array | ||
var parseIngredient = function parseIngredient(ingText) { | ||
var parseIngredient = function parseIngredient(ingText, options) { | ||
var arrRaw = compactArray(ingText.replace(/\n{2,}/g, '\n').split('\n').map(function (ing) { | ||
@@ -107,8 +107,32 @@ return ing.trim(); | ||
var firstSpace = oIng.description.indexOf(' '); | ||
var firstWord = oIng.description.substring(0, firstSpace); | ||
var firstWordRE = /^([a-zA-Z.]+)\b(.+)/; | ||
var firstWordREMatches = firstWordRE.exec(oIng.description); | ||
if (UOM_LIST.indexOf(firstWord) >= 0) { | ||
oIng.unitOfMeasure = firstWord; | ||
oIng.description = oIng.description.substring(firstSpace + 1); | ||
if (firstWordREMatches) { | ||
var firstWord = firstWordREMatches[1]; | ||
var remainingDesc = firstWordREMatches[2]; | ||
var uom = ''; | ||
var uomBase = ''; | ||
var i = 0; | ||
while (i < UOM_LIST.length && !uom) { | ||
var ndx = UOM_LIST[i].indexOf(firstWord); | ||
if (ndx >= 0) { | ||
uom = UOM_LIST[i][ndx]; | ||
uomBase = UOM_LIST[i][0]; | ||
} | ||
i++; | ||
} | ||
if (uom) { | ||
if (options != null && options.normalizeUOM) { | ||
oIng.unitOfMeasure = uomBase; | ||
} else { | ||
oIng.unitOfMeasure = uom; | ||
} | ||
oIng.description = remainingDesc.trim(); | ||
} | ||
} | ||
@@ -115,0 +139,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";var t,i=(t=require("numeric-quantity"))&&"object"==typeof t&&"default"in t?t.default:t,s=["cup","cups","c","c.","C","teaspoon","teaspoons","tsp","tsp.","t","tablespoon","tablespoons","tbsp","tbsp.","T","ounce","ounces","oz","oz.","pint","pints","pt","pt.","pound","pounds","lb","lb.","lbs","lbs.","gram","grams","g","g.","kilogram","kilograms","kg","kg.","stick","sticks","inch","inches","in","in.","foot","feet","ft","ft.","quart","quarts","qt","qt.","liter","liters","l"];module.exports=function(t){return function(t){for(var i=-1,s=t.length,r=0,n=[];++i<s;){var e=t[i];e&&(n[r++]=e)}return n}(t.replace(/\n{2,}/g,"\n").split("\n").map((function(t){return t.trim()}))).map((function(t){var r={quantity:null,quantity2:null,unitOfMeasure:null,description:"",isGroupHeader:!1},n=i(t.substring(0,1));if(isNaN(n))r.description=t,(/:$/.test(r.description)||/^For /i.test(r.description))&&(r.isGroupHeader=!0);else for(var e=6,o=NaN;e>0&&isNaN(o);)(o=i(t.substring(0,e).trim()))>-1&&(r.quantity=o,r.description=t.substring(e).trim()),e--;var u=/^(-|–|—|to )/i.exec(r.description);if(u){var a=u[1].length,p=i(r.description.substring(a).trim().substring(0,1));if(!isNaN(p))for(var c=6,l=NaN;c>0&&isNaN(l);)l=i(r.description.substring(a,c)),isNaN(l)||(r.quantity2=l,r.description=r.description.substring(c).trim()),c--}var d=r.description.indexOf(" "),f=r.description.substring(0,d);return s.indexOf(f)>=0&&(r.unitOfMeasure=f,r.description=r.description.substring(d+1)),r}))}; | ||
"use strict";var t,i=(t=require("numeric-quantity"))&&"object"==typeof t&&"default"in t?t.default:t,r=[["cup","cups","c","c.","C"],["teaspoon","teaspoons","tsp","tsp.","t"],["tablespoon","tablespoons","tbsp","tbsp.","T"],["ounce","ounces","oz","oz."],["pint","pints","pt","pt."],["pound","pounds","lb","lb.","lbs","lbs."],["gram","grams","g","g."],["kilogram","kilograms","kg","kg."],["stick","sticks"],["inch","inches","in","in."],["foot","feet","ft","ft."],["quart","quarts","qt","qt."],["liter","liters","l"],["pinch","pinches"],["piece","pieces","pcs","pcs."],["milligram","mg","mg."],["milliliter","ml","mL","ml.","mL."],["quart","quarts","qt","qt.","qts","qts."],["gallon","gallons","gal","gal."]];module.exports=function(t,s){return function(t){for(var i=-1,r=t.length,s=0,n=[];++i<r;){var e=t[i];e&&(n[s++]=e)}return n}(t.replace(/\n{2,}/g,"\n").split("\n").map((function(t){return t.trim()}))).map((function(t){var n={quantity:null,quantity2:null,unitOfMeasure:null,description:"",isGroupHeader:!1},e=i(t.substring(0,1));if(isNaN(e))n.description=t,(/:$/.test(n.description)||/^For /i.test(n.description))&&(n.isGroupHeader=!0);else for(var a=6,o=NaN;a>0&&isNaN(o);)(o=i(t.substring(0,a).trim()))>-1&&(n.quantity=o,n.description=t.substring(a).trim()),a--;var u=/^(-|–|—|to )/i.exec(n.description);if(u){var l=u[1].length,p=i(n.description.substring(l).trim().substring(0,1));if(!isNaN(p))for(var c=6,g=NaN;c>0&&isNaN(g);)g=i(n.description.substring(l,c)),isNaN(g)||(n.quantity2=g,n.description=n.description.substring(c).trim()),c--}var m=/^([a-zA-Z.]+)\b(.+)/.exec(n.description);if(m){for(var f=m[1],d=m[2],b="",q="",N=0;N<r.length&&!b;){var v=r[N].indexOf(f);v>=0&&(b=r[N][v],q=r[N][0]),N++}b&&(n.unitOfMeasure=null!=s&&s.normalizeUOM?q:b,n.description=d.trim())}return n}))}; | ||
//# sourceMappingURL=parse-ingredient.cjs.production.min.js.map |
import numericQuantity from 'numeric-quantity'; | ||
var UOM_LIST = ['cup', 'cups', 'c', 'c.', 'C', 'teaspoon', 'teaspoons', 'tsp', 'tsp.', 't', 'tablespoon', 'tablespoons', 'tbsp', 'tbsp.', 'T', 'ounce', 'ounces', 'oz', 'oz.', 'pint', 'pints', 'pt', 'pt.', 'pound', 'pounds', 'lb', 'lb.', 'lbs', 'lbs.', 'gram', 'grams', 'g', 'g.', 'kilogram', 'kilograms', 'kg', 'kg.', 'stick', 'sticks', 'inch', 'inches', 'in', 'in.', 'foot', 'feet', 'ft', 'ft.', 'quart', 'quarts', 'qt', 'qt.', 'liter', 'liters', 'l']; | ||
var UOM_LIST = [['cup', 'cups', 'c', 'c.', 'C'], ['teaspoon', 'teaspoons', 'tsp', 'tsp.', 't'], ['tablespoon', 'tablespoons', 'tbsp', 'tbsp.', 'T'], ['ounce', 'ounces', 'oz', 'oz.'], ['pint', 'pints', 'pt', 'pt.'], ['pound', 'pounds', 'lb', 'lb.', 'lbs', 'lbs.'], ['gram', 'grams', 'g', 'g.'], ['kilogram', 'kilograms', 'kg', 'kg.'], ['stick', 'sticks'], ['inch', 'inches', 'in', 'in.'], ['foot', 'feet', 'ft', 'ft.'], ['quart', 'quarts', 'qt', 'qt.'], ['liter', 'liters', 'l'], ['pinch', 'pinches'], ['piece', 'pieces', 'pcs', 'pcs.'], ['milligram', 'mg', 'mg.'], ['milliliter', 'ml', 'mL', 'ml.', 'mL.'], ['quart', 'quarts', 'qt', 'qt.', 'qts', 'qts.'], ['gallon', 'gallons', 'gal', 'gal.']]; | ||
/** | ||
@@ -32,3 +32,3 @@ * Removes falsy values from an array | ||
var parseIngredient = function parseIngredient(ingText) { | ||
var parseIngredient = function parseIngredient(ingText, options) { | ||
var arrRaw = compactArray(ingText.replace(/\n{2,}/g, '\n').split('\n').map(function (ing) { | ||
@@ -102,8 +102,32 @@ return ing.trim(); | ||
var firstSpace = oIng.description.indexOf(' '); | ||
var firstWord = oIng.description.substring(0, firstSpace); | ||
var firstWordRE = /^([a-zA-Z.]+)\b(.+)/; | ||
var firstWordREMatches = firstWordRE.exec(oIng.description); | ||
if (UOM_LIST.indexOf(firstWord) >= 0) { | ||
oIng.unitOfMeasure = firstWord; | ||
oIng.description = oIng.description.substring(firstSpace + 1); | ||
if (firstWordREMatches) { | ||
var firstWord = firstWordREMatches[1]; | ||
var remainingDesc = firstWordREMatches[2]; | ||
var uom = ''; | ||
var uomBase = ''; | ||
var i = 0; | ||
while (i < UOM_LIST.length && !uom) { | ||
var ndx = UOM_LIST[i].indexOf(firstWord); | ||
if (ndx >= 0) { | ||
uom = UOM_LIST[i][ndx]; | ||
uomBase = UOM_LIST[i][0]; | ||
} | ||
i++; | ||
} | ||
if (uom) { | ||
if (options != null && options.normalizeUOM) { | ||
oIng.unitOfMeasure = uomBase; | ||
} else { | ||
oIng.unitOfMeasure = uom; | ||
} | ||
oIng.description = remainingDesc.trim(); | ||
} | ||
} | ||
@@ -110,0 +134,0 @@ |
@@ -10,3 +10,3 @@ System.register('parseIngredient', ['numeric-quantity'], function (exports) { | ||
var UOM_LIST = ['cup', 'cups', 'c', 'c.', 'C', 'teaspoon', 'teaspoons', 'tsp', 'tsp.', 't', 'tablespoon', 'tablespoons', 'tbsp', 'tbsp.', 'T', 'ounce', 'ounces', 'oz', 'oz.', 'pint', 'pints', 'pt', 'pt.', 'pound', 'pounds', 'lb', 'lb.', 'lbs', 'lbs.', 'gram', 'grams', 'g', 'g.', 'kilogram', 'kilograms', 'kg', 'kg.', 'stick', 'sticks', 'inch', 'inches', 'in', 'in.', 'foot', 'feet', 'ft', 'ft.', 'quart', 'quarts', 'qt', 'qt.', 'liter', 'liters', 'l']; | ||
var UOM_LIST = [['cup', 'cups', 'c', 'c.', 'C'], ['teaspoon', 'teaspoons', 'tsp', 'tsp.', 't'], ['tablespoon', 'tablespoons', 'tbsp', 'tbsp.', 'T'], ['ounce', 'ounces', 'oz', 'oz.'], ['pint', 'pints', 'pt', 'pt.'], ['pound', 'pounds', 'lb', 'lb.', 'lbs', 'lbs.'], ['gram', 'grams', 'g', 'g.'], ['kilogram', 'kilograms', 'kg', 'kg.'], ['stick', 'sticks'], ['inch', 'inches', 'in', 'in.'], ['foot', 'feet', 'ft', 'ft.'], ['quart', 'quarts', 'qt', 'qt.'], ['liter', 'liters', 'l'], ['pinch', 'pinches'], ['piece', 'pieces', 'pcs', 'pcs.'], ['milligram', 'mg', 'mg.'], ['milliliter', 'ml', 'mL', 'ml.', 'mL.'], ['quart', 'quarts', 'qt', 'qt.', 'qts', 'qts.'], ['gallon', 'gallons', 'gal', 'gal.']]; | ||
/** | ||
@@ -40,3 +40,3 @@ * Removes falsy values from an array | ||
var parseIngredient = function parseIngredient(ingText) { | ||
var parseIngredient = function parseIngredient(ingText, options) { | ||
var arrRaw = compactArray(ingText.replace(/\n{2,}/g, '\n').split('\n').map(function (ing) { | ||
@@ -110,8 +110,32 @@ return ing.trim(); | ||
var firstSpace = oIng.description.indexOf(' '); | ||
var firstWord = oIng.description.substring(0, firstSpace); | ||
var firstWordRE = /^([a-zA-Z.]+)\b(.+)/; | ||
var firstWordREMatches = firstWordRE.exec(oIng.description); | ||
if (UOM_LIST.indexOf(firstWord) >= 0) { | ||
oIng.unitOfMeasure = firstWord; | ||
oIng.description = oIng.description.substring(firstSpace + 1); | ||
if (firstWordREMatches) { | ||
var firstWord = firstWordREMatches[1]; | ||
var remainingDesc = firstWordREMatches[2]; | ||
var uom = ''; | ||
var uomBase = ''; | ||
var i = 0; | ||
while (i < UOM_LIST.length && !uom) { | ||
var ndx = UOM_LIST[i].indexOf(firstWord); | ||
if (ndx >= 0) { | ||
uom = UOM_LIST[i][ndx]; | ||
uomBase = UOM_LIST[i][0]; | ||
} | ||
i++; | ||
} | ||
if (uom) { | ||
if (options != null && options.normalizeUOM) { | ||
oIng.unitOfMeasure = uomBase; | ||
} else { | ||
oIng.unitOfMeasure = uom; | ||
} | ||
oIng.description = remainingDesc.trim(); | ||
} | ||
} | ||
@@ -118,0 +142,0 @@ |
@@ -1,2 +0,2 @@ | ||
System.register("parseIngredient",["numeric-quantity"],(function(t){"use strict";var i;return{setters:[function(t){i=t.default}],execute:function(){var n=["cup","cups","c","c.","C","teaspoon","teaspoons","tsp","tsp.","t","tablespoon","tablespoons","tbsp","tbsp.","T","ounce","ounces","oz","oz.","pint","pints","pt","pt.","pound","pounds","lb","lb.","lbs","lbs.","gram","grams","g","g.","kilogram","kilograms","kg","kg.","stick","sticks","inch","inches","in","in.","foot","feet","ft","ft.","quart","quarts","qt","qt.","liter","liters","l"];t("default",(function(t){return function(t){for(var i=-1,n=t.length,s=0,r=[];++i<n;){var e=t[i];e&&(r[s++]=e)}return r}(t.replace(/\n{2,}/g,"\n").split("\n").map((function(t){return t.trim()}))).map((function(t){var s={quantity:null,quantity2:null,unitOfMeasure:null,description:"",isGroupHeader:!1},r=i(t.substring(0,1));if(isNaN(r))s.description=t,(/:$/.test(s.description)||/^For /i.test(s.description))&&(s.isGroupHeader=!0);else for(var e=6,u=NaN;e>0&&isNaN(u);)(u=i(t.substring(0,e).trim()))>-1&&(s.quantity=u,s.description=t.substring(e).trim()),e--;var o=/^(-|–|—|to )/i.exec(s.description);if(o){var a=o[1].length,p=i(s.description.substring(a).trim().substring(0,1));if(!isNaN(p))for(var c=6,l=NaN;c>0&&isNaN(l);)l=i(s.description.substring(a,c)),isNaN(l)||(s.quantity2=l,s.description=s.description.substring(c).trim()),c--}var d=s.description.indexOf(" "),f=s.description.substring(0,d);return n.indexOf(f)>=0&&(s.unitOfMeasure=f,s.description=s.description.substring(d+1)),s}))}))}}})); | ||
System.register("parseIngredient",["numeric-quantity"],(function(t){"use strict";var i;return{setters:[function(t){i=t.default}],execute:function(){var r=[["cup","cups","c","c.","C"],["teaspoon","teaspoons","tsp","tsp.","t"],["tablespoon","tablespoons","tbsp","tbsp.","T"],["ounce","ounces","oz","oz."],["pint","pints","pt","pt."],["pound","pounds","lb","lb.","lbs","lbs."],["gram","grams","g","g."],["kilogram","kilograms","kg","kg."],["stick","sticks"],["inch","inches","in","in."],["foot","feet","ft","ft."],["quart","quarts","qt","qt."],["liter","liters","l"],["pinch","pinches"],["piece","pieces","pcs","pcs."],["milligram","mg","mg."],["milliliter","ml","mL","ml.","mL."],["quart","quarts","qt","qt.","qts","qts."],["gallon","gallons","gal","gal."]];t("default",(function(t,n){return function(t){for(var i=-1,r=t.length,n=0,s=[];++i<r;){var e=t[i];e&&(s[n++]=e)}return s}(t.replace(/\n{2,}/g,"\n").split("\n").map((function(t){return t.trim()}))).map((function(t){var s={quantity:null,quantity2:null,unitOfMeasure:null,description:"",isGroupHeader:!1},e=i(t.substring(0,1));if(isNaN(e))s.description=t,(/:$/.test(s.description)||/^For /i.test(s.description))&&(s.isGroupHeader=!0);else for(var a=6,u=NaN;a>0&&isNaN(u);)(u=i(t.substring(0,a).trim()))>-1&&(s.quantity=u,s.description=t.substring(a).trim()),a--;var o=/^(-|–|—|to )/i.exec(s.description);if(o){var c=o[1].length,l=i(s.description.substring(c).trim().substring(0,1));if(!isNaN(l))for(var p=6,g=NaN;p>0&&isNaN(g);)g=i(s.description.substring(c,p)),isNaN(g)||(s.quantity2=g,s.description=s.description.substring(p).trim()),p--}var f=/^([a-zA-Z.]+)\b(.+)/.exec(s.description);if(f){for(var m=f[1],d=f[2],b="",q="",N=0;N<r.length&&!b;){var v=r[N].indexOf(m);v>=0&&(b=r[N][v],q=r[N][0]),N++}b&&(s.unitOfMeasure=null!=n&&n.normalizeUOM?q:b,s.description=d.trim())}return s}))}))}}})); | ||
//# sourceMappingURL=parse-ingredient.system.production.min.js.map |
@@ -9,3 +9,3 @@ (function (global, factory) { | ||
var UOM_LIST = ['cup', 'cups', 'c', 'c.', 'C', 'teaspoon', 'teaspoons', 'tsp', 'tsp.', 't', 'tablespoon', 'tablespoons', 'tbsp', 'tbsp.', 'T', 'ounce', 'ounces', 'oz', 'oz.', 'pint', 'pints', 'pt', 'pt.', 'pound', 'pounds', 'lb', 'lb.', 'lbs', 'lbs.', 'gram', 'grams', 'g', 'g.', 'kilogram', 'kilograms', 'kg', 'kg.', 'stick', 'sticks', 'inch', 'inches', 'in', 'in.', 'foot', 'feet', 'ft', 'ft.', 'quart', 'quarts', 'qt', 'qt.', 'liter', 'liters', 'l']; | ||
var UOM_LIST = [['cup', 'cups', 'c', 'c.', 'C'], ['teaspoon', 'teaspoons', 'tsp', 'tsp.', 't'], ['tablespoon', 'tablespoons', 'tbsp', 'tbsp.', 'T'], ['ounce', 'ounces', 'oz', 'oz.'], ['pint', 'pints', 'pt', 'pt.'], ['pound', 'pounds', 'lb', 'lb.', 'lbs', 'lbs.'], ['gram', 'grams', 'g', 'g.'], ['kilogram', 'kilograms', 'kg', 'kg.'], ['stick', 'sticks'], ['inch', 'inches', 'in', 'in.'], ['foot', 'feet', 'ft', 'ft.'], ['quart', 'quarts', 'qt', 'qt.'], ['liter', 'liters', 'l'], ['pinch', 'pinches'], ['piece', 'pieces', 'pcs', 'pcs.'], ['milligram', 'mg', 'mg.'], ['milliliter', 'ml', 'mL', 'ml.', 'mL.'], ['quart', 'quarts', 'qt', 'qt.', 'qts', 'qts.'], ['gallon', 'gallons', 'gal', 'gal.']]; | ||
/** | ||
@@ -39,3 +39,3 @@ * Removes falsy values from an array | ||
var parseIngredient = function parseIngredient(ingText) { | ||
var parseIngredient = function parseIngredient(ingText, options) { | ||
var arrRaw = compactArray(ingText.replace(/\n{2,}/g, '\n').split('\n').map(function (ing) { | ||
@@ -109,8 +109,32 @@ return ing.trim(); | ||
var firstSpace = oIng.description.indexOf(' '); | ||
var firstWord = oIng.description.substring(0, firstSpace); | ||
var firstWordRE = /^([a-zA-Z.]+)\b(.+)/; | ||
var firstWordREMatches = firstWordRE.exec(oIng.description); | ||
if (UOM_LIST.indexOf(firstWord) >= 0) { | ||
oIng.unitOfMeasure = firstWord; | ||
oIng.description = oIng.description.substring(firstSpace + 1); | ||
if (firstWordREMatches) { | ||
var firstWord = firstWordREMatches[1]; | ||
var remainingDesc = firstWordREMatches[2]; | ||
var uom = ''; | ||
var uomBase = ''; | ||
var i = 0; | ||
while (i < UOM_LIST.length && !uom) { | ||
var ndx = UOM_LIST[i].indexOf(firstWord); | ||
if (ndx >= 0) { | ||
uom = UOM_LIST[i][ndx]; | ||
uomBase = UOM_LIST[i][0]; | ||
} | ||
i++; | ||
} | ||
if (uom) { | ||
if (options != null && options.normalizeUOM) { | ||
oIng.unitOfMeasure = uomBase; | ||
} else { | ||
oIng.unitOfMeasure = uom; | ||
} | ||
oIng.description = remainingDesc.trim(); | ||
} | ||
} | ||
@@ -117,0 +141,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("numeric-quantity")):"function"==typeof define&&define.amd?define(["numeric-quantity"],i):(t=t||self).parseIngredient=i(t.numericQuantity)}(this,(function(t){"use strict";t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var i=["cup","cups","c","c.","C","teaspoon","teaspoons","tsp","tsp.","t","tablespoon","tablespoons","tbsp","tbsp.","T","ounce","ounces","oz","oz.","pint","pints","pt","pt.","pound","pounds","lb","lb.","lbs","lbs.","gram","grams","g","g.","kilogram","kilograms","kg","kg.","stick","sticks","inch","inches","in","in.","foot","feet","ft","ft.","quart","quarts","qt","qt.","liter","liters","l"];return function(n){return function(t){for(var i=-1,n=t.length,e=0,r=[];++i<n;){var s=t[i];s&&(r[e++]=s)}return r}(n.replace(/\n{2,}/g,"\n").split("\n").map((function(t){return t.trim()}))).map((function(n){var e={quantity:null,quantity2:null,unitOfMeasure:null,description:"",isGroupHeader:!1},r=t(n.substring(0,1));if(isNaN(r))e.description=n,(/:$/.test(e.description)||/^For /i.test(e.description))&&(e.isGroupHeader=!0);else for(var s=6,o=NaN;s>0&&isNaN(o);)(o=t(n.substring(0,s).trim()))>-1&&(e.quantity=o,e.description=n.substring(s).trim()),s--;var u=/^(-|–|—|to )/i.exec(e.description);if(u){var a=u[1].length,p=t(e.description.substring(a).trim().substring(0,1));if(!isNaN(p))for(var c=6,d=NaN;c>0&&isNaN(d);)d=t(e.description.substring(a,c)),isNaN(d)||(e.quantity2=d,e.description=e.description.substring(c).trim()),c--}var f=e.description.indexOf(" "),l=e.description.substring(0,f);return i.indexOf(l)>=0&&(e.unitOfMeasure=l,e.description=e.description.substring(f+1)),e}))}})); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("numeric-quantity")):"function"==typeof define&&define.amd?define(["numeric-quantity"],i):(t=t||self).parseIngredient=i(t.numericQuantity)}(this,(function(t){"use strict";t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var i=[["cup","cups","c","c.","C"],["teaspoon","teaspoons","tsp","tsp.","t"],["tablespoon","tablespoons","tbsp","tbsp.","T"],["ounce","ounces","oz","oz."],["pint","pints","pt","pt."],["pound","pounds","lb","lb.","lbs","lbs."],["gram","grams","g","g."],["kilogram","kilograms","kg","kg."],["stick","sticks"],["inch","inches","in","in."],["foot","feet","ft","ft."],["quart","quarts","qt","qt."],["liter","liters","l"],["pinch","pinches"],["piece","pieces","pcs","pcs."],["milligram","mg","mg."],["milliliter","ml","mL","ml.","mL."],["quart","quarts","qt","qt.","qts","qts."],["gallon","gallons","gal","gal."]];return function(e,n){return function(t){for(var i=-1,e=t.length,n=0,r=[];++i<e;){var s=t[i];s&&(r[n++]=s)}return r}(e.replace(/\n{2,}/g,"\n").split("\n").map((function(t){return t.trim()}))).map((function(e){var r={quantity:null,quantity2:null,unitOfMeasure:null,description:"",isGroupHeader:!1},s=t(e.substring(0,1));if(isNaN(s))r.description=e,(/:$/.test(r.description)||/^For /i.test(r.description))&&(r.isGroupHeader=!0);else for(var o=6,a=NaN;o>0&&isNaN(a);)(a=t(e.substring(0,o).trim()))>-1&&(r.quantity=a,r.description=e.substring(o).trim()),o--;var u=/^(-|–|—|to )/i.exec(r.description);if(u){var p=u[1].length,l=t(r.description.substring(p).trim().substring(0,1));if(!isNaN(l))for(var c=6,f=NaN;c>0&&isNaN(f);)f=t(r.description.substring(p,c)),isNaN(f)||(r.quantity2=f,r.description=r.description.substring(c).trim()),c--}var d=/^([a-zA-Z.]+)\b(.+)/.exec(r.description);if(d){for(var m=d[1],g=d[2],b="",q="",N=0;N<i.length&&!b;){var y=i[N].indexOf(m);y>=0&&(b=i[N][y],q=i[N][0]),N++}b&&(r.unitOfMeasure=null!=n&&n.normalizeUOM?q:b,r.description=g.trim())}return r}))}})); | ||
//# sourceMappingURL=parse-ingredient.umd.production.min.js.map |
{ | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "description": "Recipe ingredient parser with support for mixed numbers and vulgar fractions", |
@@ -133,1 +133,24 @@ # parse-ingredient | ||
``` | ||
## Options | ||
### normalizeUOM | ||
Pass `true` to convert units of measure to their long, singular form, e.g. "ml" becomes "milliliter" and "cups" becomes "cup". This can help normalize the units of measure for processing. | ||
Example: | ||
```js | ||
console.log(parseIngredient('1 c sugar', { normalizeUOM: true })); | ||
/** | ||
* [ | ||
* { | ||
* quantity: 1, | ||
* quantity2: null, | ||
* unitOfMeasure: 'cup', | ||
* description: 'sugar', | ||
* isGroupHeader: false, | ||
* } | ||
* ] | ||
*/ | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102422
517
156