Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@shootismoke/convert

shootismoke128GPL-3.00.10.0TypeScript support: included

Easily convert between AQIs (US, CN...) and raw values (ug/m3, ppm)

readme

npm (scoped) dependencies Status Maintainability Test Coverage

@shootismoke/convert

A library to convert between various Air Quality Indexes (US, CN...) and their equivalent in pollutant concentration (µg/m³, ppm, ppb).

Supported Air Quality Indexes

AQI AQI Code1 Pollutants Resources
AQI (US) usaEpa co, no2, o3, pm10, pm25, so2 US Environmental Protection Agency (EPA) [link]
AQI (CN) chnMep co, no2, o3, pm10, pm25, so2 China Ministry of Environmental Protection (MEP) [link]

We also plan to support other AQIs in the future, see issue #15 if you want to help.

1: We use the same AQI code as Breezometer, the only difference is that the code here is camelCase, because JavaScript likes camelCase.

⚡ Get Started

Install the package:

yarn install @shootismoke/convert

The package mainly exports the convert function.

convert(pollutant, from, to, value)

The function can convert, for any pollutant:

  • from a raw concentration to a supported AQI
  • from a supported AQI to a raw concentration
  • from a supported AQI to another AQI

Arguments:

  • pollutant: Pollutant: One of the supported pollutants, see them.
  • from: AqiCode | 'raw': An AQI code or the 'raw' string
  • to: AqiCode | 'raw': An AQI code or the 'raw' string
  • value: number: The value to convert
import { convert, getPollutantMeta } from '@shootismoke/convert';

// Convert PM2.5 from usaEpa AQI to raw concentration
const raw = convert('pm25', 'usaEpa', 'raw', 57);
console.log(raw); // 15

console.log(getPollutantMeta('pm25').preferredUnit); // "µg/m³", which is the unit of the value 15 above

// Convert PM2.5 from raw concentration to usaEPA AQI
const aqi = convert('pm25', 'raw', 'usaEpa', 15);
console.log(aqi); // 57

Supported Pollutants

The pollutants the AQIs apply to are: 'bc' | 'co' | 'c6h6' | 'ox' | 'nh3' | 'nmhc' | 'no' | 'nox' | 'no2' | 'o3' | 'pm10' | 'pm25' | 'so2' | 'trs'. Check this file to see the metadata for each pollutant (full name, unit...).

Full Documentation

See the API reference documentation.

:raising_hand: Contribute

  1. Fork the repo
  2. Make your changes in your own fork
  3. Make sure yarn lint and yarn test pass
  4. Create a Pull Request on this repo

Tests

Look out for *.spec.ts in the codebase. Run:

yarn test

:newspaper: License

GPL-3.0. See LICENSE file for more information.

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

