@shootismoke/aqi

Easily convert between US AQI, CN AQI and raw concentrations in ug/m3

Usage no npm install needed!

<script type="module">
  import shootismokeAqi from 'https://cdn.skypack.dev/@shootismoke/aqi';
</script>

README

npm (scoped) dependencies Status

@shootismoke/aqi

A library to convert between AQI (US or CN) value and pollutant concentration (µg/m³ or ppm) using the following standards:

  • US AQI: United States Environmental Protection Agency (EPA)
  • CN AQI: China Ministry of Environmental Protection (MEP)

⚡ Get Started

Install the package

yarn install @shootismoke/aqi

aqiToRaw(pollutant: Pollutant, aqi: number, aqiType: AqiType = 'US'): number

Converts an AQI value to raw concentration (µg/m³ or ppm).

Arguments:

  • pollutant: Pollutant: One of 'co' | 'h' | 'no2' | 'o3' | 'p' | 'pm10' | 'pm25' | 'so2' | 't' | 'w'
  • aqi: number: The AQI value
  • aqiType: AqiType: One of 'US' | 'CN'
import { aqiToRaw } from '@shootismoke/aqi';

const raw = aqiToRaw('pm25', 57, 'US');
console.log(raw); // 15

aqiToRaw(pollutant: Pollutant, raw: number, aqiType: AqiType = 'US'): number

Converts a raw concentration (µg/m³ or ppm) to AQI value.

Arguments:

  • pollutant: Pollutant: One of 'co' | 'h' | 'no2' | 'o3' | 'p' | 'pm10' | 'pm25' | 'so2' | 't' | 'w'
  • raw: number: The raw concentration
  • aqiType: AqiType: One of 'US' | 'CN'
import { rawToAqi } from '@shootismoke/aqi';

const aqi = aqiToRaw('pm25', 15, 'US');
console.log(aqi); // 57

getUnit(pollutant: Pollutant): Unit

Gets the unit of a pollutant (µg/m³ or ppm).

Arguments:

  • pollutant: Pollutant: One of 'co' | 'h' | 'no2' | 'o3' | 'p' | 'pm10' | 'pm25' | 'so2' | 't' | 'w'
import { getUnit } from '@shootismoke/aqi';

const unit = getUnit('pm25');
console.log(unit); // 'µg/m³'

:raising_hand: Contribute

  1. Fork the repo
  2. Make your changes in your own fork
  3. Create a Pull Request on this repo

:microscope: Tests

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

yarn test

:books: Resources

:newspaper: License

GPL-3.0. See LICENSE file for more information.