The goal of the project is to provide simple library that can calculate the Nutri-Score.
The Nutri-Score is a nutrition label that converts the nutritional value of products into a simple code consisting of 5 letters, each with its own colour.
Each product is awarded a score based on a scientific algorithm.
This formula takes into account the nutrients to avoid (energy value and the amount of sugars, saturated fats and salt) and the positive ones (the amount of fibre, protein, fruit, vegetables and nuts).
You can therefore see at a glance which products are recommended and which should be avoided.
Source: https://nutriscore.colruytgroup.com/colruytgroup/en/about-nutri-score/
Paper: https://pdfs.semanticscholar.org/3d1c/c206bc286bb5f80452821a0d26ff9e55b387.pdf
<script src="https://cdn.jsdelivr.net/npm/nutri-score/nutriScore.js"></script>
or
yarn add nutri-score
or
npm install nutri-score --save
import { nutriScore } from "nutri-score";
const result = nutriScore.calculateClass({
energy: 0,
fibers: 4,
fruit_percentage: 60,
proteins: 2,
saturated_fats: 2,
sodium: 500,
sugar: 10
});
console.log(result); // Output: "B"
For more methods & usage refer to the documentation bellow
Note: TypeScript definition are included in the project
... Work in progress ...
Feel free to add suggestions, PRs, comments and bug reports.
Alex Kolarski ([email protected])
(The MIT License)
Copyright (c) 2019
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.