parse-ingredient
Advanced tools
Comparing version 1.1.0-beta.0 to 1.1.0
@@ -61,58 +61,215 @@ "use strict"; | ||
var unitsOfMeasure = { | ||
bag: { short: "bag", plural: "bags", alternates: [] }, | ||
box: { short: "box", plural: "boxes", alternates: [] }, | ||
bunch: { short: "bunch", plural: "bunches", alternates: [] }, | ||
can: { short: "can", plural: "cans", alternates: [] }, | ||
carton: { short: "carton", plural: "cartons", alternates: [] }, | ||
centimeter: { short: "cm", plural: "centimeters", alternates: ["cm."] }, | ||
clove: { short: "clove", plural: "cloves", alternates: [] }, | ||
container: { short: "container", plural: "containers", alternates: [] }, | ||
cup: { short: "c", plural: "cups", alternates: ["c.", "C"] }, | ||
dash: { short: "dash", plural: "dashes", alternates: [] }, | ||
drop: { short: "drop", plural: "drops", alternates: [] }, | ||
ear: { short: "ear", plural: "ears", alternates: [] }, | ||
"fluid ounce": { short: "fl oz", plural: "fluid ounces", alternates: ["fluidounce", "floz", "fl-oz", "fluid-ounce", "fluid-ounces", "fluidounces", "fl ounce", "fl ounces", "fl-ounce", "fl-ounces", "fluid oz", "fluid-oz"] }, | ||
// prettier-ignore | ||
foot: { short: "ft", plural: "feet", alternates: ["ft."] }, | ||
gallon: { short: "gal", plural: "gallons", alternates: ["gal."] }, | ||
gram: { short: "g", plural: "grams", alternates: ["g."] }, | ||
head: { short: "head", plural: "heads", alternates: [] }, | ||
inch: { short: "in", plural: "inches", alternates: ["in."] }, | ||
kilogram: { short: "kg", plural: "kilograms", alternates: ["kg."] }, | ||
large: { short: "lg", plural: "large", alternates: ["lg", "lg."] }, | ||
liter: { short: "l", plural: "liters", alternates: [] }, | ||
medium: { short: "md", plural: "medium", alternates: ["med", "med.", "md."] }, | ||
meter: { short: "m", plural: "meters", alternates: ["m."] }, | ||
milligram: { short: "mg", plural: "milligrams", alternates: ["mg."] }, | ||
milliliter: { short: "ml", plural: "milliliters", alternates: ["mL", "ml.", "mL."] }, | ||
millimeter: { short: "mm", plural: "millimeters", alternates: ["mm."] }, | ||
ounce: { short: "oz", plural: "ounces", alternates: ["oz."] }, | ||
pack: { short: "pack", plural: "packs", alternates: [] }, | ||
package: { short: "pkg", plural: "packages", alternates: ["pkg.", "pkgs"] }, | ||
piece: { short: "piece", plural: "pieces", alternates: ["pcs", "pcs."] }, | ||
pinch: { short: "pinch", plural: "pinches", alternates: [] }, | ||
pint: { short: "pt", plural: "pints", alternates: ["pt."] }, | ||
pound: { short: "lb", plural: "pounds", alternates: ["lb.", "lbs", "lbs."] }, | ||
quart: { short: "qt", plural: "quarts", alternates: ["qt.", "qts", "qts."] }, | ||
small: { short: "sm", plural: "small", alternates: ["sm."] }, | ||
sprig: { short: "sprig", plural: "sprigs", alternates: [] }, | ||
stick: { short: "stick", plural: "sticks", alternates: [] }, | ||
tablespoon: { short: "tbsp", plural: "tablespoons", alternates: ["tbsp.", "T", "Tbsp."] }, | ||
teaspoon: { short: "tsp", plural: "teaspoons", alternates: ["tsp.", "t"] }, | ||
yard: { short: "yd", plural: "yards", alternates: ["yd.", "yds."] } | ||
}; | ||
// src/utils.ts | ||
var compactStringArray = (array) => { | ||
let index = -1; | ||
const length = array.length; | ||
let resIndex = 0; | ||
const result = []; | ||
while (++index < length) { | ||
const value = array[index].trim(); | ||
if (value) { | ||
result[resIndex++] = value; | ||
} | ||
bag: { | ||
short: "bag", | ||
plural: "bags", | ||
alternates: [] | ||
}, | ||
box: { | ||
short: "box", | ||
plural: "boxes", | ||
alternates: [] | ||
}, | ||
bunch: { | ||
short: "bunch", | ||
plural: "bunches", | ||
alternates: [] | ||
}, | ||
can: { | ||
short: "can", | ||
plural: "cans", | ||
alternates: [] | ||
}, | ||
carton: { | ||
short: "carton", | ||
plural: "cartons", | ||
alternates: [] | ||
}, | ||
centimeter: { | ||
short: "cm", | ||
plural: "centimeters", | ||
alternates: ["cm."] | ||
}, | ||
clove: { | ||
short: "clove", | ||
plural: "cloves", | ||
alternates: [] | ||
}, | ||
container: { | ||
short: "container", | ||
plural: "containers", | ||
alternates: [] | ||
}, | ||
cup: { | ||
short: "c", | ||
plural: "cups", | ||
alternates: ["c.", "C"] | ||
}, | ||
dash: { | ||
short: "dash", | ||
plural: "dashes", | ||
alternates: [] | ||
}, | ||
drop: { | ||
short: "drop", | ||
plural: "drops", | ||
alternates: [] | ||
}, | ||
ear: { | ||
short: "ear", | ||
plural: "ears", | ||
alternates: [] | ||
}, | ||
"fluid ounce": { | ||
short: "fl oz", | ||
plural: "fluid ounces", | ||
alternates: [ | ||
"fluidounce", | ||
"floz", | ||
"fl-oz", | ||
"fluid-ounce", | ||
"fluid-ounces", | ||
"fluidounces", | ||
"fl ounce", | ||
"fl ounces", | ||
"fl-ounce", | ||
"fl-ounces", | ||
"fluid oz", | ||
"fluid-oz" | ||
] | ||
}, | ||
foot: { | ||
short: "ft", | ||
plural: "feet", | ||
alternates: ["ft."] | ||
}, | ||
gallon: { | ||
short: "gal", | ||
plural: "gallons", | ||
alternates: ["gal."] | ||
}, | ||
gram: { | ||
short: "g", | ||
plural: "grams", | ||
alternates: ["g."] | ||
}, | ||
head: { | ||
short: "head", | ||
plural: "heads", | ||
alternates: [] | ||
}, | ||
inch: { | ||
short: "in", | ||
plural: "inches", | ||
alternates: ["in."] | ||
}, | ||
kilogram: { | ||
short: "kg", | ||
plural: "kilograms", | ||
alternates: ["kg."] | ||
}, | ||
large: { | ||
short: "lg", | ||
plural: "large", | ||
alternates: ["lg", "lg."] | ||
}, | ||
liter: { | ||
short: "l", | ||
plural: "liters", | ||
alternates: [] | ||
}, | ||
medium: { | ||
short: "md", | ||
plural: "medium", | ||
alternates: ["med", "med.", "md."] | ||
}, | ||
meter: { | ||
short: "m", | ||
plural: "meters", | ||
alternates: ["m."] | ||
}, | ||
milligram: { | ||
short: "mg", | ||
plural: "milligrams", | ||
alternates: ["mg."] | ||
}, | ||
milliliter: { | ||
short: "ml", | ||
plural: "milliliters", | ||
alternates: ["mL", "ml.", "mL."] | ||
}, | ||
millimeter: { | ||
short: "mm", | ||
plural: "millimeters", | ||
alternates: ["mm."] | ||
}, | ||
ounce: { | ||
short: "oz", | ||
plural: "ounces", | ||
alternates: ["oz."] | ||
}, | ||
pack: { | ||
short: "pack", | ||
plural: "packs", | ||
alternates: [] | ||
}, | ||
package: { | ||
short: "pkg", | ||
plural: "packages", | ||
alternates: ["pkg.", "pkgs"] | ||
}, | ||
piece: { | ||
short: "piece", | ||
plural: "pieces", | ||
alternates: ["pcs", "pcs."] | ||
}, | ||
pinch: { | ||
short: "pinch", | ||
plural: "pinches", | ||
alternates: [] | ||
}, | ||
pint: { | ||
short: "pt", | ||
plural: "pints", | ||
alternates: ["pt."] | ||
}, | ||
pound: { | ||
short: "lb", | ||
plural: "pounds", | ||
alternates: ["lb.", "lbs", "lbs."] | ||
}, | ||
quart: { | ||
short: "qt", | ||
plural: "quarts", | ||
alternates: ["qt.", "qts", "qts."] | ||
}, | ||
small: { | ||
short: "sm", | ||
plural: "small", | ||
alternates: ["sm."] | ||
}, | ||
sprig: { | ||
short: "sprig", | ||
plural: "sprigs", | ||
alternates: [] | ||
}, | ||
stick: { | ||
short: "stick", | ||
plural: "sticks", | ||
alternates: [] | ||
}, | ||
tablespoon: { | ||
short: "tbsp", | ||
plural: "tablespoons", | ||
alternates: ["tbsp.", "T", "Tbsp."] | ||
}, | ||
teaspoon: { | ||
short: "tsp", | ||
plural: "teaspoons", | ||
alternates: ["tsp.", "t"] | ||
}, | ||
yard: { | ||
short: "yd", | ||
plural: "yards", | ||
alternates: ["yd.", "yds."] | ||
} | ||
return result; | ||
}; | ||
@@ -128,3 +285,4 @@ | ||
const uomArrayLength = uomArray.length; | ||
return compactStringArray(ingredientText.split(newLineRegExp)).map((line) => { | ||
const ingredientArray = ingredientText.split(newLineRegExp).map((line) => line.trim()).filter(Boolean); | ||
return ingredientArray.map((line) => { | ||
const oIng = { | ||
@@ -138,4 +296,3 @@ quantity: null, | ||
}; | ||
const nqResultFirstChar = (0, import_numeric_quantity2.numericQuantity)(line.substring(0, 1)); | ||
if (isNaN(nqResultFirstChar)) { | ||
if (isNaN((0, import_numeric_quantity2.numericQuantity)(line[0]))) { | ||
const trailingQtyResult = trailingQuantityRegEx.exec(line); | ||
@@ -191,4 +348,4 @@ if (trailingQtyResult) { | ||
const q2reMatchLen = q2reMatch[1].length; | ||
const nqResultFirstChar2 = (0, import_numeric_quantity2.numericQuantity)(oIng.description.substring(q2reMatchLen).trim()[0]); | ||
if (!isNaN(nqResultFirstChar2)) { | ||
const nqResultFirstChar = (0, import_numeric_quantity2.numericQuantity)(oIng.description.substring(q2reMatchLen).trim()[0]); | ||
if (!isNaN(nqResultFirstChar)) { | ||
let lenNum = 7; | ||
@@ -195,0 +352,0 @@ let nqResult = NaN; |
@@ -1,2 +0,2 @@ | ||
"use strict";var M=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var C=(s,e)=>{for(var o in e)M(s,o,{get:e[o],enumerable:!0})},F=(s,e,o,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of j(e))!P.call(s,a)&&a!==o&&M(s,a,{get:()=>e[a],enumerable:!(c=A(e,a))||c.enumerable});return s};var T=s=>F(M({},"__esModule",{value:!0}),s);var J={};C(J,{defaultOptions:()=>x,firstWordRegEx:()=>w,fors:()=>$,forsRegEx:()=>q,ofRegEx:()=>R,ofs:()=>L,parseIngredient:()=>B,rangeSeparatorRegEx:()=>E,rangeSeparatorWords:()=>D,trailingQuantityRegEx:()=>O,unitsOfMeasure:()=>I});module.exports=T(J);var p=require("numeric-quantity");var U=require("numeric-quantity"),x={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1},$=["For"],q=new RegExp(`^(?:${$.join("|")})\\s`,"i"),D=["or","to"],v=`(-|\u2013|\u2014|(?:${D.join("|")})\\s)`,E=new RegExp(`^${v}`,"i"),w=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,z=U.numericRegex.source.replace(/^\^/,"").replace(/\$$/,""),O=new RegExp(`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${z})\\s*(${v}))?\\s*(${z})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`,"i"),L=["of"],R=new RegExp(`^(?:${L.join("|")})\\s+`,"i"),I={bag:{short:"bag",plural:"bags",alternates:[]},box:{short:"box",plural:"boxes",alternates:[]},bunch:{short:"bunch",plural:"bunches",alternates:[]},can:{short:"can",plural:"cans",alternates:[]},carton:{short:"carton",plural:"cartons",alternates:[]},centimeter:{short:"cm",plural:"centimeters",alternates:["cm."]},clove:{short:"clove",plural:"cloves",alternates:[]},container:{short:"container",plural:"containers",alternates:[]},cup:{short:"c",plural:"cups",alternates:["c.","C"]},dash:{short:"dash",plural:"dashes",alternates:[]},drop:{short:"drop",plural:"drops",alternates:[]},ear:{short:"ear",plural:"ears",alternates:[]},"fluid ounce":{short:"fl oz",plural:"fluid ounces",alternates:["fluidounce","floz","fl-oz","fluid-ounce","fluid-ounces","fluidounces","fl ounce","fl ounces","fl-ounce","fl-ounces","fluid oz","fluid-oz"]},foot:{short:"ft",plural:"feet",alternates:["ft."]},gallon:{short:"gal",plural:"gallons",alternates:["gal."]},gram:{short:"g",plural:"grams",alternates:["g."]},head:{short:"head",plural:"heads",alternates:[]},inch:{short:"in",plural:"inches",alternates:["in."]},kilogram:{short:"kg",plural:"kilograms",alternates:["kg."]},large:{short:"lg",plural:"large",alternates:["lg","lg."]},liter:{short:"l",plural:"liters",alternates:[]},medium:{short:"md",plural:"medium",alternates:["med","med.","md."]},meter:{short:"m",plural:"meters",alternates:["m."]},milligram:{short:"mg",plural:"milligrams",alternates:["mg."]},milliliter:{short:"ml",plural:"milliliters",alternates:["mL","ml.","mL."]},millimeter:{short:"mm",plural:"millimeters",alternates:["mm."]},ounce:{short:"oz",plural:"ounces",alternates:["oz."]},pack:{short:"pack",plural:"packs",alternates:[]},package:{short:"pkg",plural:"packages",alternates:["pkg.","pkgs"]},piece:{short:"piece",plural:"pieces",alternates:["pcs","pcs."]},pinch:{short:"pinch",plural:"pinches",alternates:[]},pint:{short:"pt",plural:"pints",alternates:["pt."]},pound:{short:"lb",plural:"pounds",alternates:["lb.","lbs","lbs."]},quart:{short:"qt",plural:"quarts",alternates:["qt.","qts","qts."]},small:{short:"sm",plural:"small",alternates:["sm."]},sprig:{short:"sprig",plural:"sprigs",alternates:[]},stick:{short:"stick",plural:"sticks",alternates:[]},tablespoon:{short:"tbsp",plural:"tablespoons",alternates:["tbsp.","T","Tbsp."]},teaspoon:{short:"tsp",plural:"teaspoons",alternates:["tsp.","t"]},yard:{short:"yd",plural:"yards",alternates:["yd.","yds."]}};var S=s=>{let e=-1,o=s.length,c=0,a=[];for(;++e<o;){let g=s[e].trim();g&&(a[c++]=g)}return a};var G=/\r?\n/,H=([s,e])=>({id:s,...e}),B=(s,e=x)=>{let o={...x,...e},c={...I,...o.additionalUOMs},a=Object.entries(c).map(H),g=a.length;return S(s.split(G)).map(m=>{let t={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1},Q=(0,p.numericQuantity)(m.substring(0,1));if(isNaN(Q)){let r=O.exec(m);if(r){t.description=m.replace(O,"").trim();let n=r[3],i=r[12];n?(t.quantity=(0,p.numericQuantity)(n),t.quantity2=(0,p.numericQuantity)(i)):t.quantity=(0,p.numericQuantity)(i);let l=r.at(-1);if(l){let u="",d="",f=-1;for(;++f<g&&!u;){let{alternates:y,id:h,short:k,plural:W}=a[f];[...y,h,k,W].includes(l)&&(u=l,d=h)}u&&(t.unitOfMeasureID=d,t.unitOfMeasure=o.normalizeUOM?d:u)}}else t.description=m,(t.description.endsWith(":")||q.test(t.description))&&(t.isGroupHeader=!0)}else{let r=6,n=NaN;for(;r>0&&isNaN(n);)n=(0,p.numericQuantity)(m.substring(0,r).trim()),n>-1&&(t.quantity=n,t.description=m.substring(r).trim()),r--}let N=E.exec(t.description);if(N){let r=N[1].length,n=(0,p.numericQuantity)(t.description.substring(r).trim()[0]);if(!isNaN(n)){let i=7,l=NaN;for(;--i>0&&isNaN(l);)l=(0,p.numericQuantity)(t.description.substring(r,i)),isNaN(l)||(t.quantity2=l,t.description=t.description.substring(i).trim())}}let b=w.exec(t.description);if(b){let r=b[1].replace(/\s+/g," "),n=(b[2]??"").trim();if(n){let i="",l="",u=-1;for(;++u<g&&!i;){let{alternates:d,id:f,short:y,plural:h}=a[u];[...d,f,y,h].includes(r)&&(i=r,l=f)}i&&(t.unitOfMeasureID=l,t.unitOfMeasure=o.normalizeUOM?l:i,t.description=n)}}return!o.allowLeadingOf&&t.description.match(R)&&(t.description=t.description.replace(R,"")),t})};0&&(module.exports={defaultOptions,firstWordRegEx,fors,forsRegEx,ofRegEx,ofs,parseIngredient,rangeSeparatorRegEx,rangeSeparatorWords,trailingQuantityRegEx,unitsOfMeasure}); | ||
"use strict";var b=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var j=(a,e)=>{for(var l in e)b(a,l,{get:e[l],enumerable:!0})},P=(a,e,l,m)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of A(e))!S.call(a,o)&&o!==l&&b(a,o,{get:()=>e[o],enumerable:!(m=W(e,o))||m.enumerable});return a};var T=a=>P(b({},"__esModule",{value:!0}),a);var H={};j(H,{defaultOptions:()=>h,firstWordRegEx:()=>E,fors:()=>$,forsRegEx:()=>M,ofRegEx:()=>O,ofs:()=>L,parseIngredient:()=>G,rangeSeparatorRegEx:()=>q,rangeSeparatorWords:()=>D,trailingQuantityRegEx:()=>x,unitsOfMeasure:()=>N});module.exports=T(H);var u=require("numeric-quantity");var U=require("numeric-quantity"),h={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1},$=["For"],M=new RegExp(`^(?:${$.join("|")})\\s`,"i"),D=["or","to"],v=`(-|\u2013|\u2014|(?:${D.join("|")})\\s)`,q=new RegExp(`^${v}`,"i"),E=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,z=U.numericRegex.source.replace(/^\^/,"").replace(/\$$/,""),x=new RegExp(`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${z})\\s*(${v}))?\\s*(${z})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`,"i"),L=["of"],O=new RegExp(`^(?:${L.join("|")})\\s+`,"i"),N={bag:{short:"bag",plural:"bags",alternates:[]},box:{short:"box",plural:"boxes",alternates:[]},bunch:{short:"bunch",plural:"bunches",alternates:[]},can:{short:"can",plural:"cans",alternates:[]},carton:{short:"carton",plural:"cartons",alternates:[]},centimeter:{short:"cm",plural:"centimeters",alternates:["cm."]},clove:{short:"clove",plural:"cloves",alternates:[]},container:{short:"container",plural:"containers",alternates:[]},cup:{short:"c",plural:"cups",alternates:["c.","C"]},dash:{short:"dash",plural:"dashes",alternates:[]},drop:{short:"drop",plural:"drops",alternates:[]},ear:{short:"ear",plural:"ears",alternates:[]},"fluid ounce":{short:"fl oz",plural:"fluid ounces",alternates:["fluidounce","floz","fl-oz","fluid-ounce","fluid-ounces","fluidounces","fl ounce","fl ounces","fl-ounce","fl-ounces","fluid oz","fluid-oz"]},foot:{short:"ft",plural:"feet",alternates:["ft."]},gallon:{short:"gal",plural:"gallons",alternates:["gal."]},gram:{short:"g",plural:"grams",alternates:["g."]},head:{short:"head",plural:"heads",alternates:[]},inch:{short:"in",plural:"inches",alternates:["in."]},kilogram:{short:"kg",plural:"kilograms",alternates:["kg."]},large:{short:"lg",plural:"large",alternates:["lg","lg."]},liter:{short:"l",plural:"liters",alternates:[]},medium:{short:"md",plural:"medium",alternates:["med","med.","md."]},meter:{short:"m",plural:"meters",alternates:["m."]},milligram:{short:"mg",plural:"milligrams",alternates:["mg."]},milliliter:{short:"ml",plural:"milliliters",alternates:["mL","ml.","mL."]},millimeter:{short:"mm",plural:"millimeters",alternates:["mm."]},ounce:{short:"oz",plural:"ounces",alternates:["oz."]},pack:{short:"pack",plural:"packs",alternates:[]},package:{short:"pkg",plural:"packages",alternates:["pkg.","pkgs"]},piece:{short:"piece",plural:"pieces",alternates:["pcs","pcs."]},pinch:{short:"pinch",plural:"pinches",alternates:[]},pint:{short:"pt",plural:"pints",alternates:["pt."]},pound:{short:"lb",plural:"pounds",alternates:["lb.","lbs","lbs."]},quart:{short:"qt",plural:"quarts",alternates:["qt.","qts","qts."]},small:{short:"sm",plural:"small",alternates:["sm."]},sprig:{short:"sprig",plural:"sprigs",alternates:[]},stick:{short:"stick",plural:"sticks",alternates:[]},tablespoon:{short:"tbsp",plural:"tablespoons",alternates:["tbsp.","T","Tbsp."]},teaspoon:{short:"tsp",plural:"teaspoons",alternates:["tsp.","t"]},yard:{short:"yd",plural:"yards",alternates:["yd.","yds."]}};var C=/\r?\n/,F=([a,e])=>({id:a,...e}),G=(a,e=h)=>{let l={...h,...e},m={...N,...l.additionalUOMs},o=Object.entries(m).map(F),k=o.length;return a.split(C).map(p=>p.trim()).filter(Boolean).map(p=>{let s={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1};if(isNaN((0,u.numericQuantity)(p[0]))){let t=x.exec(p);if(t){s.description=p.replace(x,"").trim();let r=t[3],n=t[12];r?(s.quantity=(0,u.numericQuantity)(r),s.quantity2=(0,u.numericQuantity)(n)):s.quantity=(0,u.numericQuantity)(n);let i=t.at(-1);if(i){let c="",g="",f=-1;for(;++f<k&&!c;){let{alternates:R,id:d,short:I,plural:Q}=o[f];[...R,d,I,Q].includes(i)&&(c=i,g=d)}c&&(s.unitOfMeasureID=g,s.unitOfMeasure=l.normalizeUOM?g:c)}}else s.description=p,(s.description.endsWith(":")||M.test(s.description))&&(s.isGroupHeader=!0)}else{let t=6,r=NaN;for(;t>0&&isNaN(r);)r=(0,u.numericQuantity)(p.substring(0,t).trim()),r>-1&&(s.quantity=r,s.description=p.substring(t).trim()),t--}let w=q.exec(s.description);if(w){let t=w[1].length,r=(0,u.numericQuantity)(s.description.substring(t).trim()[0]);if(!isNaN(r)){let n=7,i=NaN;for(;--n>0&&isNaN(i);)i=(0,u.numericQuantity)(s.description.substring(t,n)),isNaN(i)||(s.quantity2=i,s.description=s.description.substring(n).trim())}}let y=E.exec(s.description);if(y){let t=y[1].replace(/\s+/g," "),r=(y[2]??"").trim();if(r){let n="",i="",c=-1;for(;++c<k&&!n;){let{alternates:g,id:f,short:R,plural:d}=o[c];[...g,f,R,d].includes(t)&&(n=t,i=f)}n&&(s.unitOfMeasureID=i,s.unitOfMeasure=l.normalizeUOM?i:n,s.description=r)}}return!l.allowLeadingOf&&s.description.match(O)&&(s.description=s.description.replace(O,"")),s})};0&&(module.exports={defaultOptions,firstWordRegEx,fors,forsRegEx,ofRegEx,ofs,parseIngredient,rangeSeparatorRegEx,rangeSeparatorWords,trailingQuantityRegEx,unitsOfMeasure}); | ||
//# sourceMappingURL=parse-ingredient.cjs.production.js.map |
@@ -42,58 +42,215 @@ var __defProp = Object.defineProperty; | ||
var unitsOfMeasure = { | ||
bag: { short: "bag", plural: "bags", alternates: [] }, | ||
box: { short: "box", plural: "boxes", alternates: [] }, | ||
bunch: { short: "bunch", plural: "bunches", alternates: [] }, | ||
can: { short: "can", plural: "cans", alternates: [] }, | ||
carton: { short: "carton", plural: "cartons", alternates: [] }, | ||
centimeter: { short: "cm", plural: "centimeters", alternates: ["cm."] }, | ||
clove: { short: "clove", plural: "cloves", alternates: [] }, | ||
container: { short: "container", plural: "containers", alternates: [] }, | ||
cup: { short: "c", plural: "cups", alternates: ["c.", "C"] }, | ||
dash: { short: "dash", plural: "dashes", alternates: [] }, | ||
drop: { short: "drop", plural: "drops", alternates: [] }, | ||
ear: { short: "ear", plural: "ears", alternates: [] }, | ||
"fluid ounce": { short: "fl oz", plural: "fluid ounces", alternates: ["fluidounce", "floz", "fl-oz", "fluid-ounce", "fluid-ounces", "fluidounces", "fl ounce", "fl ounces", "fl-ounce", "fl-ounces", "fluid oz", "fluid-oz"] }, | ||
// prettier-ignore | ||
foot: { short: "ft", plural: "feet", alternates: ["ft."] }, | ||
gallon: { short: "gal", plural: "gallons", alternates: ["gal."] }, | ||
gram: { short: "g", plural: "grams", alternates: ["g."] }, | ||
head: { short: "head", plural: "heads", alternates: [] }, | ||
inch: { short: "in", plural: "inches", alternates: ["in."] }, | ||
kilogram: { short: "kg", plural: "kilograms", alternates: ["kg."] }, | ||
large: { short: "lg", plural: "large", alternates: ["lg", "lg."] }, | ||
liter: { short: "l", plural: "liters", alternates: [] }, | ||
medium: { short: "md", plural: "medium", alternates: ["med", "med.", "md."] }, | ||
meter: { short: "m", plural: "meters", alternates: ["m."] }, | ||
milligram: { short: "mg", plural: "milligrams", alternates: ["mg."] }, | ||
milliliter: { short: "ml", plural: "milliliters", alternates: ["mL", "ml.", "mL."] }, | ||
millimeter: { short: "mm", plural: "millimeters", alternates: ["mm."] }, | ||
ounce: { short: "oz", plural: "ounces", alternates: ["oz."] }, | ||
pack: { short: "pack", plural: "packs", alternates: [] }, | ||
package: { short: "pkg", plural: "packages", alternates: ["pkg.", "pkgs"] }, | ||
piece: { short: "piece", plural: "pieces", alternates: ["pcs", "pcs."] }, | ||
pinch: { short: "pinch", plural: "pinches", alternates: [] }, | ||
pint: { short: "pt", plural: "pints", alternates: ["pt."] }, | ||
pound: { short: "lb", plural: "pounds", alternates: ["lb.", "lbs", "lbs."] }, | ||
quart: { short: "qt", plural: "quarts", alternates: ["qt.", "qts", "qts."] }, | ||
small: { short: "sm", plural: "small", alternates: ["sm."] }, | ||
sprig: { short: "sprig", plural: "sprigs", alternates: [] }, | ||
stick: { short: "stick", plural: "sticks", alternates: [] }, | ||
tablespoon: { short: "tbsp", plural: "tablespoons", alternates: ["tbsp.", "T", "Tbsp."] }, | ||
teaspoon: { short: "tsp", plural: "teaspoons", alternates: ["tsp.", "t"] }, | ||
yard: { short: "yd", plural: "yards", alternates: ["yd.", "yds."] } | ||
}; | ||
// src/utils.ts | ||
var compactStringArray = (array) => { | ||
let index = -1; | ||
const length = array.length; | ||
let resIndex = 0; | ||
const result = []; | ||
while (++index < length) { | ||
const value = array[index].trim(); | ||
if (value) { | ||
result[resIndex++] = value; | ||
} | ||
bag: { | ||
short: "bag", | ||
plural: "bags", | ||
alternates: [] | ||
}, | ||
box: { | ||
short: "box", | ||
plural: "boxes", | ||
alternates: [] | ||
}, | ||
bunch: { | ||
short: "bunch", | ||
plural: "bunches", | ||
alternates: [] | ||
}, | ||
can: { | ||
short: "can", | ||
plural: "cans", | ||
alternates: [] | ||
}, | ||
carton: { | ||
short: "carton", | ||
plural: "cartons", | ||
alternates: [] | ||
}, | ||
centimeter: { | ||
short: "cm", | ||
plural: "centimeters", | ||
alternates: ["cm."] | ||
}, | ||
clove: { | ||
short: "clove", | ||
plural: "cloves", | ||
alternates: [] | ||
}, | ||
container: { | ||
short: "container", | ||
plural: "containers", | ||
alternates: [] | ||
}, | ||
cup: { | ||
short: "c", | ||
plural: "cups", | ||
alternates: ["c.", "C"] | ||
}, | ||
dash: { | ||
short: "dash", | ||
plural: "dashes", | ||
alternates: [] | ||
}, | ||
drop: { | ||
short: "drop", | ||
plural: "drops", | ||
alternates: [] | ||
}, | ||
ear: { | ||
short: "ear", | ||
plural: "ears", | ||
alternates: [] | ||
}, | ||
"fluid ounce": { | ||
short: "fl oz", | ||
plural: "fluid ounces", | ||
alternates: [ | ||
"fluidounce", | ||
"floz", | ||
"fl-oz", | ||
"fluid-ounce", | ||
"fluid-ounces", | ||
"fluidounces", | ||
"fl ounce", | ||
"fl ounces", | ||
"fl-ounce", | ||
"fl-ounces", | ||
"fluid oz", | ||
"fluid-oz" | ||
] | ||
}, | ||
foot: { | ||
short: "ft", | ||
plural: "feet", | ||
alternates: ["ft."] | ||
}, | ||
gallon: { | ||
short: "gal", | ||
plural: "gallons", | ||
alternates: ["gal."] | ||
}, | ||
gram: { | ||
short: "g", | ||
plural: "grams", | ||
alternates: ["g."] | ||
}, | ||
head: { | ||
short: "head", | ||
plural: "heads", | ||
alternates: [] | ||
}, | ||
inch: { | ||
short: "in", | ||
plural: "inches", | ||
alternates: ["in."] | ||
}, | ||
kilogram: { | ||
short: "kg", | ||
plural: "kilograms", | ||
alternates: ["kg."] | ||
}, | ||
large: { | ||
short: "lg", | ||
plural: "large", | ||
alternates: ["lg", "lg."] | ||
}, | ||
liter: { | ||
short: "l", | ||
plural: "liters", | ||
alternates: [] | ||
}, | ||
medium: { | ||
short: "md", | ||
plural: "medium", | ||
alternates: ["med", "med.", "md."] | ||
}, | ||
meter: { | ||
short: "m", | ||
plural: "meters", | ||
alternates: ["m."] | ||
}, | ||
milligram: { | ||
short: "mg", | ||
plural: "milligrams", | ||
alternates: ["mg."] | ||
}, | ||
milliliter: { | ||
short: "ml", | ||
plural: "milliliters", | ||
alternates: ["mL", "ml.", "mL."] | ||
}, | ||
millimeter: { | ||
short: "mm", | ||
plural: "millimeters", | ||
alternates: ["mm."] | ||
}, | ||
ounce: { | ||
short: "oz", | ||
plural: "ounces", | ||
alternates: ["oz."] | ||
}, | ||
pack: { | ||
short: "pack", | ||
plural: "packs", | ||
alternates: [] | ||
}, | ||
package: { | ||
short: "pkg", | ||
plural: "packages", | ||
alternates: ["pkg.", "pkgs"] | ||
}, | ||
piece: { | ||
short: "piece", | ||
plural: "pieces", | ||
alternates: ["pcs", "pcs."] | ||
}, | ||
pinch: { | ||
short: "pinch", | ||
plural: "pinches", | ||
alternates: [] | ||
}, | ||
pint: { | ||
short: "pt", | ||
plural: "pints", | ||
alternates: ["pt."] | ||
}, | ||
pound: { | ||
short: "lb", | ||
plural: "pounds", | ||
alternates: ["lb.", "lbs", "lbs."] | ||
}, | ||
quart: { | ||
short: "qt", | ||
plural: "quarts", | ||
alternates: ["qt.", "qts", "qts."] | ||
}, | ||
small: { | ||
short: "sm", | ||
plural: "small", | ||
alternates: ["sm."] | ||
}, | ||
sprig: { | ||
short: "sprig", | ||
plural: "sprigs", | ||
alternates: [] | ||
}, | ||
stick: { | ||
short: "stick", | ||
plural: "sticks", | ||
alternates: [] | ||
}, | ||
tablespoon: { | ||
short: "tbsp", | ||
plural: "tablespoons", | ||
alternates: ["tbsp.", "T", "Tbsp."] | ||
}, | ||
teaspoon: { | ||
short: "tsp", | ||
plural: "teaspoons", | ||
alternates: ["tsp.", "t"] | ||
}, | ||
yard: { | ||
short: "yd", | ||
plural: "yards", | ||
alternates: ["yd.", "yds."] | ||
} | ||
return result; | ||
}; | ||
@@ -109,3 +266,4 @@ | ||
const uomArrayLength = uomArray.length; | ||
return compactStringArray(ingredientText.split(newLineRegExp)).map((line) => { | ||
const ingredientArray = ingredientText.split(newLineRegExp).map((line) => line.trim()).filter(Boolean); | ||
return ingredientArray.map((line) => { | ||
var _a; | ||
@@ -120,4 +278,3 @@ const oIng = { | ||
}; | ||
const nqResultFirstChar = numericQuantity(line.substring(0, 1)); | ||
if (isNaN(nqResultFirstChar)) { | ||
if (isNaN(numericQuantity(line[0]))) { | ||
const trailingQtyResult = trailingQuantityRegEx.exec(line); | ||
@@ -173,4 +330,4 @@ if (trailingQtyResult) { | ||
const q2reMatchLen = q2reMatch[1].length; | ||
const nqResultFirstChar2 = numericQuantity(oIng.description.substring(q2reMatchLen).trim()[0]); | ||
if (!isNaN(nqResultFirstChar2)) { | ||
const nqResultFirstChar = numericQuantity(oIng.description.substring(q2reMatchLen).trim()[0]); | ||
if (!isNaN(nqResultFirstChar)) { | ||
let lenNum = 7; | ||
@@ -177,0 +334,0 @@ let nqResult = NaN; |
@@ -1,2 +0,2 @@ | ||
"use strict";var ParseIngredient=(()=>{var y=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var G=(s,t)=>{for(var e in t)y(s,e,{get:t[e],enumerable:!0})},H=(s,t,e,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Q(t))!B.call(s,o)&&o!==e&&y(s,o,{get:()=>t[o],enumerable:!(p=T(t,o))||p.enumerable});return s};var J=s=>H(y({},"__esModule",{value:!0}),s);var ue={};G(ue,{defaultOptions:()=>O,firstWordRegEx:()=>X,fors:()=>A,forsRegEx:()=>E,ofRegEx:()=>b,ofs:()=>S,parseIngredient:()=>ie,rangeSeparatorRegEx:()=>C,rangeSeparatorWords:()=>F,trailingQuantityRegEx:()=>R,unitsOfMeasure:()=>w});var K=Object.defineProperty,V=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,$=(s,t,e)=>t in s?K(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,q=(s,t)=>{for(var e in t||(t={}))Y.call(t,e)&&$(s,e,t[e]);if(V)for(var e of V(t))Z.call(t,e)&&$(s,e,t[e]);return s},k={"\xBC":"1/4","\xBD":"1/2","\xBE":"3/4","\u2150":"1/7","\u2151":"1/9","\u2152":"1/10","\u2153":"1/3","\u2154":"2/3","\u2155":"1/5","\u2156":"2/5","\u2157":"3/5","\u2158":"4/5","\u2159":"1/6","\u215A":"5/6","\u215B":"1/8","\u215C":"3/8","\u215D":"5/8","\u215E":"7/8","\u215F":"1/"},_=/^(?=-?\s*\.\d|-?\s*\d)(-)?\s*((?:\d(?:[\d,_]*\d)?)*)(([eE][+-]?\d(?:[\d,_]*\d)?)?|\.\d(?:[\d,_]*\d)?([eE][+-]?\d(?:[\d,_]*\d)?)?|(\s+\d(?:[\d,_]*\d)?\s*)?\s*\/\s*\d(?:[\d,_]*\d)?)?$/,ee=/^(?=-?\s*\.\d|-?\s*\d)(-)?\s*((?:\d(?:[\d,_]*\d)?)*)(([eE][+-]?\d(?:[\d,_]*\d)?)?|\.\d(?:[\d,_]*\d)?([eE][+-]?\d(?:[\d,_]*\d)?)?|(\s+\d(?:[\d,_]*\d)?\s*)?\s*\/\s*\d(?:[\d,_]*\d)?)?(?:\s*[^\.\d\/].*)?/,te=new RegExp(`(${Object.keys(k).join("|")})`),N={MMM:3e3,MM:2e3,M:1e3,CM:900,DCCC:800,DCC:700,DC:600,D:500,CD:400,CCC:300,CC:200,C:100,XC:90,LXXX:80,LXX:70,LX:60,L:50,XL:40,XXX:30,XX:20,XII:12,XI:11,X:10,IX:9,VIII:8,VII:7,VI:6,V:5,IV:4,III:3,II:2,I:1},U={"\u2160":"I","\u2161":"II","\u2162":"III","\u2163":"IV","\u2164":"V","\u2165":"VI","\u2166":"VII","\u2167":"VIII","\u2168":"IX","\u2169":"X","\u216A":"XI","\u216B":"XII","\u216C":"L","\u216D":"C","\u216E":"D","\u216F":"M","\u2170":"I","\u2171":"II","\u2172":"III","\u2173":"IV","\u2174":"V","\u2175":"VI","\u2176":"VII","\u2177":"VIII","\u2178":"IX","\u2179":"X","\u217A":"XI","\u217B":"XII","\u217C":"L","\u217D":"C","\u217E":"D","\u217F":"M"},re=new RegExp(`(${Object.keys(U).join("|")})`,"gi"),se=/^(?=[MDCLXVI])(M{0,3})(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/i,L={round:3,allowTrailingInvalid:!1,romanNumerals:!1},ae=s=>{var t,e,p,o;let d=`${s}`.replace(re,(a,n)=>U[n]).toUpperCase(),c=se.exec(d);if(!c)return NaN;let[,r,h,g,i]=c;return((t=N[r])!=null?t:0)+((e=N[h])!=null?e:0)+((p=N[g])!=null?p:0)+((o=N[i])!=null?o:0)},ne=/^\s*\//,f=(s,t=L)=>{if(typeof s=="number"||typeof s=="bigint")return s;let e=NaN,p=`${s}`.replace(te,(n,l)=>` ${k[l]}`).replace("\u2044","/").trim();if(p.length===0)return NaN;let o=q(q({},L),t),d=(o.allowTrailingInvalid?ee:_).exec(p);if(!d)return o.romanNumerals?ae(p):NaN;let[,c,r,h]=d,g=r.replace(/[,_]/g,""),i=h?.replace(/[,_]/g,"");if(!g&&i&&i.startsWith(".")?e=0:e=parseInt(g),!i)return c?e*-1:e;let a=o.round===!1?NaN:parseFloat(`1e${Math.floor(Math.max(0,o.round))}`);if(i.startsWith(".")||i.startsWith("e")||i.startsWith("E")){let n=parseFloat(`${e}${i}`);e=isNaN(a)?n:Math.round(n*a)/a}else if(ne.test(i)){let n=parseInt(g),l=parseInt(i.replace("/",""));e=isNaN(a)?n/l:Math.round(n*a/l)/a}else{let n=i.split("/"),[l,u]=n.map(m=>parseInt(m));e+=isNaN(a)?l/u:Math.round(l*a/u)/a}return c?e*-1:e};var O={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1},A=["For"],E=new RegExp(`^(?:${A.join("|")})\\s`,"i"),F=["or","to"],P=`(-|\u2013|\u2014|(?:${F.join("|")})\\s)`,C=new RegExp(`^${P}`,"i"),X=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,z=_.source.replace(/^\^/,"").replace(/\$$/,""),R=new RegExp(`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${z})\\s*(${P}))?\\s*(${z})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`,"i"),S=["of"],b=new RegExp(`^(?:${S.join("|")})\\s+`,"i"),w={bag:{short:"bag",plural:"bags",alternates:[]},box:{short:"box",plural:"boxes",alternates:[]},bunch:{short:"bunch",plural:"bunches",alternates:[]},can:{short:"can",plural:"cans",alternates:[]},carton:{short:"carton",plural:"cartons",alternates:[]},centimeter:{short:"cm",plural:"centimeters",alternates:["cm."]},clove:{short:"clove",plural:"cloves",alternates:[]},container:{short:"container",plural:"containers",alternates:[]},cup:{short:"c",plural:"cups",alternates:["c.","C"]},dash:{short:"dash",plural:"dashes",alternates:[]},drop:{short:"drop",plural:"drops",alternates:[]},ear:{short:"ear",plural:"ears",alternates:[]},"fluid ounce":{short:"fl oz",plural:"fluid ounces",alternates:["fluidounce","floz","fl-oz","fluid-ounce","fluid-ounces","fluidounces","fl ounce","fl ounces","fl-ounce","fl-ounces","fluid oz","fluid-oz"]},foot:{short:"ft",plural:"feet",alternates:["ft."]},gallon:{short:"gal",plural:"gallons",alternates:["gal."]},gram:{short:"g",plural:"grams",alternates:["g."]},head:{short:"head",plural:"heads",alternates:[]},inch:{short:"in",plural:"inches",alternates:["in."]},kilogram:{short:"kg",plural:"kilograms",alternates:["kg."]},large:{short:"lg",plural:"large",alternates:["lg","lg."]},liter:{short:"l",plural:"liters",alternates:[]},medium:{short:"md",plural:"medium",alternates:["med","med.","md."]},meter:{short:"m",plural:"meters",alternates:["m."]},milligram:{short:"mg",plural:"milligrams",alternates:["mg."]},milliliter:{short:"ml",plural:"milliliters",alternates:["mL","ml.","mL."]},millimeter:{short:"mm",plural:"millimeters",alternates:["mm."]},ounce:{short:"oz",plural:"ounces",alternates:["oz."]},pack:{short:"pack",plural:"packs",alternates:[]},package:{short:"pkg",plural:"packages",alternates:["pkg.","pkgs"]},piece:{short:"piece",plural:"pieces",alternates:["pcs","pcs."]},pinch:{short:"pinch",plural:"pinches",alternates:[]},pint:{short:"pt",plural:"pints",alternates:["pt."]},pound:{short:"lb",plural:"pounds",alternates:["lb.","lbs","lbs."]},quart:{short:"qt",plural:"quarts",alternates:["qt.","qts","qts."]},small:{short:"sm",plural:"small",alternates:["sm."]},sprig:{short:"sprig",plural:"sprigs",alternates:[]},stick:{short:"stick",plural:"sticks",alternates:[]},tablespoon:{short:"tbsp",plural:"tablespoons",alternates:["tbsp.","T","Tbsp."]},teaspoon:{short:"tsp",plural:"teaspoons",alternates:["tsp.","t"]},yard:{short:"yd",plural:"yards",alternates:["yd.","yds."]}};var W=s=>{let t=-1,e=s.length,p=0,o=[];for(;++t<e;){let d=s[t].trim();d&&(o[p++]=d)}return o};var oe=/\r?\n/,le=([s,t])=>({id:s,...t}),ie=(s,t=O)=>{let e={...O,...t},p={...w,...e.additionalUOMs},o=Object.entries(p).map(le),d=o.length;return W(s.split(oe)).map(c=>{let r={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1},h=f(c.substring(0,1));if(isNaN(h)){let a=R.exec(c);if(a){r.description=c.replace(R,"").trim();let n=a[3],l=a[12];n?(r.quantity=f(n),r.quantity2=f(l)):r.quantity=f(l);let u=a.at(-1);if(u){let m="",I="",x=-1;for(;++x<d&&!m;){let{alternates:v,id:M,short:D,plural:j}=o[x];[...v,M,D,j].includes(u)&&(m=u,I=M)}m&&(r.unitOfMeasureID=I,r.unitOfMeasure=e.normalizeUOM?I:m)}}else r.description=c,(r.description.endsWith(":")||E.test(r.description))&&(r.isGroupHeader=!0)}else{let a=6,n=NaN;for(;a>0&&isNaN(n);)n=f(c.substring(0,a).trim()),n>-1&&(r.quantity=n,r.description=c.substring(a).trim()),a--}let g=C.exec(r.description);if(g){let a=g[1].length,n=f(r.description.substring(a).trim()[0]);if(!isNaN(n)){let l=7,u=NaN;for(;--l>0&&isNaN(u);)u=f(r.description.substring(a,l)),isNaN(u)||(r.quantity2=u,r.description=r.description.substring(l).trim())}}let i=X.exec(r.description);if(i){let a=i[1].replace(/\s+/g," "),n=(i[2]??"").trim();if(n){let l="",u="",m=-1;for(;++m<d&&!l;){let{alternates:I,id:x,short:v,plural:M}=o[m];[...I,x,v,M].includes(a)&&(l=a,u=x)}l&&(r.unitOfMeasureID=u,r.unitOfMeasure=e.normalizeUOM?u:l,r.description=n)}}return!e.allowLeadingOf&&r.description.match(b)&&(r.description=r.description.replace(b,"")),r})};return J(ue);})(); | ||
"use strict";var ParseIngredient=(()=>{var v=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var Q=(r,e)=>{for(var s in e)v(r,s,{get:e[s],enumerable:!0})},G=(r,e,s,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of T(e))!B.call(r,o)&&o!==s&&v(r,o,{get:()=>e[o],enumerable:!(c=S(e,o))||c.enumerable});return r};var H=r=>G(v({},"__esModule",{value:!0}),r);var ls={};Q(ls,{defaultOptions:()=>O,firstWordRegEx:()=>C,fors:()=>A,forsRegEx:()=>E,ofRegEx:()=>y,ofs:()=>j,parseIngredient:()=>os,rangeSeparatorRegEx:()=>X,rangeSeparatorWords:()=>P,trailingQuantityRegEx:()=>R,unitsOfMeasure:()=>w});var J=Object.defineProperty,V=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable,$=(r,e,s)=>e in r?J(r,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[e]=s,q=(r,e)=>{for(var s in e||(e={}))K.call(e,s)&&$(r,s,e[s]);if(V)for(var s of V(e))Y.call(e,s)&&$(r,s,e[s]);return r},k={"\xBC":"1/4","\xBD":"1/2","\xBE":"3/4","\u2150":"1/7","\u2151":"1/9","\u2152":"1/10","\u2153":"1/3","\u2154":"2/3","\u2155":"1/5","\u2156":"2/5","\u2157":"3/5","\u2158":"4/5","\u2159":"1/6","\u215A":"5/6","\u215B":"1/8","\u215C":"3/8","\u215D":"5/8","\u215E":"7/8","\u215F":"1/"},_=/^(?=-?\s*\.\d|-?\s*\d)(-)?\s*((?:\d(?:[\d,_]*\d)?)*)(([eE][+-]?\d(?:[\d,_]*\d)?)?|\.\d(?:[\d,_]*\d)?([eE][+-]?\d(?:[\d,_]*\d)?)?|(\s+\d(?:[\d,_]*\d)?\s*)?\s*\/\s*\d(?:[\d,_]*\d)?)?$/,Z=/^(?=-?\s*\.\d|-?\s*\d)(-)?\s*((?:\d(?:[\d,_]*\d)?)*)(([eE][+-]?\d(?:[\d,_]*\d)?)?|\.\d(?:[\d,_]*\d)?([eE][+-]?\d(?:[\d,_]*\d)?)?|(\s+\d(?:[\d,_]*\d)?\s*)?\s*\/\s*\d(?:[\d,_]*\d)?)?(?:\s*[^\.\d\/].*)?/,ss=new RegExp(`(${Object.keys(k).join("|")})`),N={MMM:3e3,MM:2e3,M:1e3,CM:900,DCCC:800,DCC:700,DC:600,D:500,CD:400,CCC:300,CC:200,C:100,XC:90,LXXX:80,LXX:70,LX:60,L:50,XL:40,XXX:30,XX:20,XII:12,XI:11,X:10,IX:9,VIII:8,VII:7,VI:6,V:5,IV:4,III:3,II:2,I:1},U={"\u2160":"I","\u2161":"II","\u2162":"III","\u2163":"IV","\u2164":"V","\u2165":"VI","\u2166":"VII","\u2167":"VIII","\u2168":"IX","\u2169":"X","\u216A":"XI","\u216B":"XII","\u216C":"L","\u216D":"C","\u216E":"D","\u216F":"M","\u2170":"I","\u2171":"II","\u2172":"III","\u2173":"IV","\u2174":"V","\u2175":"VI","\u2176":"VII","\u2177":"VIII","\u2178":"IX","\u2179":"X","\u217A":"XI","\u217B":"XII","\u217C":"L","\u217D":"C","\u217E":"D","\u217F":"M"},ts=new RegExp(`(${Object.keys(U).join("|")})`,"gi"),es=/^(?=[MDCLXVI])(M{0,3})(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/i,L={round:3,allowTrailingInvalid:!1,romanNumerals:!1},rs=r=>{var e,s,c,o;let m=`${r}`.replace(ts,(a,i)=>U[i]).toUpperCase(),h=es.exec(m);if(!h)return NaN;let[,p,t,g,l]=h;return((e=N[p])!=null?e:0)+((s=N[t])!=null?s:0)+((c=N[g])!=null?c:0)+((o=N[l])!=null?o:0)},as=/^\s*\//,f=(r,e=L)=>{if(typeof r=="number"||typeof r=="bigint")return r;let s=NaN,c=`${r}`.replace(ss,(i,n)=>` ${k[n]}`).replace("\u2044","/").trim();if(c.length===0)return NaN;let o=q(q({},L),e),m=(o.allowTrailingInvalid?Z:_).exec(c);if(!m)return o.romanNumerals?rs(c):NaN;let[,h,p,t]=m,g=p.replace(/[,_]/g,""),l=t==null?void 0:t.replace(/[,_]/g,"");if(!g&&l&&l.startsWith(".")?s=0:s=parseInt(g),!l)return h?s*-1:s;let a=o.round===!1?NaN:parseFloat(`1e${Math.floor(Math.max(0,o.round))}`);if(l.startsWith(".")||l.startsWith("e")||l.startsWith("E")){let i=parseFloat(`${s}${l}`);s=isNaN(a)?i:Math.round(i*a)/a}else if(as.test(l)){let i=parseInt(g),n=parseInt(l.replace("/",""));s=isNaN(a)?i/n:Math.round(i*a/n)/a}else{let i=l.split("/"),[n,u]=i.map(d=>parseInt(d));s+=isNaN(a)?n/u:Math.round(n*a/u)/a}return h?s*-1:s};var O={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1},A=["For"],E=new RegExp(`^(?:${A.join("|")})\\s`,"i"),P=["or","to"],W=`(-|\u2013|\u2014|(?:${P.join("|")})\\s)`,X=new RegExp(`^${W}`,"i"),C=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,z=_.source.replace(/^\^/,"").replace(/\$$/,""),R=new RegExp(`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${z})\\s*(${W}))?\\s*(${z})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`,"i"),j=["of"],y=new RegExp(`^(?:${j.join("|")})\\s+`,"i"),w={bag:{short:"bag",plural:"bags",alternates:[]},box:{short:"box",plural:"boxes",alternates:[]},bunch:{short:"bunch",plural:"bunches",alternates:[]},can:{short:"can",plural:"cans",alternates:[]},carton:{short:"carton",plural:"cartons",alternates:[]},centimeter:{short:"cm",plural:"centimeters",alternates:["cm."]},clove:{short:"clove",plural:"cloves",alternates:[]},container:{short:"container",plural:"containers",alternates:[]},cup:{short:"c",plural:"cups",alternates:["c.","C"]},dash:{short:"dash",plural:"dashes",alternates:[]},drop:{short:"drop",plural:"drops",alternates:[]},ear:{short:"ear",plural:"ears",alternates:[]},"fluid ounce":{short:"fl oz",plural:"fluid ounces",alternates:["fluidounce","floz","fl-oz","fluid-ounce","fluid-ounces","fluidounces","fl ounce","fl ounces","fl-ounce","fl-ounces","fluid oz","fluid-oz"]},foot:{short:"ft",plural:"feet",alternates:["ft."]},gallon:{short:"gal",plural:"gallons",alternates:["gal."]},gram:{short:"g",plural:"grams",alternates:["g."]},head:{short:"head",plural:"heads",alternates:[]},inch:{short:"in",plural:"inches",alternates:["in."]},kilogram:{short:"kg",plural:"kilograms",alternates:["kg."]},large:{short:"lg",plural:"large",alternates:["lg","lg."]},liter:{short:"l",plural:"liters",alternates:[]},medium:{short:"md",plural:"medium",alternates:["med","med.","md."]},meter:{short:"m",plural:"meters",alternates:["m."]},milligram:{short:"mg",plural:"milligrams",alternates:["mg."]},milliliter:{short:"ml",plural:"milliliters",alternates:["mL","ml.","mL."]},millimeter:{short:"mm",plural:"millimeters",alternates:["mm."]},ounce:{short:"oz",plural:"ounces",alternates:["oz."]},pack:{short:"pack",plural:"packs",alternates:[]},package:{short:"pkg",plural:"packages",alternates:["pkg.","pkgs"]},piece:{short:"piece",plural:"pieces",alternates:["pcs","pcs."]},pinch:{short:"pinch",plural:"pinches",alternates:[]},pint:{short:"pt",plural:"pints",alternates:["pt."]},pound:{short:"lb",plural:"pounds",alternates:["lb.","lbs","lbs."]},quart:{short:"qt",plural:"quarts",alternates:["qt.","qts","qts."]},small:{short:"sm",plural:"small",alternates:["sm."]},sprig:{short:"sprig",plural:"sprigs",alternates:[]},stick:{short:"stick",plural:"sticks",alternates:[]},tablespoon:{short:"tbsp",plural:"tablespoons",alternates:["tbsp.","T","Tbsp."]},teaspoon:{short:"tsp",plural:"teaspoons",alternates:["tsp.","t"]},yard:{short:"yd",plural:"yards",alternates:["yd.","yds."]}};var is=/\r?\n/,ns=([r,e])=>({id:r,...e}),os=(r,e=O)=>{let s={...O,...e},c={...w,...s.additionalUOMs},o=Object.entries(c).map(ns),m=o.length;return r.split(is).map(p=>p.trim()).filter(Boolean).map(p=>{let t={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1};if(isNaN(f(p[0]))){let a=R.exec(p);if(a){t.description=p.replace(R,"").trim();let i=a[3],n=a[12];i?(t.quantity=f(i),t.quantity2=f(n)):t.quantity=f(n);let u=a.at(-1);if(u){let d="",I="",x=-1;for(;++x<m&&!d;){let{alternates:b,id:M,short:D,plural:F}=o[x];[...b,M,D,F].includes(u)&&(d=u,I=M)}d&&(t.unitOfMeasureID=I,t.unitOfMeasure=s.normalizeUOM?I:d)}}else t.description=p,(t.description.endsWith(":")||E.test(t.description))&&(t.isGroupHeader=!0)}else{let a=6,i=NaN;for(;a>0&&isNaN(i);)i=f(p.substring(0,a).trim()),i>-1&&(t.quantity=i,t.description=p.substring(a).trim()),a--}let g=X.exec(t.description);if(g){let a=g[1].length,i=f(t.description.substring(a).trim()[0]);if(!isNaN(i)){let n=7,u=NaN;for(;--n>0&&isNaN(u);)u=f(t.description.substring(a,n)),isNaN(u)||(t.quantity2=u,t.description=t.description.substring(n).trim())}}let l=C.exec(t.description);if(l){let a=l[1].replace(/\s+/g," "),i=(l[2]??"").trim();if(i){let n="",u="",d=-1;for(;++d<m&&!n;){let{alternates:I,id:x,short:b,plural:M}=o[d];[...I,x,b,M].includes(a)&&(n=a,u=x)}n&&(t.unitOfMeasureID=u,t.unitOfMeasure=s.normalizeUOM?u:n,t.description=i)}}return!s.allowLeadingOf&&t.description.match(y)&&(t.description=t.description.replace(y,"")),t})};return H(ls);})(); | ||
//# sourceMappingURL=parse-ingredient.umd.min.js.map |
{ | ||
"name": "parse-ingredient", | ||
"author": "Jake Boone", | ||
"version": "1.1.0-beta.0", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -51,10 +51,10 @@ "description": "Recipe ingredient parser with support for mixed numbers and vulgar fractions", | ||
"devDependencies": { | ||
"@types/web": "^0.0.114", | ||
"bun-types": "^1.0.1", | ||
"np": "^8.0.4", | ||
"@types/web": "^0.0.123", | ||
"bun-types": "^1.0.14", | ||
"np": "^9.0.0", | ||
"open": "^9.1.0", | ||
"prettier": "^3.0.3", | ||
"tsup": "^7.2.0", | ||
"typedoc": "^0.25.1", | ||
"typescript": "^5.2.2" | ||
"prettier": "^3.1.0", | ||
"tsup": "^8.0.1", | ||
"typedoc": "^0.25.4", | ||
"typescript": "^5.3.2" | ||
}, | ||
@@ -61,0 +61,0 @@ "dependencies": { |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
197663
1214
1