New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mediavine/recipe-ingredient-parser

Package Overview
Dependencies
Maintainers
8
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mediavine/recipe-ingredient-parser - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

testDist/src/convert.d.ts

57

lib/convert.js

@@ -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

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