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 🙏

© 2025 – Pkg Stats / Ryan Hefner

weather-type

v0.2.0

Published

A library for parsing weather type strings

Readme

weather-type

A library for parsing weather type strings.

Why

Various weather APIs provide some form of 'weather type' description, eg 'clear' or 'light rain'. This library parses these into objects that can be compared and combined, for example to enable averaging multiple weather types. It also converts these descriptions to a small set of description codes.

Install

npm install weather-type

Example

var WeatherType = require('weather-type');

WeatherType.default.fromString('Drizzle').map(weatherType => {
  weatherType.clouds.level === WeatherType.CloudLevel.Light; // true
  weatherType.clouds.level === WeatherType.CloudLevel.Heavy; // false

  weatherType.storm.level === WeatherType.StormLevel.None; // true

  weatherType.precipitation.level === WeatherType.PrecipitationLevel.Light; // true
  weatherType.precipitation.duration === WeatherType.PrecipitationDuration.Showers; // true
  weatherType.precipitation.type === WeatherType.PrecipitationType.Rain; // true

  weatherType.toCode(); // 'light_rain_showers'
});

Design

This models weather types as a combination of several factors:

  • Storm level
  • Cloud level
  • Precipitation level
  • Precipitation type
  • Precipitation duration

These each have a set of possible numeric values corresponding to a string description. Any numeric value can be substituted for a value in a particular WeatherType instance and, when the description code is generated, the closest value in the range of possible values will be used. This makes it possible to find an average WeatherType over a set of WeatherTypes by creating a WeatherType with the average component values of the set of WeatherTypes.

Usage

WeatherType.fromString(code: string): Option<WeatherType>

Not all strings are parseable into WeatherTypes, so this returns an Option (using option-t).

new WeatherType(storm: Storm, precipitation: Precipitation, clouds: Clouds)

Constructs a WeatherType instance from its components (see below).

WeatherType#toCode(): string

Returns the description code that best describes this WeatherType instance, based on its storm, precipitation and clouds components.

new Clouds(level: number)

Possible values of level:

  • 0 (corresponds to 'clear')
  • 1 (corresponds to 'broken_clouds')
  • 2 (corresponds to 'light_clouds')
  • 3 (corresponds to 'heavy_clouds')
  • 4 (corresponds to 'mist')
  • 5 (corresponds to 'fog')

Each of these values has an associated boolean reader, eg isClear(), for convenience, which returns true if level rounds to the corresponding value.

new Precipitation(level: number, duration: number, type: number)

Possible values of level:

  • 0 (corresponds to 'none')
  • 1 (corresponds to 'light')
  • 2 (corresponds to 'heavy')

Possible values of duration:

  • 0 (corresponds to 'showers')
  • 1 (corresponds to 'steady')

Possible values of type:

  • 0 (corresponds to 'rain')
  • 1 (corresponds to 'sleet')
  • 2 (corresponds to 'snow')
  • 2 (corresponds to 'hail')

Each of these values, apart from none, has an associated boolean reader, eg isLight(), for convenience. They return true if the appropriate variable corresponds to the specified value.

Precipitation#isApplicable(): boolean

Returns true if level rounds to a value greater that 0.

new Storm(level: number)

Possible values of level:

  • 0 (corresponds to 'none')
  • 1 (corresponds to 'thunderstorm')

Storm#isApplicable(): boolean

Returns true if level rounds to a value greater that 0.

Description codes

The full list of description codes that the library can output are (in rough order of precedence):

  • thunderstorm
  • heavy_hail
  • heavy_snow
  • heavy_sleet
  • heavy_rain
  • heavy_hail_showers
  • heavy_snow_showers
  • heavy_sleet_showers
  • heavy_rain_showers
  • light_hail
  • light_snow
  • light_sleet
  • light_rain
  • light_hail_showers
  • light_snow_showers
  • light_sleet_showers
  • light_rain_showers
  • Fog
  • Mist
  • heavy_clouds
  • light_clouds
  • broken_clouds
  • clear

Tests

The tests are not distributed with the npm package (to reduce its size). To run the tests, please clone this repo from github, then run the tests:

git clone https://github.com/dp28/weather-type.git
cd weather-type
npm install
karma start

License

MIT