parse-ingredient
Advanced tools
Comparing version 1.0.1 to 1.1.0-beta.0
@@ -32,2 +32,3 @@ "use strict"; | ||
rangeSeparatorWords: () => rangeSeparatorWords, | ||
trailingQuantityRegEx: () => trailingQuantityRegEx, | ||
unitsOfMeasure: () => unitsOfMeasure | ||
@@ -38,5 +39,6 @@ }); | ||
// src/parseIngredient.ts | ||
var import_numeric_quantity = require("numeric-quantity"); | ||
var import_numeric_quantity2 = require("numeric-quantity"); | ||
// src/constants.ts | ||
var import_numeric_quantity = require("numeric-quantity"); | ||
var defaultOptions = { | ||
@@ -50,7 +52,10 @@ additionalUOMs: {}, | ||
var rangeSeparatorWords = ["or", "to"]; | ||
var rangeSeparatorRegEx = new RegExp( | ||
`^(-|\u2013|\u2014|(?:${rangeSeparatorWords.join("|")})\\s)`, | ||
var rangeSeparatorRegExSource = `(-|\u2013|\u2014|(?:${rangeSeparatorWords.join("|")})\\s)`; | ||
var rangeSeparatorRegEx = new RegExp(`^${rangeSeparatorRegExSource}`, "i"); | ||
var firstWordRegEx = /^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/; | ||
var numericRegexAnywhere = import_numeric_quantity.numericRegex.source.replace(/^\^/, "").replace(/\$$/, ""); | ||
var trailingQuantityRegEx = new RegExp( | ||
`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${numericRegexAnywhere})\\s*(${rangeSeparatorRegExSource}))?\\s*(${numericRegexAnywhere})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`, | ||
"i" | ||
); | ||
var firstWordRegEx = /^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/; | ||
var ofs = ["of"]; | ||
@@ -120,3 +125,3 @@ var ofRegEx = new RegExp(`^(?:${ofs.join("|")})\\s+`, "i"); | ||
var addIdToUomDefinition = ([uom, def]) => ({ id: uom, ...def }); | ||
var parseIngredient = (ingText, options = defaultOptions) => { | ||
var parseIngredient = (ingredientText, options = defaultOptions) => { | ||
const opts = { ...defaultOptions, ...options }; | ||
@@ -126,3 +131,3 @@ const mergedUOMs = { ...unitsOfMeasure, ...opts.additionalUOMs }; | ||
const uomArrayLength = uomArray.length; | ||
return compactStringArray(ingText.split(newLineRegExp)).map((line) => { | ||
return compactStringArray(ingredientText.split(newLineRegExp)).map((line) => { | ||
const oIng = { | ||
@@ -136,7 +141,38 @@ quantity: null, | ||
}; | ||
const nqResultFirstChar = (0, import_numeric_quantity.numericQuantity)(line.substring(0, 1)); | ||
const nqResultFirstChar = (0, import_numeric_quantity2.numericQuantity)(line.substring(0, 1)); | ||
if (isNaN(nqResultFirstChar)) { | ||
oIng.description = line; | ||
if (oIng.description.endsWith(":") || forsRegEx.test(oIng.description)) { | ||
oIng.isGroupHeader = true; | ||
const trailingQtyResult = trailingQuantityRegEx.exec(line); | ||
if (trailingQtyResult) { | ||
oIng.description = line.replace(trailingQuantityRegEx, "").trim(); | ||
const firstQty = trailingQtyResult[3]; | ||
const secondQty = trailingQtyResult[12]; | ||
if (!firstQty) { | ||
oIng.quantity = (0, import_numeric_quantity2.numericQuantity)(secondQty); | ||
} else { | ||
oIng.quantity = (0, import_numeric_quantity2.numericQuantity)(firstQty); | ||
oIng.quantity2 = (0, import_numeric_quantity2.numericQuantity)(secondQty); | ||
} | ||
const uomRaw = trailingQtyResult.at(-1); | ||
if (uomRaw) { | ||
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(uomRaw)) { | ||
uom = uomRaw; | ||
uomID = id; | ||
} | ||
} | ||
if (uom) { | ||
oIng.unitOfMeasureID = uomID; | ||
oIng.unitOfMeasure = opts.normalizeUOM ? uomID : uom; | ||
} | ||
} | ||
} else { | ||
oIng.description = line; | ||
if (oIng.description.endsWith(":") || forsRegEx.test(oIng.description)) { | ||
oIng.isGroupHeader = true; | ||
} | ||
} | ||
@@ -147,3 +183,3 @@ } else { | ||
while (lenNum > 0 && isNaN(nqResult)) { | ||
nqResult = (0, import_numeric_quantity.numericQuantity)(line.substring(0, lenNum).trim()); | ||
nqResult = (0, import_numeric_quantity2.numericQuantity)(line.substring(0, lenNum).trim()); | ||
if (nqResult > -1) { | ||
@@ -159,3 +195,3 @@ oIng.quantity = nqResult; | ||
const q2reMatchLen = q2reMatch[1].length; | ||
const nqResultFirstChar2 = (0, import_numeric_quantity.numericQuantity)(oIng.description.substring(q2reMatchLen).trim()[0]); | ||
const nqResultFirstChar2 = (0, import_numeric_quantity2.numericQuantity)(oIng.description.substring(q2reMatchLen).trim()[0]); | ||
if (!isNaN(nqResultFirstChar2)) { | ||
@@ -165,3 +201,3 @@ let lenNum = 7; | ||
while (--lenNum > 0 && isNaN(nqResult)) { | ||
nqResult = (0, import_numeric_quantity.numericQuantity)(oIng.description.substring(q2reMatchLen, lenNum)); | ||
nqResult = (0, import_numeric_quantity2.numericQuantity)(oIng.description.substring(q2reMatchLen, lenNum)); | ||
if (!isNaN(nqResult)) { | ||
@@ -214,4 +250,5 @@ oIng.quantity2 = nqResult; | ||
rangeSeparatorWords, | ||
trailingQuantityRegEx, | ||
unitsOfMeasure | ||
}); | ||
//# sourceMappingURL=parse-ingredient.cjs.development.js.map |
@@ -1,2 +0,2 @@ | ||
"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}); | ||
"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}); | ||
//# sourceMappingURL=parse-ingredient.cjs.production.js.map |
@@ -22,2 +22,3 @@ var __defProp = Object.defineProperty; | ||
// src/constants.ts | ||
import { numericRegex } from "numeric-quantity"; | ||
var defaultOptions = { | ||
@@ -31,7 +32,10 @@ additionalUOMs: {}, | ||
var rangeSeparatorWords = ["or", "to"]; | ||
var rangeSeparatorRegEx = new RegExp( | ||
`^(-|\u2013|\u2014|(?:${rangeSeparatorWords.join("|")})\\s)`, | ||
var rangeSeparatorRegExSource = `(-|\u2013|\u2014|(?:${rangeSeparatorWords.join("|")})\\s)`; | ||
var rangeSeparatorRegEx = new RegExp(`^${rangeSeparatorRegExSource}`, "i"); | ||
var firstWordRegEx = /^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/; | ||
var numericRegexAnywhere = numericRegex.source.replace(/^\^/, "").replace(/\$$/, ""); | ||
var trailingQuantityRegEx = new RegExp( | ||
`(,|:|-|\u2013|\u2014|x|\u2A2F)?\\s*((${numericRegexAnywhere})\\s*(${rangeSeparatorRegExSource}))?\\s*(${numericRegexAnywhere})\\s*(fl(?:uid)?(?:\\s+|-)(?:oz|ounces?)|\\w+)?$`, | ||
"i" | ||
); | ||
var firstWordRegEx = /^(fl(?:uid)?(?:\s+|-)(?:oz|ounces?)|\w+[-.]?)(.+)?/; | ||
var ofs = ["of"]; | ||
@@ -101,3 +105,3 @@ var ofRegEx = new RegExp(`^(?:${ofs.join("|")})\\s+`, "i"); | ||
var addIdToUomDefinition = ([uom, def]) => __spreadValues({ id: uom }, def); | ||
var parseIngredient = (ingText, options = defaultOptions) => { | ||
var parseIngredient = (ingredientText, options = defaultOptions) => { | ||
const opts = __spreadValues(__spreadValues({}, defaultOptions), options); | ||
@@ -107,3 +111,3 @@ const mergedUOMs = __spreadValues(__spreadValues({}, unitsOfMeasure), opts.additionalUOMs); | ||
const uomArrayLength = uomArray.length; | ||
return compactStringArray(ingText.split(newLineRegExp)).map((line) => { | ||
return compactStringArray(ingredientText.split(newLineRegExp)).map((line) => { | ||
var _a; | ||
@@ -120,5 +124,36 @@ const oIng = { | ||
if (isNaN(nqResultFirstChar)) { | ||
oIng.description = line; | ||
if (oIng.description.endsWith(":") || forsRegEx.test(oIng.description)) { | ||
oIng.isGroupHeader = true; | ||
const trailingQtyResult = trailingQuantityRegEx.exec(line); | ||
if (trailingQtyResult) { | ||
oIng.description = line.replace(trailingQuantityRegEx, "").trim(); | ||
const firstQty = trailingQtyResult[3]; | ||
const secondQty = trailingQtyResult[12]; | ||
if (!firstQty) { | ||
oIng.quantity = numericQuantity(secondQty); | ||
} else { | ||
oIng.quantity = numericQuantity(firstQty); | ||
oIng.quantity2 = numericQuantity(secondQty); | ||
} | ||
const uomRaw = trailingQtyResult.at(-1); | ||
if (uomRaw) { | ||
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(uomRaw)) { | ||
uom = uomRaw; | ||
uomID = id; | ||
} | ||
} | ||
if (uom) { | ||
oIng.unitOfMeasureID = uomID; | ||
oIng.unitOfMeasure = opts.normalizeUOM ? uomID : uom; | ||
} | ||
} | ||
} else { | ||
oIng.description = line; | ||
if (oIng.description.endsWith(":") || forsRegEx.test(oIng.description)) { | ||
oIng.isGroupHeader = true; | ||
} | ||
} | ||
@@ -192,4 +227,5 @@ } else { | ||
rangeSeparatorWords, | ||
trailingQuantityRegEx, | ||
unitsOfMeasure | ||
}; | ||
//# sourceMappingURL=parse-ingredient.legacy-esm.js.map |
@@ -1,2 +0,2 @@ | ||
"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);})(); | ||
"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);})(); | ||
//# sourceMappingURL=parse-ingredient.umd.min.js.map |
{ | ||
"name": "parse-ingredient", | ||
"author": "Jake Boone", | ||
"version": "1.0.1", | ||
"version": "1.1.0-beta.0", | ||
"license": "MIT", | ||
@@ -43,4 +43,5 @@ "description": "Recipe ingredient parser with support for mixed numbers and vulgar fractions", | ||
"build": "tsup", | ||
"test": "jest", | ||
"watch": "jest --watch", | ||
"docs": "bunx typedoc", | ||
"test": "bun test", | ||
"watch": "bun test --watch", | ||
"pretty-print": "prettier --write src *.{mjs,json,html,ts}", | ||
@@ -51,16 +52,14 @@ "publish:npm": "np", | ||
"devDependencies": { | ||
"@types/jest": "^29.5.3", | ||
"bun-types": "^0.7.0", | ||
"gh-pages": "^5.0.0", | ||
"jest": "^29.6.1", | ||
"@types/web": "^0.0.114", | ||
"bun-types": "^1.0.1", | ||
"np": "^8.0.4", | ||
"open": "^9.1.0", | ||
"prettier": "^3.0.0", | ||
"ts-jest": "^29.1.1", | ||
"tsup": "^7.1.0", | ||
"typescript": "^5.1.6" | ||
"prettier": "^3.0.3", | ||
"tsup": "^7.2.0", | ||
"typedoc": "^0.25.1", | ||
"typescript": "^5.2.2" | ||
}, | ||
"dependencies": { | ||
"numeric-quantity": "2.0.0" | ||
"numeric-quantity": "^2.0.0" | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
# parse-ingredient | ||
[![npm][badge-npm]](https://www.npmjs.com/package/parse-ingredient) | ||
@@ -10,4 +8,10 @@ ![workflow status](https://github.com/jakeboone02/parse-ingredient/actions/workflows/main.yml/badge.svg) | ||
Parses a string, which can include mixed numbers or vulgar fractions (thanks to [numeric-quantity](https://www.npmjs.com/package/numeric-quantity)), into an array of recipe ingredient objects with the following signature: | ||
Parses a string, which can include mixed numbers or vulgar fractions (thanks to [numeric-quantity](https://www.npmjs.com/package/numeric-quantity)), into an array of recipe ingredient objects. | ||
**[Full documentation](https://jakeboone02.github.io/parse-ingredient/)** | ||
**[Demo](https://jakeboone02.github.io/parse-ingredient-demo/)** | ||
Ingredient objects have the following signature: | ||
```ts | ||
@@ -44,20 +48,13 @@ interface Ingredient { | ||
For a complimentary library that handles the inverse operation, displaying numeric values as imperial measurements (e.g. `'1 1/2'` instead of `1.5`), see [format-quantity](https://www.npmjs.com/package/format-quantity). | ||
If present (i.e., not `null`), the `unitOfMeasureID` property corresponds to a key from the exported `unitsOfMeasure` object which defines short, plural, and other alternate versions of known units of measure. To extend the list of units, use the `additionalUOMs` option and/or or submit a [pull request](https://github.com/jakeboone02/parse-ingredient/pulls) to add new units to this library's default list. | ||
If present (i.e. not `null`), the `unitOfMeasureID` property corresponds to a key from the exported `unitsOfMeasure` object which defines short, plural, and other alternate versions of known units of measure. To extend the list of units, use the [`additionalUOMs` option](#additionaluoms) and/or or submit a [pull request](https://github.com/jakeboone02/parse-ingredient/pulls) to add new units to this library's default list. | ||
> For a complimentary library that handles the inverse operation, displaying numeric values as imperial measurements (e.g. `'1 1/2'` instead of `1.5`), see [format-quantity](https://www.npmjs.com/package/format-quantity). | ||
## Demo | ||
[See demo here](https://jakeboone02.github.io/parse-ingredient/). | ||
## Installation | ||
### npm/yarn | ||
### npm | ||
```shell | ||
# npm | ||
npm i parse-ingredient | ||
# yarn | ||
yarn add parse-ingredient | ||
# OR yarn add / pnpm add / bun add | ||
``` | ||
@@ -137,2 +134,13 @@ | ||
// ] | ||
console.log(parseIngredient('Ripe tomato x2')); | ||
// [ | ||
// { | ||
// quantity: 2, | ||
// quantity2: null, | ||
// unitOfMeasure: null, | ||
// unitOfMeasureID: null, | ||
// description: 'Ripe tomato', | ||
// isGroupHeader: false, | ||
// } | ||
// ] | ||
``` | ||
@@ -212,12 +220,2 @@ | ||
## Other exports | ||
| Name | Type | Description | | ||
| -------------------------- | ----------- | ------------------------------------------------------------------------------------- | | ||
| `unitsOfMeasure` | `object` | Information about natively-supported units of measure (see `UnitOfMeasure` interface) | | ||
| `ParseIngredientOptions` | `interface` | Shape of the second parameter to the `parseIngredient` function | | ||
| `Ingredient` | `interface` | Interface describing the shape of each element in the returned ingredient array | | ||
| `UnitOfMeasure` | `interface` | Interface including short, plural, and alternate forms of a unit of measure | | ||
| `UnitOfMeasureDefinitions` | `type` | Object with keys representing a `unitOfMeasureID` and values of type `UnitOfMeasure` | | ||
## Contributors ✨ | ||
@@ -224,0 +222,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
187463
8
740
2
247
+ Addednumeric-quantity@2.0.1(transitive)
- Removednumeric-quantity@2.0.0(transitive)
Updatednumeric-quantity@^2.0.0