0.10.0 (2023-02-18)

  • refactor!: Remove fp-ts (#729) (ce170c2), closes #729

BREAKING CHANGES

  • Usage of fp-ts has been removed across all packaged. Functions that used to return a TaskEither now return a simple Promise.

0.9.1 (2022-10-03)

Note: Version bump only for package @shootismoke/common

0.9.0 (2022-10-03)

  • feat(ui)!: Remove usage of Algolia, use geoapify instead (#669) (a593a9f), closes #669

BREAKING CHANGES

0.8.10 (2021-08-17)

Bug Fixes

  • Fix british columbia type from AQICN (#519) (06bf7a8)

0.8.9 (2021-03-06)

Features

  • convert: Add all parameters from OpenAQ v2 (#432) (89e9e59)

0.8.8 (2021-03-06)

Bug Fixes

0.8.7 (2021-03-01)

Bug Fixes

0.8.6 (2021-02-28)

Bug Fixes

  • ui: Update Algolia return type validation (#424) (efb8263)

0.8.5 (2021-02-28)

Bug Fixes

  • ui: Rename fetchStation to fetchStationId (#423) (8649044)

0.8.4 (2021-02-28)

Bug Fixes

  • Fix getSortedOpenAQResults function (8186c9f)

0.8.3 (2021-02-28)

Bug Fixes

0.8.2 (2021-02-27)

Bug Fixes

  • Add some exports, remove react-native stuff from default exports (#421) (9b6fec1)

0.8.1 (2021-02-27)

Note: Version bump only for package @shootismoke/common

0.8.0 (2021-02-27)

Features

BREAKING CHANGES

  • The OpenAQFormat type has been renamed to OpenAQResult, and follows the v2 schema.

0.7.2 (2021-02-24)

Bug Fixes

0.7.1 (2021-02-23)

Bug Fixes

0.7.0 (2021-02-23)

Features

0.6.4 (2021-01-14)

Bug Fixes

  • Rename raw to ugm3 in convert, better UI utils (#387) (39d499b)

0.6.3 (2021-01-12)

Bug Fixes

0.6.2 (2020-10-31)

Features

0.6.1 (2020-10-22)

Bug Fixes

0.6.0 (2020-10-22)

Bug Fixes

  • ui: Remove CigarettesBlock, CigarettesText and ConversionBox (#313) (6631fae)
  • ui: Remove measurements with negative value (#327) (8ed2f95)

BREAKING CHANGES

  • ui: The component CigarettesBlock, CigarettesText and ConversionBox have been removed from the ui package.

0.5.7 (2020-10-18)

Bug Fixes

0.5.6 (2020-10-18)

Bug Fixes

0.5.5 (2020-10-17)

Bug Fixes

  • ui: Filter out old data in Normalized (#319) (385fac3)

0.5.4 (2020-10-16)

Bug Fixes

0.5.3 (2020-10-16)

Bug Fixes

  • ui: Difference in hours absolute should be smaller than 6 (#317) (f09b36f)

0.5.2 (2020-10-16)

Bug Fixes

  • ui: raceApiPromise only return recent results (#316) (1176a83)

0.5.1 (2020-10-15)

Note: Version bump only for package @shootismoke/common

0.5.0 (2020-10-15)

Features

BREAKING CHANGES

  • isStationToFar and distanceToStation now take a PM2.5 measurement OpenAQFormat object, instead of the Api object.

0.4.0 (2020-10-13)

Bug Fixes

  • ui: Allow aqicn & openaq options in race (#314) (6226962)

BREAKING CHANGES

  • ui: The raceApiPromise function's 2nd argument, RaceApiOptions, now is an object with 2 optional fields: aqicn and openaq, where each field represents the options to pass down to the respective dataprovider.

0.3.1 (2020-10-11)

Features

0.3.0 (2020-10-10)

Features

0.2.32 (2020-10-04)

Features

0.2.30 (2020-06-09)

Bug Fixes

  • ui: Fix styles TS typings (baa7021)

0.2.29 (2020-06-09)

Bug Fixes

0.2.28 (2020-06-05)

Note: Version bump only for package @shootismoke/common

0.2.27 (2020-06-05)

Features

  • Add functions to ui, fix fetchByGps in dataproviders (#183) (6678714)

0.2.26 (2020-06-03)

Bug Fixes

Features

0.2.25 (2020-06-02)

Bug Fixes

0.2.24 (2020-06-02)

Features

0.2.23 (2020-03-21)

Bug Fixes

  • dataproviders: Sanitize aqicn response delhi to india (#123) (9f23ec7)

0.2.22 (2020-03-21)

Bug Fixes

  • dataproviders: Handle case with empty response (#122) (d6f891a)

0.2.21 (2020-03-19)

Bug Fixes

0.2.20 (2020-03-19)

Bug Fixes

0.2.19 (2020-03-16)

Bug Fixes

  • graphql: Generate types for latest backend (#119) (c8d18c8)

0.2.18 (2020-02-17)

Bug Fixes

  • graphql: Add getOrCreateUser mutation (#101) (b14ecaa)

0.2.17 (2020-02-16)

Bug Fixes

  • dataproviders: Correct universalId for aqicn (#95) (d712991)

0.2.16 (2020-02-15)

Bug Fixes

  • graphql: Add _id on notifications (1359933)

0.2.15 (2020-02-15)

Bug Fixes

  • dataproviders: Better error msg when 0 result (#94) (84934f4)

0.2.14 (2020-02-14)

Bug Fixes

  • graphql: Add getUser query schema (#92) (43caae8)

0.2.13 (2020-02-12)

Bug Fixes

  • graphql: New graphql schema, with universalId (#91) (a981807)
  • graphql: Update to latest graphql with timezone (#90) (eeff991)

0.2.11 (2020-02-09)

Bug Fixes

  • graphql: Update to latest graphql schema (#89) (b8b8568)

0.2.10 (2020-02-07)

Bug Fixes

  • graphql: Update to latest schema with station (#88) (92b4b05)

0.2.9 (2020-02-07)

Bug Fixes

  • dataproviders: Add better error messages for openaq (#70) (bced690)
  • graphql: Update to latest graphql schema (#81) (6e054f8)

0.2.8 (2020-01-28)

Bug Fixes

  • dataproviders: Add correct options to openaq fetch (#69) (e2589eb)

0.2.7 (2020-01-20)

Bug Fixes

  • convert: Correct Conversion of o3 (#49) (3dc9877)
  • dataproviders: Correct Pollutant Names when Normalizing Data (#50) (14c3aea)

0.2.6 (2020-01-05)

Bug Fixes

  • Export All{Providers, Pollutants, Units} (#31) (12a061b)

0.2.5 (2020-01-05)

Bug Fixes

  • convert: Export AllUnits from convert (#26) (31d787d)
  • dataproviders: Make country always return the ISO 2-letter code (#28) (06dfa19)
  • graphql: Add @convert dependency (#30) (2575fa2)
  • graphql: Re-export graphql schemas as frontend need them (#27) (64dfd6c)

0.2.4 (2020-01-04)

Note: Version bump only for package @shootismoke/common

0.2.3 (2019-12-25)

Bug Fixes

  • dataproviders: Fix dates for aqicn and waqi (#21) (48f54d6)

0.2.2 (2019-12-25)

Note: Version bump only for package @shootismoke/common

0.2.1 (2019-12-25)

Features

  • dataproviders: Add getStationName and dominantPol functions (#20) (66c4ba2)

0.2.0 (2019-12-22)

chore

  • Move all packages from backend to common (734732e)

Code Refactoring

  • convert: Move aqi to convert package (#13) (e6cbf0b)
  • dataproviders: Use Open AQ format (#17) (9363a95)

Features

  • convert: Add breakpoints for co,no2,so2,pm10,o3 for EPA and MEP (#18) (5e67d25)

BREAKING CHANGES

  • dataproviders: All data provider fetches return normalized results using the openaq-data-format
  • convert: The @shootismoke/aqi package has been renamed to @shootismoke/convert
  • @shootismoke/aqi, @shootismoke/dataproviders and @shootismoke/graphql have been moved from https://github.com/shootismoke/backend to this repo

0.1.17 (2019-11-16)

Bug Fixes

  • dataproviders: Use axios instead of fetch (#37) (ff09a2d)
  • microservices: Make graphql endpoint work again (#36) (ba144b7)

0.1.16 (2019-11-16)

Bug Fixes

  • dataproviders: Remove useless dependency (#35) (d2a0dd4)

0.1.15 (2019-11-16)

Bug Fixes

0.1.14 (2019-11-14)

Bug Fixes

0.1.13 (2019-11-14)

Bug Fixes

0.1.12 (2019-11-14)

Bug Fixes

  • dataproviders: Add dominant pollutant (#30) (f645ed6)

0.1.11 (2019-11-14)

Bug Fixes

  • dataproviders: Change normalized format (#29) (e8f50a5)

0.1.10 (2019-11-13)

Bug Fixes

  • dataproviders: Add conversion to cigarettes (#27) (af577be)
  • dataproviders: Export types (#26) (27c3165)

0.1.9 (2019-11-13)

Note: Version bump only for package @shootismoke/backend

0.1.8 (2019-11-13)

Features

  • dataproviders: Add normalized data format (#25) (a7bd857)

0.1.7 (2019-11-12)

Bug Fixes

  • dataproviders: Add fetching from waqi (#24) (a17f3f4)
  • microservices: Use sparse index on expoPushToken (#23) (93cca0a)

0.1.6 (2019-11-10)

Note: Version bump only for package @shootismoke/backend

0.1.5 (2019-11-02)

Bug Fixes

  • graphql: Use type instead of enum (#21) (7836a63)

0.1.4 (2019-11-02)

Bug Fixes

  • graphql: Remove dependency from apollo-server (#19) (3dbfa45)
  • Fix license in package.json (82a9705)

0.1.3 (2019-11-02)

Bug Fixes

  • graphql: Fix graphql index export (#18) (05143cc)

0.1.2 (2019-11-02)

Note: Version bump only for package @shootismoke/backend

0.1.1 (2019-11-02)

Bug Fixes

Features