@orzelius/weathermodule

2.0.1 • Public • Published

WeatherModule

Install

npm i @orzelius/weathermodule

Use like this (uncached):

const { weatherApp } = require('@orzelius/weathermodule');

//Uncached verson
weatherApp.getData('York', 1)
    .then(data => console.log(data))
    .catch(err => {
        throw err;
});

First parameter is the name of the city and the second one is optional index, if more than one city is returned.

Or like this (cached):

const { weatherApp, DataCash } = require('@orzelius/weathermodule');

//Declare cache
const cachedWeatherApp = new DataCash(() => { return weatherApp.getData('York', 1) }, 0.05)
//Use cache
console.log(cachedWeatherApp.getData().then((data) => { console.log(!!data) }));
//Some timeouts to see it work
setTimeout(cachedWeatherApp.getData, 1000);
setTimeout(cachedWeatherApp.getData, 2000);
setTimeout(cachedWeatherApp.getData, 3000);
setTimeout(cachedWeatherApp.getData, 4000);
setTimeout(cachedWeatherApp.getData, 5000);
setTimeout(cachedWeatherApp.getData, 6000);

The 0.05 is cache ttl in minutes (3s in this case)

Readme

Keywords

none

Package Sidebar

Install

npm i @orzelius/weathermodule

Weekly Downloads

7

Version

2.0.1

License

ISC

Unpacked Size

6.98 kB

Total Files

7

Last publish

Collaborators

  • orzelius