Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-ingredient

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-ingredient - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

65

dist/cjs/parse-ingredient.cjs.development.js

@@ -52,3 +52,3 @@ "use strict";

);
var firstWordRegEx = /^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)/;
var firstWordRegEx = /^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/;
var ofs = ["of"];

@@ -101,3 +101,3 @@ var ofRegEx = new RegExp(`^(?:${ofs.join("|")})\\s+`, "i");

// src/utils.ts
var compactArray = (array) => {
var compactStringArray = (array) => {
let index = -1;

@@ -108,3 +108,3 @@ const length = array.length;

while (++index < length) {
const value = array[index];
const value = array[index].trim();
if (value) {

@@ -118,10 +118,10 @@ result[resIndex++] = value;

// src/parseIngredient.ts
var newLineRegExp = /\r?\n/;
var addIdToUomDefinition = ([uom, def]) => ({ id: uom, ...def });
var parseIngredient = (ingText, options = defaultOptions) => {
const opts = { ...defaultOptions, ...options };
const mergedUOMs = { ...unitsOfMeasure, ...opts.additionalUOMs };
const uomArray = Object.entries(mergedUOMs).map(([uom, def]) => ({ id: uom, ...def }));
const arrRaw = compactArray(
ingText.replace(/\n{2,}/g, "\n").split("\n").map((ing) => ing.trim())
);
const arrIngs = arrRaw.map((line) => {
const uomArray = Object.entries(mergedUOMs).map(addIdToUomDefinition);
const uomArrayLength = uomArray.length;
return compactStringArray(ingText.split(newLineRegExp)).map((line) => {
const oIng = {

@@ -156,9 +156,7 @@ quantity: null,

const q2reMatchLen = q2reMatch[1].length;
const nqResultFirstChar2 = (0, import_numeric_quantity.numericQuantity)(
oIng.description.substring(q2reMatchLen).trim().substring(0, 1)
);
const nqResultFirstChar2 = (0, import_numeric_quantity.numericQuantity)(oIng.description.substring(q2reMatchLen).trim()[0]);
if (!isNaN(nqResultFirstChar2)) {
let lenNum = 6;
let lenNum = 7;
let nqResult = NaN;
while (lenNum > 0 && isNaN(nqResult)) {
while (--lenNum > 0 && isNaN(nqResult)) {
nqResult = (0, import_numeric_quantity.numericQuantity)(oIng.description.substring(q2reMatchLen, lenNum));

@@ -169,3 +167,2 @@ if (!isNaN(nqResult)) {

}
lenNum--;
}

@@ -177,27 +174,20 @@ }

const firstWord = firstWordREMatches[1].replace(/\s+/g, " ");
const remainingDesc = firstWordREMatches[2];
let uom = "";
let uomID = "";
let i = 0;
while (i < uomArray.length && !uom) {
const versions = [
...uomArray[i].alternates,
uomArray[i].id,
uomArray[i].short,
uomArray[i].plural
];
if (versions.includes(firstWord)) {
uom = firstWord;
uomID = uomArray[i].id;
const remainingDesc = (firstWordREMatches[2] ?? "").trim();
if (remainingDesc) {
let uom = "";
let uomID = "";
let i = -1;
while (++i < uomArrayLength && !uom) {
const { alternates, id, short, plural } = uomArray[i];
const versions = [...alternates, id, short, plural];
if (versions.includes(firstWord)) {
uom = firstWord;
uomID = id;
}
}
i++;
}
if (uom) {
oIng.unitOfMeasureID = uomID;
if (opts.normalizeUOM) {
oIng.unitOfMeasure = uomID;
} else {
oIng.unitOfMeasure = uom;
if (uom) {
oIng.unitOfMeasureID = uomID;
oIng.unitOfMeasure = opts.normalizeUOM ? uomID : uom;
oIng.description = remainingDesc;
}
oIng.description = remainingDesc.trim();
}

@@ -210,3 +200,2 @@ }

});
return arrIngs;
};

@@ -213,0 +202,0 @@ // Annotate the CommonJS export names for ESM import in node:

@@ -1,4 +0,2 @@

"use strict";var x=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var D=(s,r)=>{for(var a in r)x(s,a,{get:r[a],enumerable:!0})},v=(s,r,a,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of z(r))!U.call(s,e)&&e!==a&&x(s,e,{get:()=>r[e],enumerable:!(c=E(r,e))||c.enumerable});return s};var W=s=>v(x({},"__esModule",{value:!0}),s);var T={};D(T,{defaultOptions:()=>d,firstWordRegEx:()=>R,fors:()=>N,forsRegEx:()=>b,ofRegEx:()=>g,ofs:()=>I,parseIngredient:()=>L,rangeSeparatorRegEx:()=>O,rangeSeparatorWords:()=>k,unitsOfMeasure:()=>M});module.exports=W(T);var m=require("numeric-quantity");var d={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1},N=["For"],b=new RegExp(`^(?:${N.join("|")})\\s`,"i"),k=["or","to"],O=new RegExp(`^(-|\u2013|\u2014|(?:${k.join("|")})\\s)`,"i"),R=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)/,I=["of"],g=new RegExp(`^(?:${I.join("|")})\\s+`,"i"),M={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 y=s=>{let r=-1,a=s.length,c=0,e=[];for(;++r<a;){let f=s[r];f&&(e[c++]=f)}return e};var L=(s,r=d)=>{let a={...d,...r},c={...M,...a.additionalUOMs},e=Object.entries(c).map(([o,t])=>({id:o,...t}));return y(s.replace(/\n{2,}/g,`
`).split(`
`).map(o=>o.trim())).map(o=>{let t={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1},w=(0,m.numericQuantity)(o.substring(0,1));if(isNaN(w))t.description=o,(t.description.endsWith(":")||b.test(t.description))&&(t.isGroupHeader=!0);else{let l=6,i=NaN;for(;l>0&&isNaN(i);)i=(0,m.numericQuantity)(o.substring(0,l).trim()),i>-1&&(t.quantity=i,t.description=o.substring(l).trim()),l--}let q=O.exec(t.description);if(q){let l=q[1].length,i=(0,m.numericQuantity)(t.description.substring(l).trim().substring(0,1));if(!isNaN(i)){let n=6,p=NaN;for(;n>0&&isNaN(p);)p=(0,m.numericQuantity)(t.description.substring(l,n)),isNaN(p)||(t.quantity2=p,t.description=t.description.substring(n).trim()),n--}}let h=R.exec(t.description);if(h){let l=h[1].replace(/\s+/g," "),i=h[2],n="",p="",u=0;for(;u<e.length&&!n;)[...e[u].alternates,e[u].id,e[u].short,e[u].plural].includes(l)&&(n=l,p=e[u].id),u++;n&&(t.unitOfMeasureID=p,a.normalizeUOM?t.unitOfMeasure=p:t.unitOfMeasure=n,t.description=i.trim())}return!a.allowLeadingOf&&t.description.match(g)&&(t.description=t.description.replace(g,"")),t})};0&&(module.exports={defaultOptions,firstWordRegEx,fors,forsRegEx,ofRegEx,ofs,parseIngredient,rangeSeparatorRegEx,rangeSeparatorWords,unitsOfMeasure});
"use strict";var h=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var S=(r,e)=>{for(var a in e)h(r,a,{get:e[a],enumerable:!0})},j=(r,e,a,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of v(e))!W.call(r,s)&&s!==a&&h(r,s,{get:()=>e[s],enumerable:!(p=L(e,s))||p.enumerable});return r};var A=r=>j(h({},"__esModule",{value:!0}),r);var T={};S(T,{defaultOptions:()=>m,firstWordRegEx:()=>O,fors:()=>k,forsRegEx:()=>x,ofRegEx:()=>g,ofs:()=>I,parseIngredient:()=>F,rangeSeparatorRegEx:()=>b,rangeSeparatorWords:()=>y,unitsOfMeasure:()=>M});module.exports=A(T);var u=require("numeric-quantity");var m={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1},k=["For"],x=new RegExp(`^(?:${k.join("|")})\\s`,"i"),y=["or","to"],b=new RegExp(`^(-|\u2013|\u2014|(?:${y.join("|")})\\s)`,"i"),O=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,I=["of"],g=new RegExp(`^(?:${I.join("|")})\\s+`,"i"),M={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 E=r=>{let e=-1,a=r.length,p=0,s=[];for(;++e<a;){let c=r[e].trim();c&&(s[p++]=c)}return s};var P=/\r?\n/,C=([r,e])=>({id:r,...e}),F=(r,e=m)=>{let a={...m,...e},p={...M,...a.additionalUOMs},s=Object.entries(p).map(C),c=s.length;return E(r.split(P)).map(d=>{let t={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1},w=(0,u.numericQuantity)(d.substring(0,1));if(isNaN(w))t.description=d,(t.description.endsWith(":")||x.test(t.description))&&(t.isGroupHeader=!0);else{let n=6,l=NaN;for(;n>0&&isNaN(l);)l=(0,u.numericQuantity)(d.substring(0,n).trim()),l>-1&&(t.quantity=l,t.description=d.substring(n).trim()),n--}let R=b.exec(t.description);if(R){let n=R[1].length,l=(0,u.numericQuantity)(t.description.substring(n).trim()[0]);if(!isNaN(l)){let o=7,i=NaN;for(;--o>0&&isNaN(i);)i=(0,u.numericQuantity)(t.description.substring(n,o)),isNaN(i)||(t.quantity2=i,t.description=t.description.substring(o).trim())}}let f=O.exec(t.description);if(f){let n=f[1].replace(/\s+/g," "),l=(f[2]??"").trim();if(l){let o="",i="",q=-1;for(;++q<c&&!o;){let{alternates:z,id:N,short:U,plural:D}=s[q];[...z,N,U,D].includes(n)&&(o=n,i=N)}o&&(t.unitOfMeasureID=i,t.unitOfMeasure=a.normalizeUOM?i:o,t.description=l)}}return!a.allowLeadingOf&&t.description.match(g)&&(t.description=t.description.replace(g,"")),t})};0&&(module.exports={defaultOptions,firstWordRegEx,fors,forsRegEx,ofRegEx,ofs,parseIngredient,rangeSeparatorRegEx,rangeSeparatorWords,unitsOfMeasure});
//# sourceMappingURL=parse-ingredient.cjs.production.js.map

@@ -34,3 +34,3 @@ var __defProp = Object.defineProperty;

);
var firstWordRegEx = /^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)/;
var firstWordRegEx = /^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/;
var ofs = ["of"];

@@ -83,3 +83,3 @@ var ofRegEx = new RegExp(`^(?:${ofs.join("|")})\\s+`, "i");

// src/utils.ts
var compactArray = (array) => {
var compactStringArray = (array) => {
let index = -1;

@@ -90,3 +90,3 @@ const length = array.length;

while (++index < length) {
const value = array[index];
const value = array[index].trim();
if (value) {

@@ -100,10 +100,11 @@ result[resIndex++] = value;

// src/parseIngredient.ts
var newLineRegExp = /\r?\n/;
var addIdToUomDefinition = ([uom, def]) => __spreadValues({ id: uom }, def);
var parseIngredient = (ingText, options = defaultOptions) => {
const opts = __spreadValues(__spreadValues({}, defaultOptions), options);
const mergedUOMs = __spreadValues(__spreadValues({}, unitsOfMeasure), opts.additionalUOMs);
const uomArray = Object.entries(mergedUOMs).map(([uom, def]) => __spreadValues({ id: uom }, def));
const arrRaw = compactArray(
ingText.replace(/\n{2,}/g, "\n").split("\n").map((ing) => ing.trim())
);
const arrIngs = arrRaw.map((line) => {
const uomArray = Object.entries(mergedUOMs).map(addIdToUomDefinition);
const uomArrayLength = uomArray.length;
return compactStringArray(ingText.split(newLineRegExp)).map((line) => {
var _a;
const oIng = {

@@ -138,9 +139,7 @@ quantity: null,

const q2reMatchLen = q2reMatch[1].length;
const nqResultFirstChar2 = numericQuantity(
oIng.description.substring(q2reMatchLen).trim().substring(0, 1)
);
const nqResultFirstChar2 = numericQuantity(oIng.description.substring(q2reMatchLen).trim()[0]);
if (!isNaN(nqResultFirstChar2)) {
let lenNum = 6;
let lenNum = 7;
let nqResult = NaN;
while (lenNum > 0 && isNaN(nqResult)) {
while (--lenNum > 0 && isNaN(nqResult)) {
nqResult = numericQuantity(oIng.description.substring(q2reMatchLen, lenNum));

@@ -151,3 +150,2 @@ if (!isNaN(nqResult)) {

}
lenNum--;
}

@@ -159,27 +157,20 @@ }

const firstWord = firstWordREMatches[1].replace(/\s+/g, " ");
const remainingDesc = firstWordREMatches[2];
let uom = "";
let uomID = "";
let i = 0;
while (i < uomArray.length && !uom) {
const versions = [
...uomArray[i].alternates,
uomArray[i].id,
uomArray[i].short,
uomArray[i].plural
];
if (versions.includes(firstWord)) {
uom = firstWord;
uomID = uomArray[i].id;
const remainingDesc = ((_a = firstWordREMatches[2]) != null ? _a : "").trim();
if (remainingDesc) {
let uom = "";
let uomID = "";
let i = -1;
while (++i < uomArrayLength && !uom) {
const { alternates, id, short, plural } = uomArray[i];
const versions = [...alternates, id, short, plural];
if (versions.includes(firstWord)) {
uom = firstWord;
uomID = id;
}
}
i++;
}
if (uom) {
oIng.unitOfMeasureID = uomID;
if (opts.normalizeUOM) {
oIng.unitOfMeasure = uomID;
} else {
oIng.unitOfMeasure = uom;
if (uom) {
oIng.unitOfMeasureID = uomID;
oIng.unitOfMeasure = opts.normalizeUOM ? uomID : uom;
oIng.description = remainingDesc;
}
oIng.description = remainingDesc.trim();
}

@@ -192,3 +183,2 @@ }

});
return arrIngs;
};

@@ -195,0 +185,0 @@ export {

@@ -1,4 +0,2 @@

"use strict";var ParseIngredient=(()=>{var b=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var P=(s,r)=>{for(var e in r)b(s,e,{get:r[e],enumerable:!0})},T=(s,r,e,u)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of z(r))!F.call(s,a)&&a!==e&&b(s,a,{get:()=>r[a],enumerable:!(u=$(r,a))||u.enumerable});return s};var U=s=>T(b({},"__esModule",{value:!0}),s);var Z={};P(Z,{defaultOptions:()=>N,firstWordRegEx:()=>_,fors:()=>V,forsRegEx:()=>O,ofRegEx:()=>M,ofs:()=>q,parseIngredient:()=>Y,rangeSeparatorRegEx:()=>v,rangeSeparatorWords:()=>k,unitsOfMeasure:()=>R});var W=Object.defineProperty,C=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable,X=(s,r,e)=>r in s?W(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e,E=(s,r)=>{for(var e in r||(r={}))j.call(r,e)&&X(s,e,r[e]);if(C)for(var e of C(r))A.call(r,e)&&X(s,e,r[e]);return s},w={"\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=/^(?=-?\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)?)?$/,B=/^(?=-?\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\/].*)?/,G=new RegExp(`(${Object.keys(w).join("|")})`),x={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},D={"\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(D).join("|")})`,"gi"),Q=/^(?=[MDCLXVI])(M{0,3})(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/i,y={round:3,allowTrailingInvalid:!1,romanNumerals:!1},J=s=>{var r,e,u,a;let m=`${s}`.replace(H,(i,n)=>D[n]).toUpperCase(),h=Q.exec(m);if(!h)return NaN;let[,p,t,g,o]=h;return((r=x[p])!=null?r:0)+((e=x[t])!=null?e:0)+((u=x[g])!=null?u:0)+((a=x[o])!=null?a:0)},K=/^\s*\//,I=(s,r=y)=>{if(typeof s=="number"||typeof s=="bigint")return s;let e=NaN,u=`${s}`.replace(G,(n,l)=>` ${w[l]}`).replace("\u2044","/").trim();if(u.length===0)return NaN;let a=E(E({},y),r),m=(a.allowTrailingInvalid?B:S).exec(u);if(!m)return a.romanNumerals?J(u):NaN;let[,h,p,t]=m,g=p.replace(/[,_]/g,""),o=t?.replace(/[,_]/g,"");if(!g&&o&&o.startsWith(".")?e=0:e=parseInt(g),!o)return h?e*-1:e;let i=a.round===!1?NaN:parseFloat(`1e${Math.floor(Math.max(0,a.round))}`);if(o.startsWith(".")||o.startsWith("e")||o.startsWith("E")){let n=parseFloat(`${e}${o}`);e=isNaN(i)?n:Math.round(n*i)/i}else if(K.test(o)){let n=parseInt(g),l=parseInt(o.replace("/",""));e=isNaN(i)?n/l:Math.round(n*i/l)/i}else{let n=o.split("/"),[l,c]=n.map(d=>parseInt(d));e+=isNaN(i)?l/c:Math.round(l*i/c)/i}return h?e*-1:e};var N={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1},V=["For"],O=new RegExp(`^(?:${V.join("|")})\\s`,"i"),k=["or","to"],v=new RegExp(`^(-|\u2013|\u2014|(?:${k.join("|")})\\s)`,"i"),_=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)/,q=["of"],M=new RegExp(`^(?:${q.join("|")})\\s+`,"i"),R={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 L=s=>{let r=-1,e=s.length,u=0,a=[];for(;++r<e;){let m=s[r];m&&(a[u++]=m)}return a};var Y=(s,r=N)=>{let e={...N,...r},u={...R,...e.additionalUOMs},a=Object.entries(u).map(([p,t])=>({id:p,...t}));return L(s.replace(/\n{2,}/g,`
`).split(`
`).map(p=>p.trim())).map(p=>{let t={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1},g=I(p.substring(0,1));if(isNaN(g))t.description=p,(t.description.endsWith(":")||O.test(t.description))&&(t.isGroupHeader=!0);else{let n=6,l=NaN;for(;n>0&&isNaN(l);)l=I(p.substring(0,n).trim()),l>-1&&(t.quantity=l,t.description=p.substring(n).trim()),n--}let o=v.exec(t.description);if(o){let n=o[1].length,l=I(t.description.substring(n).trim().substring(0,1));if(!isNaN(l)){let c=6,d=NaN;for(;c>0&&isNaN(d);)d=I(t.description.substring(n,c)),isNaN(d)||(t.quantity2=d,t.description=t.description.substring(c).trim()),c--}}let i=_.exec(t.description);if(i){let n=i[1].replace(/\s+/g," "),l=i[2],c="",d="",f=0;for(;f<a.length&&!c;)[...a[f].alternates,a[f].id,a[f].short,a[f].plural].includes(n)&&(c=n,d=a[f].id),f++;c&&(t.unitOfMeasureID=d,e.normalizeUOM?t.unitOfMeasure=d:t.unitOfMeasure=c,t.description=l.trim())}return!e.allowLeadingOf&&t.description.match(M)&&(t.description=t.description.replace(M,"")),t})};return U(Z);})();
"use strict";var ParseIngredient=(()=>{var M=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var W=(r,t)=>{for(var e in t)M(r,e,{get:t[e],enumerable:!0})},j=(r,t,e,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of F(t))!P.call(r,l)&&l!==e&&M(r,l,{get:()=>t[l],enumerable:!(u=A(t,l))||u.enumerable});return r};var S=r=>j(M({},"__esModule",{value:!0}),r);var ae={};W(ae,{defaultOptions:()=>x,firstWordRegEx:()=>v,fors:()=>w,forsRegEx:()=>O,ofRegEx:()=>N,ofs:()=>k,parseIngredient:()=>se,rangeSeparatorRegEx:()=>b,rangeSeparatorWords:()=>L,unitsOfMeasure:()=>_});var T=Object.defineProperty,C=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,X=(r,t,e)=>t in r?T(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,E=(r,t)=>{for(var e in t||(t={}))B.call(t,e)&&X(r,e,t[e]);if(C)for(var e of C(t))G.call(t,e)&&X(r,e,t[e]);return r},D={"\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/"},H=/^(?=-?\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)?)?$/,Q=/^(?=-?\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\/].*)?/,J=new RegExp(`(${Object.keys(D).join("|")})`),I={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},V={"\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"},K=new RegExp(`(${Object.keys(V).join("|")})`,"gi"),Y=/^(?=[MDCLXVI])(M{0,3})(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/i,y={round:3,allowTrailingInvalid:!1,romanNumerals:!1},Z=r=>{var t,e,u,l;let d=`${r}`.replace(K,(a,n)=>V[n]).toUpperCase(),c=Y.exec(d);if(!c)return NaN;let[,s,g,m,o]=c;return((t=I[s])!=null?t:0)+((e=I[g])!=null?e:0)+((u=I[m])!=null?u:0)+((l=I[o])!=null?l:0)},ee=/^\s*\//,f=(r,t=y)=>{if(typeof r=="number"||typeof r=="bigint")return r;let e=NaN,u=`${r}`.replace(J,(n,i)=>` ${D[i]}`).replace("\u2044","/").trim();if(u.length===0)return NaN;let l=E(E({},y),t),d=(l.allowTrailingInvalid?Q:H).exec(u);if(!d)return l.romanNumerals?Z(u):NaN;let[,c,s,g]=d,m=s.replace(/[,_]/g,""),o=g?.replace(/[,_]/g,"");if(!m&&o&&o.startsWith(".")?e=0:e=parseInt(m),!o)return c?e*-1:e;let a=l.round===!1?NaN:parseFloat(`1e${Math.floor(Math.max(0,l.round))}`);if(o.startsWith(".")||o.startsWith("e")||o.startsWith("E")){let n=parseFloat(`${e}${o}`);e=isNaN(a)?n:Math.round(n*a)/a}else if(ee.test(o)){let n=parseInt(m),i=parseInt(o.replace("/",""));e=isNaN(a)?n/i:Math.round(n*a/i)/a}else{let n=o.split("/"),[i,p]=n.map(h=>parseInt(h));e+=isNaN(a)?i/p:Math.round(i*a/p)/a}return c?e*-1:e};var x={additionalUOMs:{},allowLeadingOf:!1,normalizeUOM:!1},w=["For"],O=new RegExp(`^(?:${w.join("|")})\\s`,"i"),L=["or","to"],b=new RegExp(`^(-|\u2013|\u2014|(?:${L.join("|")})\\s)`,"i"),v=/^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/,k=["of"],N=new RegExp(`^(?:${k.join("|")})\\s+`,"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 q=r=>{let t=-1,e=r.length,u=0,l=[];for(;++t<e;){let d=r[t].trim();d&&(l[u++]=d)}return l};var te=/\r?\n/,re=([r,t])=>({id:r,...t}),se=(r,t=x)=>{let e={...x,...t},u={..._,...e.additionalUOMs},l=Object.entries(u).map(re),d=l.length;return q(r.split(te)).map(c=>{let s={quantity:null,quantity2:null,unitOfMeasureID:null,unitOfMeasure:null,description:"",isGroupHeader:!1},g=f(c.substring(0,1));if(isNaN(g))s.description=c,(s.description.endsWith(":")||O.test(s.description))&&(s.isGroupHeader=!0);else{let a=6,n=NaN;for(;a>0&&isNaN(n);)n=f(c.substring(0,a).trim()),n>-1&&(s.quantity=n,s.description=c.substring(a).trim()),a--}let m=b.exec(s.description);if(m){let a=m[1].length,n=f(s.description.substring(a).trim()[0]);if(!isNaN(n)){let i=7,p=NaN;for(;--i>0&&isNaN(p);)p=f(s.description.substring(a,i)),isNaN(p)||(s.quantity2=p,s.description=s.description.substring(i).trim())}}let o=v.exec(s.description);if(o){let a=o[1].replace(/\s+/g," "),n=(o[2]??"").trim();if(n){let i="",p="",h=-1;for(;++h<d&&!i;){let{alternates:U,id:R,short:$,plural:z}=l[h];[...U,R,$,z].includes(a)&&(i=a,p=R)}i&&(s.unitOfMeasureID=p,s.unitOfMeasure=e.normalizeUOM?p:i,s.description=n)}}return!e.allowLeadingOf&&s.description.match(N)&&(s.description=s.description.replace(N,"")),s})};return S(ae);})();
//# sourceMappingURL=parse-ingredient.umd.min.js.map
{
"name": "parse-ingredient",
"author": "Jake Boone",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",

@@ -47,15 +47,15 @@ "description": "Recipe ingredient parser with support for mixed numbers and vulgar fractions",

"publish:npm": "np",
"publish:demo": "node gh-pages.publish.js"
"publish:demo": "bun ./gh-pages.publish.js"
},
"devDependencies": {
"@types/jest": "^29.5.2",
"bun-types": "^0.6.9",
"@types/jest": "^29.5.3",
"bun-types": "^0.7.0",
"gh-pages": "^5.0.0",
"jest": "^29.5.0",
"jest": "^29.6.1",
"np": "^8.0.4",
"open": "^9.1.0",
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"tsup": "^7.0.0",
"typescript": "^5.1.3"
"prettier": "^3.0.0",
"ts-jest": "^29.1.1",
"tsup": "^7.1.0",
"typescript": "^5.1.6"
},

@@ -62,0 +62,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc