Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openfoodfac-ts

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openfoodfac-ts

[Open Food Facts](https://world.openfoodfacts.org/) Api written in TypeScript 🥫🍕🍼

  • 0.3.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
60
increased by39.53%
Maintainers
1
Weekly downloads
 
Created
Source

openfoodfac-ts

Open Food Facts Api written in TypeScript 🥫🍕🍼

Node CI

Features 🚀

  • Complete TypeScript support with type-safe responses 💪
  • Clean API ✨
  • Mock testing ready ✔

Getting started 🐾

Installation 💿

npm i openfoodfac-ts

Usage 🛠️

import { OpenFoodFactsApi } from 'openfoodfac-ts';

const openFoodFactsApi = new OpenFoodFactsApi();

const product = await openFoodFactsApi.findProductByBarcode('58918274712');

const countries = await openFoodFactsApi.findCountries();

Usage with config 🛠️

import { OpenFoodFactsApi } from 'openfoodfac-ts';

const openFoodFactsApi = new OpenFoodFactsApi({
  /**
   * Country id.
   * List of countries https://world.openfoodfacts.org/countries.
   * @default 'world'
   */
  country: 'pl'
  /**
   * User Agent used while requesting the API.
   */
  userAgent: 'Mozilla/5.0 ...'
  /**
   * AbortController instance used while requesting the API.
   * Allows you to cancel request at any time.
   */
  abortController: new AbortController()
});

const products = await openFoodFactsApi.findProductsByCategory('vegetables');

Setting abort controller dynamically

const abortController = new AbortController();

const tomatoeProducts = await openFoodFactsApi
  .setAbortController(abortController)
  .findProductsBySearchTerm('Tomatoes');

API 🗺

class OpenFoodFactsApi {

    findProductByBarcode(barcode: string): Promise<ApiTypes.Product | null>;
    
    findProductsBySearchTerm(searchTerm: string, page?: number): Promise<ApiTypes.ProductsResponse>;
    
    findProductsByBrand(brandName: string, page?: number): Promise<ApiTypes.ProductsResponse>;
    
    findProductsByCategory(category: string, page?: number): Promise<ApiTypes.ProductsResponse>;
    
    findCategories(): Promise<ApiTypes.TagsResponse>;
    
    findCountries(): Promise<ApiTypes.TagsResponse>;
    
    findIngredients(): Promise<ApiTypes.TagsResponse>;
    
    findPackagings(): Promise<ApiTypes.TagsResponse>;
    
    findPackagingCodes(): Promise<ApiTypes.TagsResponse>;
    
    findPurchasePlaces(): Promise<ApiTypes.TagsResponse>;
    
    findStates(): Promise<ApiTypes.TagsResponse>;
    
    findTraces(): Promise<ApiTypes.TagsResponse>;
    
    findEntryDates(): Promise<ApiTypes.TagsResponse>;
    
    findAllergens(): Promise<ApiTypes.TagsResponse>;
    
    findAdditives(): Promise<ApiTypes.TagsResponse>;
    
    findLanguages(): Promise<ApiTypes.TagsResponse>;
    
    findBrands(): Promise<ApiTypes.TagsResponse>;
    
    setController(abortController?: AbortController): this;

    setUserAgent(userAgent?: string): this;
    
}

Testing 🧰

Usage with Jest

There is a mock version available that uses mocked json response instead of making real API calls.

To make jest use mocked version, paste below code in your jest.setup.* file.

jest.mock('openfoodfac-ts/OpenFoodFactsApi');

License ⚖️

MIT

FAQs

Package last updated on 07 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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