@mediavine/recipe-ingredient-parser
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -32,26 +32,27 @@ "use strict"; | ||
exports.getAllMatches = getAllMatches; | ||
// const unicodeObj: { [key: string]: string } = { | ||
// '¼': '1/4', | ||
// '½': '1/2', | ||
// '¾': '3/4', | ||
// '⅐': '1/7', | ||
// '⅑': '1/9', | ||
// '⅒': '1/10', | ||
// '⅓': '1/3', | ||
// '⅔': '2/3', | ||
// '⅕': '1/5', | ||
// '⅖': '2/5', | ||
// '⅗': '3/5', | ||
// '⅘': '4/5', | ||
// '⅙': '1/6', | ||
// '⅚': '5/6', | ||
// '⅛': '1/8', | ||
// '⅜': '3/8', | ||
// '⅝': '5/8', | ||
// '⅞': '7/8' | ||
// }; | ||
var unicodeObj = { | ||
'¼': '1/4', | ||
'½': '1/2', | ||
'¾': '3/4', | ||
'⅐': '1/7', | ||
'⅑': '1/9', | ||
'⅒': '1/10', | ||
'⅓': '1/3', | ||
'⅔': '2/3', | ||
'⅕': '1/5', | ||
'⅖': '2/5', | ||
'⅗': '3/5', | ||
'⅘': '4/5', | ||
'⅙': '1/6', | ||
'⅚': '5/6', | ||
'⅛': '1/8', | ||
'⅜': '3/8', | ||
'⅝': '5/8', | ||
'⅞': '7/8' | ||
}; | ||
function findQuantityAndConvertIfUnicode(ingredientLine) { | ||
var rangeRegex = /^(\d+)\s?[-–]\s?(\d+)/g; | ||
var numericAndFractionRegex = /^(\d+\/\d+)|(\d+\s\d+\/\d+)|(\d+\-\d+)|(\d+.\d+)|\d+/g; | ||
// const unicodeFractionRegex = /\d*[^\u0000-\u007F]+/g; | ||
var unicodeFractionRegex = /\d*[^\u0000-\u007F]+/g; | ||
var onlyUnicodeFraction = /[^\u0000-\u007F]+/g; | ||
if (ingredientLine.match(rangeRegex)) { | ||
@@ -61,9 +62,9 @@ var rangeParts = getAllMatches(ingredientLine, rangeRegex); | ||
} | ||
// if (ingredientLine.match(unicodeFractionRegex)) { | ||
// const numericPart = getFirstMatch(ingredientLine, numericAndFractionRegex); | ||
// const unicodePart = getFirstMatch(ingredientLine, numericPart ? onlyUnicodeFraction : unicodeFractionRegex); | ||
// if (unicodeObj[unicodePart]) { | ||
// return [`${numericPart} ${unicodeObj[unicodePart]}`, ingredientLine.replace(getFirstMatch(ingredientLine, unicodeFractionRegex), '').trim()]; | ||
// } | ||
// } | ||
if (ingredientLine.match(unicodeFractionRegex)) { | ||
var numericPart = getFirstMatch(ingredientLine, numericAndFractionRegex); | ||
var unicodePart = getFirstMatch(ingredientLine, numericPart ? onlyUnicodeFraction : unicodeFractionRegex); | ||
if (unicodeObj[unicodePart]) { | ||
return [numericPart + " " + unicodeObj[unicodePart], ingredientLine.replace(getFirstMatch(ingredientLine, unicodeFractionRegex), '').trim()]; | ||
} | ||
} | ||
if (ingredientLine.match(numericAndFractionRegex)) { | ||
@@ -70,0 +71,0 @@ return [ingredientLine.match(numericAndFractionRegex) && getFirstMatch(ingredientLine, numericAndFractionRegex), ingredientLine.replace(getFirstMatch(ingredientLine, numericAndFractionRegex), '').trim()]; |
{ | ||
"name": "@mediavine/recipe-ingredient-parser", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Natural language parser for recipes and ingredient lists", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -28,22 +28,22 @@ export function convertFromFraction(value: string) { | ||
// const unicodeObj: { [key: string]: string } = { | ||
// '¼': '1/4', | ||
// '½': '1/2', | ||
// '¾': '3/4', | ||
// '⅐': '1/7', | ||
// '⅑': '1/9', | ||
// '⅒': '1/10', | ||
// '⅓': '1/3', | ||
// '⅔': '2/3', | ||
// '⅕': '1/5', | ||
// '⅖': '2/5', | ||
// '⅗': '3/5', | ||
// '⅘': '4/5', | ||
// '⅙': '1/6', | ||
// '⅚': '5/6', | ||
// '⅛': '1/8', | ||
// '⅜': '3/8', | ||
// '⅝': '5/8', | ||
// '⅞': '7/8' | ||
// }; | ||
const unicodeObj: { [key: string]: string } = { | ||
'¼': '1/4', | ||
'½': '1/2', | ||
'¾': '3/4', | ||
'⅐': '1/7', | ||
'⅑': '1/9', | ||
'⅒': '1/10', | ||
'⅓': '1/3', | ||
'⅔': '2/3', | ||
'⅕': '1/5', | ||
'⅖': '2/5', | ||
'⅗': '3/5', | ||
'⅘': '4/5', | ||
'⅙': '1/6', | ||
'⅚': '5/6', | ||
'⅛': '1/8', | ||
'⅜': '3/8', | ||
'⅝': '5/8', | ||
'⅞': '7/8' | ||
}; | ||
@@ -53,3 +53,5 @@ export function findQuantityAndConvertIfUnicode(ingredientLine: string) { | ||
const numericAndFractionRegex = /^(\d+\/\d+)|(\d+\s\d+\/\d+)|(\d+\-\d+)|(\d+.\d+)|\d+/g; | ||
// const unicodeFractionRegex = /\d*[^\u0000-\u007F]+/g; | ||
const unicodeFractionRegex = /\d*[^\u0000-\u007F]+/g; | ||
const onlyUnicodeFraction = /[^\u0000-\u007F]+/g; | ||
if(ingredientLine.match(rangeRegex)) { | ||
@@ -59,9 +61,9 @@ const rangeParts = getAllMatches(ingredientLine, rangeRegex) | ||
} | ||
// if (ingredientLine.match(unicodeFractionRegex)) { | ||
// const numericPart = getFirstMatch(ingredientLine, numericAndFractionRegex); | ||
// const unicodePart = getFirstMatch(ingredientLine, numericPart ? onlyUnicodeFraction : unicodeFractionRegex); | ||
// if (unicodeObj[unicodePart]) { | ||
// return [`${numericPart} ${unicodeObj[unicodePart]}`, ingredientLine.replace(getFirstMatch(ingredientLine, unicodeFractionRegex), '').trim()]; | ||
// } | ||
// } | ||
if (ingredientLine.match(unicodeFractionRegex)) { | ||
const numericPart = getFirstMatch(ingredientLine, numericAndFractionRegex); | ||
const unicodePart = getFirstMatch(ingredientLine, numericPart ? onlyUnicodeFraction : unicodeFractionRegex); | ||
if (unicodeObj[unicodePart]) { | ||
return [`${numericPart} ${unicodeObj[unicodePart]}`, ingredientLine.replace(getFirstMatch(ingredientLine, unicodeFractionRegex), '').trim()]; | ||
} | ||
} | ||
if (ingredientLine.match(numericAndFractionRegex)) { | ||
@@ -68,0 +70,0 @@ return [ingredientLine.match(numericAndFractionRegex) && getFirstMatch(ingredientLine, numericAndFractionRegex), ingredientLine.replace(getFirstMatch(ingredientLine, numericAndFractionRegex), '').trim()]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
79859
37
838