Socket
Socket
Sign inDemoInstall

weather-forecaster

Package Overview
Dependencies
7
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    weather-forecaster

A NPM module that will allow you to easily access the current and detailed weather conditions of any city in any country you prefer!


Version published
Maintainers
1
Install size
166 kB
Created

Readme

Source

weather-forecaster

weather-forecaster is a NPM module that will allow you to easily access the current and detailed weather conditions of any city in any country that you prefer!

package-image install-image

NPM

Installation

npm install weather-forecaster

Properties

FieldTypeUnitDescription
dateobjectThe date that the observation pertains (both numeric and long date formats)
locationstringName of the location (City, Country)
location_woeidintegerWhere On Earth ID
humidity_percentageintegerpercentage
weather_statestringName of the weather state
weather_state_iconURLstringIcon of the weather state (SVG format)
air_pressure_hPafloathPa
wind_speedobjectkmh, mph
wind_directionstringcompass pointCompass point of the wind direction
temp_celciusobjectcentigrade
temp_fahrenheitobjectfahrenheit
visibility_rangeobjectkm, milesMeasure of the distance which the weather state can be clearly discerned

Usage

Since this package's structure is asynchronous you have to use "async-await" or ".then()" structures when using the module.

Example usages with these structures are given below.

  • Getting all the data with IIFE:
const weather_forecast = require("weather-forecaster");


(async () => {

    const data = await weather_forecast("san francisco");

    // your code..

    console.log(data);

})();
  • Getting all the data with .then():
const weather_forecast = require("weather-forecaster");


weather_forecast("istanbul").then(data => {

    // your code..

    console.log(data);

});
  • Getting all the data with async-await:
const weather_forecast = require("weather-forecaster");


async function myWeatherData(query) {

    const data = await weather_forecast(query);

    // your code..

    console.log(data);

};

myWeatherData("new york");
  • Destructuring & getting specific data:
const weather_forecast = require("weather-forecaster");


async function myWeatherData(query) {

    const data = await weather_forecast(query);

    /*
    this destructuring assignment will allow us to use 
    these parts of the data without using the data.<name> format
    */
    const { weather_state, temp_celcius } = data;

    // in this case the expected outputs will be the same

    //                                  example outputs:
    console.log(weather_state);      // Light Cloud
    console.log(data.weather_state); // Light Cloud


    /*
    we can do that destructuring assignment once again with
    the parts that we already destructured
    */
    const { lowest, highest, current } = temp_celcius;

    const first_array = [
        lowest,
        highest,
        current
    ];

    const second_array = [
        temp_celcius.lowest,
        temp_celcius.highest,
        temp_celcius.current
    ];

    const third_array = [
        data.temp_celcius.lowest,
        data.temp_celcius.highest,
        data.temp_celcius.current
    ];

    // in this case the expected outputs will be the same

    //                            example outputs:
    console.log(first_array);  // [ 15.2, 23.2, 23.5 ]
    console.log(second_array); // [ 15.2, 23.2, 23.5 ]
    console.log(third_array);  // [ 15.2, 23.2, 23.5 ]

};

myWeatherData("new york");

License

Licensed under The MIT License (MIT). For the full copyright and license information, please view the LICENSE file.

Keywords

FAQs

Last updated on 24 Jun 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc