parse-ingredient
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -255,3 +255,3 @@ /** | ||
readonly plural: "liters"; | ||
readonly alternates: never[]; | ||
readonly alternates: string[]; | ||
}; | ||
@@ -258,0 +258,0 @@ readonly medium: { |
@@ -178,3 +178,3 @@ "use strict"; | ||
plural: "liters", | ||
alternates: [] | ||
alternates: ["l."] | ||
}, | ||
@@ -219,3 +219,3 @@ medium: { | ||
plural: "packages", | ||
alternates: ["pkg.", "pkgs"] | ||
alternates: ["pkg.", "pkgs", "pkgs."] | ||
}, | ||
@@ -225,3 +225,3 @@ piece: { | ||
plural: "pieces", | ||
alternates: ["pcs", "pcs."] | ||
alternates: ["pc", "pc.", "pcs", "pcs."] | ||
}, | ||
@@ -266,3 +266,3 @@ pinch: { | ||
plural: "tablespoons", | ||
alternates: ["tbsp.", "T", "Tbsp."] | ||
alternates: ["tbsp.", "T", "Tbsp.", "Tbsp"] | ||
}, | ||
@@ -269,0 +269,0 @@ teaspoon: { |
@@ -255,3 +255,3 @@ /** | ||
readonly plural: "liters"; | ||
readonly alternates: never[]; | ||
readonly alternates: string[]; | ||
}; | ||
@@ -258,0 +258,0 @@ readonly medium: { |
@@ -1,2 +0,2 @@ | ||
"use strict";var M=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var j=(a,e)=>{for(var n in e)M(a,n,{get:e[n],enumerable:!0})},P=(a,e,n,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of A(e))!S.call(a,o)&&o!==n&&M(a,o,{get:()=>e[o],enumerable:!(d=W(e,o))||d.enumerable});return a};var T=a=>P(M({},"__esModule",{value:!0}),a);var H={};j(H,{defaultOptions:()=>h,firstWordRegEx:()=>N,fors:()=>D,forsRegEx:()=>q,ofRegEx:()=>O,ofs:()=>Q,parseIngredient:()=>G,rangeSeparatorRegEx:()=>E,rangeSeparatorWords:()=>v,trailingQuantityRegEx:()=>x,unitsOfMeasure:()=>k});module.exports=T(H);var u=require("numeric-quantity");var $=require("numeric-quantity"),h={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1,ignoreUOMs:[]},D=["For"],q=new RegExp(`^(?:${D.join("|")})\\s`,"i"),v=["or","to"],L=`(-|\u2013|\u2014|(?:${v.join("|")})\\s)`,E=new RegExp(`^${L}`,"i"),N=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,z=$.numericRegex.source.replace(/^\^/,"").replace(/\$$/,""),x=new RegExp(`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${z})\\s*(${L}))?\\s*(${z})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`,"i"),Q=["of"],O=new RegExp(`^(?:${Q.join("|")})\\s+`,"i"),k={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 n={...h,...e},d={...k,...n.additionalUOMs},o=Object.entries(d).map(F),w=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&&n.ignoreUOMs.includes(t.at(-1)??""))s.description=p;else if(t){s.description=p.replace(x,"").trim();let r=t[3],l=t[12];r?(s.quantity=(0,u.numericQuantity)(r),s.quantity2=(0,u.numericQuantity)(l)):s.quantity=(0,u.numericQuantity)(l);let i=t.at(-1);if(i){let c="",g="",f=-1;for(;++f<w&&!c;){let{alternates:R,id:m,short:U,plural:b}=o[f];[...R,m,U,b].includes(i)&&(c=i,g=m)}c&&(s.unitOfMeasureID=g,s.unitOfMeasure=n.normalizeUOM?g:c)}}else s.description=p,(s.description.endsWith(":")||q.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 I=E.exec(s.description);if(I){let t=I[1].length,r=(0,u.numericQuantity)(s.description.substring(t).trim()[0]);if(!isNaN(r)){let l=7,i=NaN;for(;--l>0&&isNaN(i);)i=(0,u.numericQuantity)(s.description.substring(t,l)),isNaN(i)||(s.quantity2=i,s.description=s.description.substring(l).trim())}}let y=N.exec(s.description);if(y){let t=y[1].replace(/\s+/g," "),r=(y[2]??"").trim();if(r){let l="",i="",c=-1;for(;++c<w&&!l;){let{alternates:g,id:f,short:R,plural:m}=o[c];[...g,f,R,m].filter(b=>!n.ignoreUOMs.includes(b)).includes(t)&&(l=t,i=f)}l&&(s.unitOfMeasureID=i,s.unitOfMeasure=n.normalizeUOM?i:l,s.description=r)}}return!n.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}); | ||
"use strict";var M=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var j=(a,e)=>{for(var n in e)M(a,n,{get:e[n],enumerable:!0})},P=(a,e,n,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of A(e))!S.call(a,o)&&o!==n&&M(a,o,{get:()=>e[o],enumerable:!(d=W(e,o))||d.enumerable});return a};var T=a=>P(M({},"__esModule",{value:!0}),a);var H={};j(H,{defaultOptions:()=>h,firstWordRegEx:()=>k,fors:()=>D,forsRegEx:()=>q,ofRegEx:()=>O,ofs:()=>Q,parseIngredient:()=>G,rangeSeparatorRegEx:()=>E,rangeSeparatorWords:()=>v,trailingQuantityRegEx:()=>x,unitsOfMeasure:()=>N});module.exports=T(H);var u=require("numeric-quantity");var $=require("numeric-quantity"),h={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1,ignoreUOMs:[]},D=["For"],q=new RegExp(`^(?:${D.join("|")})\\s`,"i"),v=["or","to"],L=`(-|\u2013|\u2014|(?:${v.join("|")})\\s)`,E=new RegExp(`^${L}`,"i"),k=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,z=$.numericRegex.source.replace(/^\^/,"").replace(/\$$/,""),x=new RegExp(`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${z})\\s*(${L}))?\\s*(${z})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`,"i"),Q=["of"],O=new RegExp(`^(?:${Q.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:["l."]},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","pkgs."]},piece:{short:"piece",plural:"pieces",alternates:["pc","pc.","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.","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 n={...h,...e},d={...N,...n.additionalUOMs},o=Object.entries(d).map(F),w=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&&n.ignoreUOMs.includes(t.at(-1)??""))s.description=p;else if(t){s.description=p.replace(x,"").trim();let r=t[3],l=t[12];r?(s.quantity=(0,u.numericQuantity)(r),s.quantity2=(0,u.numericQuantity)(l)):s.quantity=(0,u.numericQuantity)(l);let i=t.at(-1);if(i){let c="",g="",f=-1;for(;++f<w&&!c;){let{alternates:y,id:m,short:U,plural:R}=o[f];[...y,m,U,R].includes(i)&&(c=i,g=m)}c&&(s.unitOfMeasureID=g,s.unitOfMeasure=n.normalizeUOM?g:c)}}else s.description=p,(s.description.endsWith(":")||q.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 I=E.exec(s.description);if(I){let t=I[1].length,r=(0,u.numericQuantity)(s.description.substring(t).trim()[0]);if(!isNaN(r)){let l=7,i=NaN;for(;--l>0&&isNaN(i);)i=(0,u.numericQuantity)(s.description.substring(t,l)),isNaN(i)||(s.quantity2=i,s.description=s.description.substring(l).trim())}}let b=k.exec(s.description);if(b){let t=b[1].replace(/\s+/g," "),r=(b[2]??"").trim();if(r){let l="",i="",c=-1;for(;++c<w&&!l;){let{alternates:g,id:f,short:y,plural:m}=o[c];[...g,f,y,m].filter(R=>!n.ignoreUOMs.includes(R)).includes(t)&&(l=t,i=f)}l&&(s.unitOfMeasureID=i,s.unitOfMeasure=n.normalizeUOM?i:l,s.description=r)}}return!n.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 |
@@ -159,3 +159,3 @@ var __defProp = Object.defineProperty; | ||
plural: "liters", | ||
alternates: [] | ||
alternates: ["l."] | ||
}, | ||
@@ -200,3 +200,3 @@ medium: { | ||
plural: "packages", | ||
alternates: ["pkg.", "pkgs"] | ||
alternates: ["pkg.", "pkgs", "pkgs."] | ||
}, | ||
@@ -206,3 +206,3 @@ piece: { | ||
plural: "pieces", | ||
alternates: ["pcs", "pcs."] | ||
alternates: ["pc", "pc.", "pcs", "pcs."] | ||
}, | ||
@@ -247,3 +247,3 @@ pinch: { | ||
plural: "tablespoons", | ||
alternates: ["tbsp.", "T", "Tbsp."] | ||
alternates: ["tbsp.", "T", "Tbsp.", "Tbsp"] | ||
}, | ||
@@ -250,0 +250,0 @@ teaspoon: { |
@@ -1,2 +0,2 @@ | ||
"use strict";var ParseIngredient=(()=>{var E=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var B=(a,n)=>{for(var e in n)E(a,e,{get:n[e],enumerable:!0})},Q=(a,n,e,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of T(n))!j.call(a,o)&&o!==e&&E(a,o,{get:()=>n[o],enumerable:!(c=_(n,o))||c.enumerable});return a};var S=a=>Q(E({},"__esModule",{value:!0}),a);var es={};B(es,{defaultOptions:()=>O,firstWordRegEx:()=>$,fors:()=>z,forsRegEx:()=>v,ofRegEx:()=>y,ofs:()=>F,parseIngredient:()=>ts,rangeSeparatorRegEx:()=>D,rangeSeparatorWords:()=>A,trailingQuantityRegEx:()=>b,unitsOfMeasure:()=>w});var q={"\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/"},R=/^(?=-?\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)?)?$/,G=new RegExp(R.source.replace(/\$$/,"(?:\\s*[^\\.\\d\\/].*)?")),P=new RegExp(`(${Object.keys(q).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},L={"\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"},H=new RegExp(`(${Object.keys(L).join("|")})`,"gi"),J=/^(?=[MDCLXVI])(M{0,3})(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/i,k={round:3,allowTrailingInvalid:!1,romanNumerals:!1},K=a=>{let n=`${a}`.replace(H,(p,s)=>L[s]).toUpperCase(),e=J.exec(n);if(!e)return NaN;let[,c,o,d,h]=e;return(N[c]??0)+(N[o]??0)+(N[d]??0)+(N[h]??0)},Y=/^\s*\//,f=(a,n=k)=>{if(typeof a=="number"||typeof a=="bigint")return a;let e=NaN,c=`${a}`.replace(P,(r,i)=>` ${q[i]}`).replace("\u2044","/").trim();if(c.length===0)return NaN;let o={...k,...n},d=(o.allowTrailingInvalid?G:R).exec(c);if(!d)return o.romanNumerals?K(c):NaN;let[,h,p,s]=d,m=p.replace(/[,_]/g,""),u=s==null?void 0:s.replace(/[,_]/g,"");if(!m&&u&&u.startsWith(".")?e=0:e=parseInt(m),!u)return h?e*-1:e;let t=o.round===!1?NaN:parseFloat(`1e${Math.floor(Math.max(0,o.round))}`);if(u.startsWith(".")||u.startsWith("e")||u.startsWith("E")){let r=parseFloat(`${e}${u}`);e=isNaN(t)?r:Math.round(r*t)/t}else if(Y.test(u)){let r=parseInt(m),i=parseInt(u.replace("/",""));e=isNaN(t)?r/i:Math.round(r*t/i)/t}else{let r=u.split("/"),[i,l]=r.map(g=>parseInt(g));e+=isNaN(t)?i/l:Math.round(i*t/l)/t}return h?e*-1:e};var O={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1,ignoreUOMs:[]},z=["For"],v=new RegExp(`^(?:${z.join("|")})\\s`,"i"),A=["or","to"],W=`(-|\u2013|\u2014|(?:${A.join("|")})\\s)`,D=new RegExp(`^${W}`,"i"),$=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,U=R.source.replace(/^\^/,"").replace(/\$$/,""),b=new RegExp(`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${U})\\s*(${W}))?\\s*(${U})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`,"i"),F=["of"],y=new RegExp(`^(?:${F.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 Z=/\r?\n/,ss=([a,n])=>({id:a,...n}),ts=(a,n=O)=>{let e={...O,...n},c={...w,...e.additionalUOMs},o=Object.entries(c).map(ss),d=o.length;return a.split(Z).map(p=>p.trim()).filter(Boolean).map(p=>{let s={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1};if(isNaN(f(p[0]))){let t=b.exec(p);if(t&&e.ignoreUOMs.includes(t.at(-1)??""))s.description=p;else if(t){s.description=p.replace(b,"").trim();let r=t[3],i=t[12];r?(s.quantity=f(r),s.quantity2=f(i)):s.quantity=f(i);let l=t.at(-1);if(l){let g="",I="",x=-1;for(;++x<d&&!g;){let{alternates:X,id:M,short:V,plural:C}=o[x];[...X,M,V,C].includes(l)&&(g=l,I=M)}g&&(s.unitOfMeasureID=I,s.unitOfMeasure=e.normalizeUOM?I:g)}}else s.description=p,(s.description.endsWith(":")||v.test(s.description))&&(s.isGroupHeader=!0)}else{let t=6,r=NaN;for(;t>0&&isNaN(r);)r=f(p.substring(0,t).trim()),r>-1&&(s.quantity=r,s.description=p.substring(t).trim()),t--}let m=D.exec(s.description);if(m){let t=m[1].length,r=f(s.description.substring(t).trim()[0]);if(!isNaN(r)){let i=7,l=NaN;for(;--i>0&&isNaN(l);)l=f(s.description.substring(t,i)),isNaN(l)||(s.quantity2=l,s.description=s.description.substring(i).trim())}}let u=$.exec(s.description);if(u){let t=u[1].replace(/\s+/g," "),r=(u[2]??"").trim();if(r){let i="",l="",g=-1;for(;++g<d&&!i;){let{alternates:I,id:x,short:X,plural:M}=o[g];[...I,x,X,M].filter(C=>!e.ignoreUOMs.includes(C)).includes(t)&&(i=t,l=x)}i&&(s.unitOfMeasureID=l,s.unitOfMeasure=e.normalizeUOM?l:i,s.description=r)}}return!e.allowLeadingOf&&s.description.match(y)&&(s.description=s.description.replace(y,"")),s})};return S(es);})(); | ||
"use strict";var ParseIngredient=(()=>{var E=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var B=(a,n)=>{for(var e in n)E(a,e,{get:n[e],enumerable:!0})},Q=(a,n,e,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of _(n))!j.call(a,o)&&o!==e&&E(a,o,{get:()=>n[o],enumerable:!(c=T(n,o))||c.enumerable});return a};var S=a=>Q(E({},"__esModule",{value:!0}),a);var es={};B(es,{defaultOptions:()=>O,firstWordRegEx:()=>$,fors:()=>z,forsRegEx:()=>v,ofRegEx:()=>y,ofs:()=>F,parseIngredient:()=>ts,rangeSeparatorRegEx:()=>D,rangeSeparatorWords:()=>A,trailingQuantityRegEx:()=>b,unitsOfMeasure:()=>w});var q={"\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/"},R=/^(?=-?\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)?)?$/,G=new RegExp(R.source.replace(/\$$/,"(?:\\s*[^\\.\\d\\/].*)?")),P=new RegExp(`(${Object.keys(q).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},L={"\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"},H=new RegExp(`(${Object.keys(L).join("|")})`,"gi"),J=/^(?=[MDCLXVI])(M{0,3})(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/i,k={round:3,allowTrailingInvalid:!1,romanNumerals:!1},K=a=>{let n=`${a}`.replace(H,(p,s)=>L[s]).toUpperCase(),e=J.exec(n);if(!e)return NaN;let[,c,o,d,h]=e;return(N[c]??0)+(N[o]??0)+(N[d]??0)+(N[h]??0)},Y=/^\s*\//,f=(a,n=k)=>{if(typeof a=="number"||typeof a=="bigint")return a;let e=NaN,c=`${a}`.replace(P,(r,i)=>` ${q[i]}`).replace("\u2044","/").trim();if(c.length===0)return NaN;let o={...k,...n},d=(o.allowTrailingInvalid?G:R).exec(c);if(!d)return o.romanNumerals?K(c):NaN;let[,h,p,s]=d,m=p.replace(/[,_]/g,""),u=s==null?void 0:s.replace(/[,_]/g,"");if(!m&&u&&u.startsWith(".")?e=0:e=parseInt(m),!u)return h?e*-1:e;let t=o.round===!1?NaN:parseFloat(`1e${Math.floor(Math.max(0,o.round))}`);if(u.startsWith(".")||u.startsWith("e")||u.startsWith("E")){let r=parseFloat(`${e}${u}`);e=isNaN(t)?r:Math.round(r*t)/t}else if(Y.test(u)){let r=parseInt(m),i=parseInt(u.replace("/",""));e=isNaN(t)?r/i:Math.round(r*t/i)/t}else{let r=u.split("/"),[i,l]=r.map(g=>parseInt(g));e+=isNaN(t)?i/l:Math.round(i*t/l)/t}return h?e*-1:e};var O={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1,ignoreUOMs:[]},z=["For"],v=new RegExp(`^(?:${z.join("|")})\\s`,"i"),A=["or","to"],W=`(-|\u2013|\u2014|(?:${A.join("|")})\\s)`,D=new RegExp(`^${W}`,"i"),$=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,U=R.source.replace(/^\^/,"").replace(/\$$/,""),b=new RegExp(`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${U})\\s*(${W}))?\\s*(${U})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`,"i"),F=["of"],y=new RegExp(`^(?:${F.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:["l."]},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","pkgs."]},piece:{short:"piece",plural:"pieces",alternates:["pc","pc.","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.","Tbsp"]},teaspoon:{short:"tsp",plural:"teaspoons",alternates:["tsp.","t"]},yard:{short:"yd",plural:"yards",alternates:["yd.","yds."]}};var Z=/\r?\n/,ss=([a,n])=>({id:a,...n}),ts=(a,n=O)=>{let e={...O,...n},c={...w,...e.additionalUOMs},o=Object.entries(c).map(ss),d=o.length;return a.split(Z).map(p=>p.trim()).filter(Boolean).map(p=>{let s={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1};if(isNaN(f(p[0]))){let t=b.exec(p);if(t&&e.ignoreUOMs.includes(t.at(-1)??""))s.description=p;else if(t){s.description=p.replace(b,"").trim();let r=t[3],i=t[12];r?(s.quantity=f(r),s.quantity2=f(i)):s.quantity=f(i);let l=t.at(-1);if(l){let g="",I="",x=-1;for(;++x<d&&!g;){let{alternates:X,id:M,short:V,plural:C}=o[x];[...X,M,V,C].includes(l)&&(g=l,I=M)}g&&(s.unitOfMeasureID=I,s.unitOfMeasure=e.normalizeUOM?I:g)}}else s.description=p,(s.description.endsWith(":")||v.test(s.description))&&(s.isGroupHeader=!0)}else{let t=6,r=NaN;for(;t>0&&isNaN(r);)r=f(p.substring(0,t).trim()),r>-1&&(s.quantity=r,s.description=p.substring(t).trim()),t--}let m=D.exec(s.description);if(m){let t=m[1].length,r=f(s.description.substring(t).trim()[0]);if(!isNaN(r)){let i=7,l=NaN;for(;--i>0&&isNaN(l);)l=f(s.description.substring(t,i)),isNaN(l)||(s.quantity2=l,s.description=s.description.substring(i).trim())}}let u=$.exec(s.description);if(u){let t=u[1].replace(/\s+/g," "),r=(u[2]??"").trim();if(r){let i="",l="",g=-1;for(;++g<d&&!i;){let{alternates:I,id:x,short:X,plural:M}=o[g];[...I,x,X,M].filter(C=>!e.ignoreUOMs.includes(C)).includes(t)&&(i=t,l=x)}i&&(s.unitOfMeasureID=l,s.unitOfMeasure=e.normalizeUOM?l:i,s.description=r)}}return!e.allowLeadingOf&&s.description.match(y)&&(s.description=s.description.replace(y,"")),s})};return S(es);})(); | ||
//# sourceMappingURL=parse-ingredient.umd.min.js.map |
{ | ||
"name": "parse-ingredient", | ||
"author": "Jake Boone", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"license": "MIT", | ||
@@ -48,6 +48,6 @@ "description": "Recipe ingredient parser with support for mixed numbers and vulgar fractions", | ||
"build": "tsup", | ||
"docs": "bunx typedoc", | ||
"docs": "typedoc", | ||
"test": "bun test", | ||
"watch": "bun test --watch", | ||
"pretty-print": "prettier --write src *.{mjs,json,html,ts}", | ||
"pretty-print": "prettier --write '*.{html,json,ts}' './src/*.*'", | ||
"publish:npm": "np", | ||
@@ -57,10 +57,10 @@ "publish:demo": "bun ./gh-pages.publish.js" | ||
"devDependencies": { | ||
"@types/web": "^0.0.135", | ||
"bun-types": "^1.0.22", | ||
"np": "^9.2.0", | ||
"open": "^10.0.3", | ||
"prettier": "^3.2.2", | ||
"tsup": "^8.0.1", | ||
"typedoc": "^0.25.7", | ||
"typescript": "^5.3.3" | ||
"@types/web": "^0.0.151", | ||
"@types/bun": "^1.1.6", | ||
"np": "^10.0.6", | ||
"open": "^10.1.0", | ||
"prettier": "3.3.2", | ||
"tsup": "^8.1.0", | ||
"typedoc": "^0.26.3", | ||
"typescript": "^5.5.3" | ||
}, | ||
@@ -67,0 +67,0 @@ "dependencies": { |
@@ -239,2 +239,3 @@ [![npm][badge-npm]](https://www.npmjs.com/package/parse-ingredient) | ||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/rogermparent"><img src="https://avatars.githubusercontent.com/u/9111807?v=4?s=100" width="100px;" alt="Roger"/><br /><sub><b>Roger</b></sub></a><br /><a href="https://github.com/jakeboone02/parse-ingredient/commits?author=rogermparent" title="Code">💻</a></td> | ||
<td align="center" valign="top" width="14.28%"><a href="http://site.tylermayoff.com"><img src="https://avatars.githubusercontent.com/u/10094264?v=4?s=100" width="100px;" alt="Tyler"/><br /><sub><b>Tyler</b></sub></a><br /><a href="https://github.com/jakeboone02/parse-ingredient/commits?author=tmayoff" title="Code">💻</a> <a href="https://github.com/jakeboone02/parse-ingredient/commits?author=tmayoff" title="Tests">⚠️</a></td> | ||
</tr> | ||
@@ -253,3 +254,3 @@ </tbody> | ||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
[badge-all-contributors]: https://img.shields.io/badge/all_contributors-3-orange.svg | ||
[badge-all-contributors]: https://img.shields.io/badge/all_contributors-4-orange.svg | ||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
@@ -256,0 +257,0 @@ <!-- prettier-ignore-end --> |
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
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
241468
258