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 🙏

© 2024 – Pkg Stats / Ryan Hefner

yr.no-forecast

v2.1.0

Published

retrieve a weather forecast for a given time and location from met.no

Downloads

52

Readme

yr.no-forecast

TravisCI npm version Coverage Status

Wrapper to easily get weather data for a specified location in JSON format. Uses yr.no-interface under the hood. See the API docs at yr.no.

Usage

Use the getWeather(queryParams) function to get a LocationForecast object by calling the "locationforecast" API.

Here's an example:

const yrno = require('yr.no-forecast')({
  version: '1.9', // this is the default if not provided,
  request: {
    // make calls to locationforecast timeout after 15 seconds
    timeout: 15000
  }
});

const LOCATION = {
  // This is Dublin, Ireland
  lat: 53.3478,
  lon: 6.2597
};

yrno.getWeather(LOCATION)
  .then((weather) => {
    // Get general weather for next five days (Array with five objects)
    weather.getFiveDaySummary()
      .then((data) => console.log('five day summary', data));

    // Get a weather data point for a given time between now and 9 days ahead
    weather.getForecastForTime(new Date())
      .then((data) => console.log('current weather', data));
  })
  .catch((e) => {
    console.log('an error occurred!', e);
  });

API

module(config)

This module exports a single factory function that can be used to get a configured instance that exports the getWeather function.

Currently supported config options:

  • version - Passed when making a call to the met.no API to select the locationforecast version to call
  • request - Can be populated with options for the request module. The only setting that you should need to pass is timeout and is demonstrated above

instance.getWeather(params[, version])

Returns a Promise that will resolve with a LocationForecast object that contains functions to get weather data. You can pass the version parameter if you want to override the default of 1.9, or the default you supplied when creating and instance.

LocationForecast.getFiveDaySummary()

Returns a Promise that resolves to an Array of 5 weather data Objects.

LocationForecast.getForecastForTime(time)

Returns a Promise that resolves to a weather data Object that is closest to the provided time argument. The time argument will be passed to moment.utc so many time formats will work, but a millisecond timestamp or ISO formatted date string are both ideal options to use use.

LocationForecast.getXml()

Returns the raw XML string that the locationforecast API returned.

LocationForecast.getJson()

Returns the JSON representation of the entire locationforecast response.

LocationForecast.getFirstDateInPayload()

Returns the first date string that is available in the data returned from the locationforecast call.

LocationForecast.getValidTimes()

Returns an Array of ISO timestamps that represent points in time that we have weather data for.

Weather JSON Format

Some fields will be undefined depending on the weather conditions. Always verify the field you need exists, e.g use data.hasOwnProperty('fog') or similar techniques.

{
  "datatype": "forecast",
  "from": "2017-04-18T03:00:00Z",
  "to": "2017-04-18T03:00:00Z",
  "icon": "PartlyCloud",
  "rain": "0.0 mm",
  "altitude": "0",
  "latitude": "59.8940",
  "longitude": "10.6450",
  "temperature": {
    "id": "TTT",
    "unit": "celsius",
    "value": "-0.9"
  },
  "windDirection": {
    "id": "dd",
    "deg": "14.6",
    "name": "N"
  },
  "windSpeed": {
    "id": "ff",
    "mps": "1.5",
    "beaufort": "1",
    "name": "Flau vind"
  },
  "windGust": {
    "id": "ff_gust",
    "mps": "2.4"
  },
  "humidity": {
    "value": "78.3",
    "unit": "percent"
  },
  "pressure": {
    "id": "pr",
    "unit": "hPa",
    "value": "1030.1"
  },
  "cloudiness": {
    "id": "NN",
    "percent": "15.4"
  },
  "fog": {
    "id": "FOG",
    "percent": "0.0"
  },
  "lowClouds": {
    "id": "LOW",
    "percent": "15.4"
  },
  "mediumClouds": {
    "id": "MEDIUM",
    "percent": "0.8"
  },
  "highClouds": {
    "id": "HIGH",
    "percent": "0.0"
  },
  "dewpointTemperature": {
    "id": "TD",
    "unit": "celsius",
    "value": "-4.5"
  }
}

CHANGELOG

Can be found at this link.