aqi-calc
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

AQI Calc

Easily convert pollutant measurements into AQI values per the EPA's blue scale. For additional references on how AQI is calculated see the thoughtful documentation on Wikipedia for Computing the AQI. Also, for a complete reference on all of the official break points view the official EPA AQI Breakpoints page.

Usage

import { AQSample, calculateAQI, Substance, TemperatureScale, Unit } from "aqi-calc"

const sample: AQSample = {
  substance: Substance.Ozone,
  unit: Unit.PPM,
  value: 0.055,
  temperature:{
    value: 25,
    scale: TemperatureScale.Celcius
  },
  interval: "8H"
}

console.log(calculateAQI(sample)) 
// => {aqi: 51, description: "Moderate", hexColor: "#ff0"}

Defining an Air Quality Sample:

To convert a reading simply provide the input amount, the substance, and the unit the input amount represents. See the types below for supported values:

enum Substance {
  CarbonMonoxide = "CO",
  NitrousDioxide = "NO2",
  Ozone = "O3",
  SulfurDioxide = "SO2",
  FineParticles = "PM2_5",
  CoarseParticles = "PM10"
}

enum Unit {
  PPM = "PPM",
  PPB = "PPB",
  UG_M3 = "ug/m3"
}

enum Interval {
  OneHour = "1H",
  EightHour = "8H",
  Day = "24H"
}

interface ISample = {
  substance: Substance,
  interval: Interval,
  amount: number,
  unit: Unit,
  temperature?: ITemperature
}

Defining the Temperature:

The ambient temperature where the reading occured affects the air density and thus the AQI calculations. If you do not know the temperature a default environment assuming 25C will be used during any conversions.

enum TemperatureScale {
  Farhenheit = "F",
  Celcius = "C"
}

interface ITemperature = {
  value: number,
  scale: TemperatureScale
}

Result Output:

The ouput of the calculateAQI method is returned as an AQIResult type which defines the resulting AQI along with the corresponding description and hex color for the matching break point:

enum AirQualityDescription {
  Good = "Good",
  Moderate = "Moderate",
  Sensitive = "Unhealthy For Sensitive",
  Unhealthy = "Unhealthy",
  VeryUnhealthy = "Very Unhealthy",
  Hazardous = "Hazardous",
  None = "NONE"
}

type AQIResult = {
  aqi: number,
  description: AirQualityDescription,
  hexColor: string
}

Readme

Keywords

none

Package Sidebar

Install

npm i aqi-calc

Weekly Downloads

1

Version

1.2.1

License

MIT

Unpacked Size

35.2 kB

Total Files

19

Last publish

Collaborators

  • jimjeffers