Created
October 16, 2019 14:44
-
-
Save turingmachine/2f2438d239c9c63d5d38e29a70e28501 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const transformFoodDeclarations = apiFoodDeclaration => { | |
const boldTextRegex = /\$([^\$]+)\$/g | |
const producing_country = | |
_.get(apiFoodDeclaration, 'producing_country', null) === '-' | |
? null | |
: _.replace( | |
_.get(apiFoodDeclaration, 'producing_country', null), | |
'DE: ', | |
'' | |
) | |
const shelf_producing_country = _.get( | |
apiFoodDeclaration, | |
'shelf_data.gmaa.producing_country', | |
null | |
) | |
try { | |
return { | |
description: _.get( | |
apiFoodDeclaration, | |
'regulated_description', | |
'' | |
).replace(boldTextRegex, '<strong>$1</strong>'), | |
origin: _.replace(_.get(apiFoodDeclaration, 'orign', null), 'DE: ', ''), | |
producing_country: | |
shelf_producing_country !== 'Herkunft siehe Verpackung' | |
? shelf_producing_country | |
: producing_country, | |
ingredients: striptags(_.get(apiFoodDeclaration, 'ingredients', null)), | |
allergens: _.replace( | |
_.get(apiFoodDeclaration, 'allergen_text', null), | |
'DE: ', | |
'' | |
), | |
nutrients: transformNutrients( | |
_.get(apiFoodDeclaration, 'nutrition_facts.standard', null) | |
), | |
generalInformation: _.get(apiFoodDeclaration, 'general_information', []) | |
.map(info => { | |
return { | |
title: info.label, | |
text: _.replace(info.value, 'DE: ', ''), | |
} | |
}) | |
.filter(generalInformation => { | |
return _.every([ | |
generalInformation.title !== 'Auslobung', | |
generalInformation.title !== 'Haltbarkeit', | |
generalInformation.title !== 'Text Datierung', | |
generalInformation.text !== '-', | |
]) | |
}), | |
} | |
} catch (error) { | |
console.log(error) | |
Raven.captureException(error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment