npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

weather-formulas

v1.0.9

Published

A collection of atmospheric, meteorological weather calculations

Readme

weather-formulas

A library of atmospheric and weather-related formulas.

import { temperature } from 'weather-formulas';
const dewPoint = temperature.dewPointMagnusFormula(298.15, 60);
console.log(`Dew Point: ${dewPoint} K`);
  • Test code for all formulas.
  • Supports provided and custom valuation sets, and configurable parameters where applicable.
  • Supports both ES Module (ESM) and CommonJS (CJS).

Table of Contents

Features

Air Density

| Formula | Description | |---------------------------|-----------------------------------------------------------------------------| | Dry Air Density | Calculate air density for dry air. 🔗 | | Moist Air Density | Calculate air density for moist air, considering humidity. 🔗 | | Air Density at Altitude | Calculate air density at a given altitude. 🔗 | | Decay Constant | Calculate decay constant for air density with altitude. 🔗 |

Altitude

| Formula | Description | |-----------------------------|---------------------------------------------------------------------------| | Freezing Level Altitude | Estimate the altitude where temperature drops below freezing. 🔗 |

Humidity

| Formula | Description | |-----------------------------|---------------------------------------------------------------------------| | Relative Humidity | Calculate the ratio of the current absolute humidity to the maximum possible humidity. 🔗 | | Specific Humidity | Calculate the mass of water vapor per unit mass of air. 🔗 | | Mixing Ratio | Calculate the ratio of water vapor to dry air. 🔗 | | Vapor Pressure | Calculate the partial pressure of water vapor in the air. 🔗 | | Actual Vapor Pressure | Calculate the partial pressure of water vapor actually present in the air, based on saturation vapor pressure and relative humidity. 🔗 | | Saturation Vapor Pressure | Calculate the maximum vapor pressure at a given temperature. 🔗 | | Dew Point Depression | Calculate the difference between the air temperature and the dew point temperature, indicating how close the air is to saturation. 🔗 | | Lifting Condensation Level | Estimate the altitude at which an air parcel becomes saturated when lifted and condensation begins (cloud base height). 🔗 |

Pressure

| Formula | Description | |-----------------------------|---------------------------------------------------------------------------| | Pressure Altitude | Calculate the altitude based on observed pressure. 🔗 | | Density Altitude | Calculate the altitude adjusted for temperature and air density. 🔗 | | Barometric Formula | Calculate pressure at a given altitude using the barometric formula. 🔗 | | Adjust Pressure To Sea Level | Adjust pressure to sea level using various methods: | |   Simple formula | A quick approximation for standard conditions. 🔗 | |   Advanced formula | A more accurate calculation using the barometric formula. 🔗 | |   By dynamic lapse rate | Adjust pressure using a dynamically calculated lapse rate. 🔗 | |   By historical data | Adjust pressure using historical readings. 🔗 |

Temperature

| Formula | Description | |-----------------------------|---------------------------------------------------------------------------| | Dew Point | Calculate the dew point using the Magnus formula or Arden Buck equation. 🔗 | | Wind Chill | Estimate the perceived temperature based on wind speed and air temperature. 🔗 | | (Australian) Apparent Temperature | Calculate the apparent temperature considering humidity and wind. 🔗 | | Wet-bulb Temperature | Calculate the wet-bulb temperature. 🔗 | | Equivalent Temperature | Calculate the temperature an air parcel would have if all water vapor were condensed and the latent heat released. 🔗 | | Potential Temperature | Calculate the temperature an air parcel would have if brought to a standard pressure. 🔗 | | Virtual Temperature | Calculate the temperature accounting for water vapor in the air. 🔗 | | Lapse Rate | Calculate the rate of temperature change with altitude. 🔗 | | Dynamic lapse rate | Calculate the lapse rate dynamically based on readings. 🔗 | | Weighted Average Temperature | Calculate the weighted average temperature based on altitude differences. 🔗 | | Adjust Temperature by Lapse Rate | Adjust temperature based on a fixed lapse rate. 🔗 |

Wind

| Formula | Description | |-----------------------------|---------------------------------------------------------------------------| | Wind Direction | Convert wind direction in degrees to compass direction. 🔗 | | Wind Power Density | Calculate wind power density in watts per square meter. 🔗 | | Wind Force | Calculate wind force in kilograms per square meter. 🔗 | | Adjust Wind Speed for Altitude | Adjust wind speed between different altitudes based on air density. 🔗 | | Apparent Wind | Calculate the wind speed and direction experienced by a moving observer (e.g., vessel or vehicle). 🔗 |

Phenomena

| Formula | Description | |-----------------------------|---------------------------------------------------------------------------| | Fog Visibility | Estimate visibility in fog using Koschmieder’s Law. 🔗 | | Fog Point Temperature | Calculate the fog point temperature (dew point at ground level). 🔗 | | Fog Probability | Predict the probability of fog formation using meteorological factors. |

Scales

| Scale | Description | |-----------------------------|---------------------------------------------------------------------------| | Beaufort Scale | Classify wind speed according to the Beaufort scale. 🔗 | | Saffir-Simpson Scale | Classify hurricane wind speed according to the Saffir-Simpson scale. 🔗 | | UV Index | Classify ultraviolet index. 🔗 | | Heat Index | Measure the perceived temperature based on air temperature and humidity. 🔗 | | Humidex | Calculate the humidex, a Canadian measure of perceived temperature. 🔗 |

Install

Install the library using npm:

$ npm install weather-formulas

Usage

Note: All temperatures must be provided and are returned in Kelvin (the SI unit for temperature).

ES Modules (ESM)

If your project is configured to use ES Modules (e.g., "type": "module" in package.json), you can use the import syntax to load the package:

import { temperature, humidity, pressure, wind, airDensity } from 'weather-formulas';

// Example usage
const RH = humidity.relativeHumidity(298.15, 293.15); // 25°C and 20°C in Kelvin
console.log(`Relative Humidity: ${RH}%`);

CommonJS (CJS)

If your project uses CommonJS (e.g., no "type": "module" in package.json), you can use the require syntax to load the package:

const { temperature, humidity, pressure, wind, airDensity } = require('weather-formulas');

// Example usage
const RH = humidity.relativeHumidity(298.15, 293.15); // 25°C and 20°C in Kelvin
console.log(`Relative Humidity: ${RH}%`);

TypeScript

import { temperature } from 'weather-formulas';

const dewPoint: number = temperature.dewPointMagnusFormula(298.15, 60); // 25°C and 60% humidity
console.log(`Dew Point: ${dewPoint} K`);

Advanced Examples

Use a provided valuation set:

const valuationSet = temperature.DEW_POINT_VALUATIONS.DAVID_BOLTON;
const actual = temperature.dewPointMagnusFormula(298.15, 60, valuationSet); // 25°C and 60% humidity
console.log(`Dew Point: ${actual} K`);

Use a custom valuation set:

const valuationSet = { a: 6, b: 17, c: 250, d: 234.5 };
const actual = temperature.dewPointArdenBuckEquation(298.15, 60, valuationSet); // 25°C and 60% humidity
console.log(`Dew Point: ${actual} K`);

Inspect code/tests for all possibilities.

Testing

All formulas are covered by automated tests.
Run tests with:

npm run test

Compatibility

  • Requires Node.js 18+.
  • Fully typed with TypeScript (v5+).
  • Supports both ES Modules (ESM) and CommonJS (CJS).

Contribute

Please feel free to contribute by creating a Pull Request including test code, or by suggesting other formulas.

License

This project is licensed under the GPL v3 License.

Support

For support, please open an issue in the GitHub repository.

Disclaimer

While the formulas are implemented with care, results may vary due to floating point errors, edge cases, or incorrect usage. Please verify results and report any issues or inaccuracies.