foo

foodweb

Easily access open source food and nutritional data from the USDA.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

10

Maintenance

Last Commit

4yrs ago

Contributors

1

Package

Dependencies

1

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

foodWeb

foodWeb is an open source project that makes it simple to access the USDA's Nutrient Standard Reference Database.

Installation

$ npm i -S foodweb
$ yarn add foodweb

Example

var foodWeb = require('foodweb');

var item = foodWeb.search('cheez it')[0];

// kilocalories in 100 grams
var calories = item.data.kcal;
// kilocalories in a serving
var serving = Math.round((item.data.primaryWeight / 100) * calories);
// description of serving
var servingDescription = item.data.primaryWeightDesc;

console.log(servingDescription, 'is', serving, 'calories');
// 29 crackers is 135 calories

Note: While foodWeb works best in Node.js, it is fully compatible with client packagers like webpack. See a demo here!

Methods

foodWeb.search(term, maxLength)

Search the pre-built index. For more advanced documentation (like using weighting or rough matches) read this documentation.

var foodWeb = require('foodweb');

var term = 'butter'; // the search term
var maxLength = 5; // the maximum number of items to return

foodWeb.search(term, maxLength);
/*
 [foodMatch {
     internal: {...},
     score: Number,
     data: foodItem {...}
 }, ...]
*/

Returns an array of foodMatch objects in descending relatedness.

Objects

foodWeb.internal

An instance from the internal search library used.

foodMatch.internal

A score and metadata from the internal search library used.

foodMatch.score

A fraction representing how close the search term was to the matched item.

foodMatch.data

A foodItem object containing all of the information about the item.

foodItem

This contains all of the information from the database including calories, nutrient makeup, and serving sizes. Read the full documentation here to learn more.

License

MIT (C) Russell Steadman. Learn more in the LICENSE file.

The source data is released by the USDA under a Creative Commons 4.0 Attributional License. The contents of the files were modified.

Support Me

Like this project? Buy me a cup of coffee. ☕ Here are more of my projects.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial