Socket
Socket
Sign inDemoInstall

openweather-api-node

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openweather-api-node - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

typings/index.d.ts

4

CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.
## `v1.3.0` - 18.01.2022
### Added
* Typescript Definitions
## `v1.2.0` - 16.01.2022

@@ -5,0 +9,0 @@ ### Added

133

index.js

@@ -0,1 +1,5 @@

/**
* @typedef {"af"|"al"|"ar"|"az"|"bg"|"ca"|"cz"|"da"|"de"|"el"|"en"|"eu"|"fa"|"fi"|"fr"|"gl"|"he"|"hi"|"hr"|"hu"|"id"|"it"|"ja"|"kr"|"la"|"lt"|"mk"|"no"|"nl"|"pl"|"pt"|"pt_br"|"ro"|"ru"|"sv"|"se"|"sk"|"sl"|"sp"|"es"|"sr"|"th"|"tr"|"ua"|"uk"|"vi"|"zh_cn"|"zh_tw"|"zu"} Language
*/
const SUP_LANGS = [

@@ -51,5 +55,10 @@ "af",

"zu"
],
SUP_UNITS = ["standard", "metric", "imperial"]
]
/**
* @typedef {"standard"|"metric"|"imperial"} Unit
*/
const SUP_UNITS = ["standard", "metric", "imperial"]
const API_ENDPOINT = "https://api.openweathermap.org/",

@@ -102,13 +111,27 @@ GEO_PATH = "geo/1.0/",

* @typedef Options
* @property {String} key
* @property {String} lang
* @property {String} units
* @property {Coordinates} coordinates
* @property {String} units
* @property {String} locationName
* @property {String} zipCode
* @property {String} [key]
* @property {Language} [lang]
* @property {String} [units]
* @property {Coordinates} [coordinates]
* @property {Unit} [units]
* @property {String} [locationName]
* @property {String} [zipCode]
*/
/**
* @typedef Location
* @property {String} name Name of the found location
* @property {Object} local_names
* * local_names.[language code] - Name of the found location in different languages. The list of names can be different for different locations
* * local_names.ascii - Internal field
* * local_names.feature_name - Internal field
* @property {Number} lat Geographical coordinates of the found location (latitude)
* @property {Number} lon Geographical coordinates of the found location (longitude)
* @property {String} country Country of the found location
* @property {String|undefined} state State of the found location (where available)
*/
class OpenWeatherAPI {
/**@typedef {Options} */
#globalOptions = {

@@ -130,3 +153,3 @@ key: undefined,

* @constructor
* @param {Options} globalOptions - object that defines global options
* @param {Options} [globalOptions={}] - object that defines global options
* @returns OpenWeatherAPI object

@@ -180,3 +203,3 @@ */

*
* @returns {Object} global options
* @returns {Options} global options
*/

@@ -200,3 +223,3 @@ getGlobalOptions() {

*
* @returns global API key
* @returns {String|undefined} global API key
*/

@@ -210,3 +233,3 @@ getKey() {

*
* @param {String} lang - language
* @param {Language} lang - language
*/

@@ -220,3 +243,3 @@ setLanguage(lang) {

*
* @returns global language
* @returns {Language|undefined} global language
*/

@@ -238,3 +261,3 @@ getLanguage() {

*
* @param {String} units - units (Only **standard**, **metric** or **imperial** are supported)
* @param {Unit} units - units (Only **standard**, **metric** or **imperial** are supported)
*/

@@ -248,3 +271,3 @@ setUnits(units) {

*
* @returns global units
* @returns {Unit|undefined} global units
*/

@@ -334,4 +357,4 @@ getUnits() {

*
* @param {Options} options - options used only for this call
* @returns location
* @param {Options} [options={}] - options used only for this call
* @returns {Promise<Location|null>} location
*/

@@ -371,4 +394,4 @@ async getLocation(options = {}) {

*
* @param {Number} limit - maximum length of returned array
* @param {Options} options - options used only for this call
* @param {Number} [limit=Number.POSITIVE_INFINITY] - maximum length of returned array
* @param {Options} [options={}] - options used only for this call
* @returns array of Weather objects, one for every next minute (Empty if API returned no info about minutely weather)

@@ -393,4 +416,4 @@ */

*
* @param {Number} limit - maximum length of returned array
* @param {Options} options - options used only for this call
* @param {Number} [limit=Number.POSITIVE_INFINITY] - maximum length of returned array
* @param {Options} [options={}] - options used only for this call
* @returns array of Weather objects, one for every next hour (Empty if API returned no info about hourly weather)

@@ -414,5 +437,5 @@ */

*
* @param {Number} limit - maximum length of returned array
* @param {Boolean} includeToday - boolean indicating whether to include today's weather in returned array
* @param {Options} options - options used only for this call
* @param {Number} [limit=Number.POSITIVE_INFINITY] - maximum length of returned array
* @param {Boolean} [includeToday=false] - boolean indicating whether to include today's weather in returned array
* @param {Options} [options={}] - options used only for this call
* @returns array of Weather objects, one for every next day (Empty if API returned no info about daily weather)

@@ -439,4 +462,4 @@ */

*
* @param {Options} options - options used only for this call
* @returns weather object of today's weather **NOT the same as current!**
* @param {Options} [options={}] - options used only for this call
* @returns {Promise<dailyParser.DailyWeather>} weather object of today's weather **NOT the same as current!**
*/

@@ -447,7 +470,20 @@ async getToday(options = {}) {

// ToDo: Add Date() substitues to start and end:
/**
* Getter for alerts
* @typedef {Object} Alert
* @property {String} sender_name Name of the alert source. Please read here the full list of alert sources: https://openweathermap.org/api/one-call-api#listsource
* @property {String} event Alert event name
* @property {Number} start Date and time of the start of the alert, Unix, UTC
* @property {Number} end Date and time of the end of the alert, Unix, UTC
* @property {String} description Description of the alert
* @property {String[]} tags Type of severe weather
*/
/**
* Getter for alerts\
* **Note:** some agencies provide the alert’s description only in a local language.
*
* @param {Options} options - options used only for this call
* @returns alerts (undefined if API returned no info about alerts)
* @param {Options} [options={}] - options used only for this call
* @returns {Promise<Alert[]>} alerts
*/

@@ -465,3 +501,3 @@ async getAlerts(options = {}) {

let data = response.data
return data.alerts
return data.alerts ?? []
}

@@ -472,4 +508,14 @@

*
* @param {Options} options - options used only for this call
* @returns object that contains everything
* @param {Options} [options={}] - options used only for this call
* @returns {Promise<{
* lat: Number,
* lon: Number,
* timezone: String,
* timezone_offset: Number,
* current: currentParser.CurrentWeather,
* minutely: minutelyParser.MinutelyWeather,
* hourly: hourlyParser.HourlyWeather,
* daily: dailyParser.DailyWeather,
* alerts: Alert[]
* }>} object that contains everything
*/

@@ -504,3 +550,11 @@ async getEverything(options = {}) {

* @param {Date|Number|String} dt - Date from the **previous five days** (Unix time, UTC time zone)
* @param {Options} options - options used only for this call
* @param {Options} [options={}] - options used only for this call
* @returns {Promise<{
* lat: Number,
* lon: Number,
* timezone: String,
* timezone_offset: Number,
* current: currentParser.CurrentWeather,
* hourly: hourlyParser.HourlyWeather
* }>}
*/

@@ -546,3 +600,4 @@ async getHistory(dt, options = {}) {

*
* @param {Options} options - options used only for this call
* @param {Options} [options={}] - options used only for this call
* @returns Air Pollution Object with data about current pollution
*/

@@ -566,4 +621,5 @@ async getCurrentAirPollution(options = {}) {

*
* @param {Number} limit - maximum length of returned array
* @param {Options} options - options used only for this call
* @param {Number} [limit=Number.POSITIVE_INFINITY] - maximum length of returned array
* @param {Options} [options={}] - options used only for this call
* @returns Array of Air Pollution Objects with data about future pollution
*/

@@ -590,3 +646,4 @@ async getForecastedAirPollution(limit = Number.POSITIVE_INFINITY, options = {}) {

* @param {Date|Number|String} to - End date (unix time, UTC time zone)
* @param {Options} options - options used only for this call
* @param {Options} [options={}] - options used only for this call
* @returns Array of Air Pollution Objects with data about historical pollution
*/

@@ -593,0 +650,0 @@ async getHistoryAirPollution(from, to, options = {}) {

{
"name": "openweather-api-node",
"version": "1.2.0",
"version": "1.3.0",
"description": "Simple Node.js package that makes it easy to work with OpenWeather API",

@@ -15,2 +15,4 @@ "main": "index.js",

"weather-api",
"air",
"pollution",
"api"

@@ -37,3 +39,4 @@ ],

"test": "test"
}
},
"types": "typings/index.d.js"
}
const getWeatherModel = require("../../models/weather-model")
/**
* @typedef {Object} Astronomical
* @property {Date} sunrise Sunrise time, Unix, UTC
* @property {Number} sunrise_raw
* @property {Date} sunset Sunset time, Unix, UTC
* @property {Number} sunset_raw
*/
/**
* @typedef {Object} Temperatures
* @property {Number} cur Current temperature or estimated temperature (in hourly forecast)
*/
/**
* @typedef {Object} FeelsLike
* @property {Number} cur Current temperature or estimated temperature (in hourly forecast)
*/
/**
* @typedef {Object} WindData
* @property {Number} speed Wind speed
* @property {Number} gust Wind gust
* @property {Number} deg Wind direction, degrees (meteorological)
*/
/**
* @typedef {Object} Icon
* @property {String} url Weather icon url
* @property {String} raw Weather icon id
*/
/**
* @typedef {Object} Conditions
* @property {Temperatures} temp Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {FeelsLike} feels_like This accounts for the human perception of weather. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {Number} pressure Atmospheric pressure on the sea level, hPa
* @property {Number} humidity Humidity, %
* @property {Number} dew_point Atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {Number} clouds Cloudiness, %
* @property {Number} uvi The maximum value of UV index for the day
* @property {Number} visibility Average visibility, metres
* @property {WindData} wind Wind statistics. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour.
* @property {Number} rain Precipitation volume, mm
* @property {Number} snow Snow volume, mm
* @property {Number} condition_id Weather condition id (https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2)
* @property {String} main Group of weather parameters (Rain, Snow, Extreme etc.)
* @property {String} description Description of the weather
* @property {Icon} icon
*/
/**
* @typedef {Object} CurrentWeather
* @property {Number} lat Geographical coordinates of the location (latitude)
* @property {Number} lon Geographical coordinates of the location (longitude)
* @property {Date} dt Date and time, UTC
* @property {Number} dt_raw Date and time, Unix, UTC
* @property {String} timezone Date and time, Unix, UTC
* @property {Number} timezone_offset Date and time, Unix, UTC
* @property {Astronomical} astronomical
* @property {Conditions} weather
*/
/**
* @returns {CurrentWeather}
*/
function currentParser(data) {

@@ -4,0 +69,0 @@ let current = getWeatherModel()

const getWeatherModel = require("../../models/weather-model")
/**
* @typedef {Object} Astronomical
* @property {Date} sunrise Sunrise time, Unix, UTC
* @property {Number} sunrise_raw
* @property {Date} sunset Sunset time, Unix, UTC
* @property {Number} sunset_raw
* @property {Date} moonrise The time of when the moon rises for this day, Unix, UTC
* @property {Number} moonrise_raw
* @property {Date} moonset The time of when the moon sets for this day, Unix, UTC
* @property {Number} moonset_raw
* @property {Number} moon_phase Moon phase. 0 and 1 are 'new moon', 0.25 is 'first quarter moon', 0.5 is 'full moon' and 0.75 is 'last quarter moon'. The periods in between are called 'waxing crescent', 'waxing gibous', 'waning gibous', and 'waning crescent', respectively.
*/
/**
* @typedef {Object} Temperatures
* @property {Number} morn Morning temperature
* @property {Number} day Day temperature
* @property {Number} eve Evening temperature
* @property {Number} night Night temperature
* @property {Number} min Lowest daily temperature
* @property {Number} max Highest daily temperature
*/
/**
* @typedef {Object} FeelsLike
* @property {Number} morn Morning temperature
* @property {Number} day Day temperature
* @property {Number} eve Evening temperature
* @property {Number} night Night temperature
*/
/**
* @typedef {Object} WindData
* @property {Number} speed Wind speed
* @property {Number} gust Wind gust
* @property {Number} deg Wind direction, degrees (meteorological)
*/
/**
* @typedef {Object} Icon
* @property {String} url Weather icon url
* @property {String} raw Weather icon id
*/
/**
* @typedef {Object} Conditions
* @property {Temperatures} temp Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {FeelsLike} feels_like This accounts for the human perception of weather. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {Number} pressure Atmospheric pressure on the sea level, hPa
* @property {Number} humidity Humidity, %
* @property {Number} dew_point Atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {Number} clouds Cloudiness, %
* @property {Number} uvi The maximum value of UV index for the day
* @property {WindData} wind Wind statistics. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour.
* @property {Number} pop Probability of precipitation
* @property {Number} rain Precipitation volume, mm
* @property {Number} snow Snow volume, mm
* @property {Number} condition_id Weather condition id (https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2)
* @property {String} main Group of weather parameters (Rain, Snow, Extreme etc.)
* @property {String} description Description of the weather
* @property {Icon} icon
*/
/**
* @typedef {Object} DailyWeather
* @property {Number} lat Geographical coordinates of the location (latitude)
* @property {Number} lon Geographical coordinates of the location (longitude)
* @property {Date} dt Date and time, UTC
* @property {Number} dt_raw Date and time, Unix, UTC
* @property {String} timezone Date and time, Unix, UTC
* @property {Number} timezone_offset Date and time, Unix, UTC
* @property {Astronomical} astronomical
* @property {Conditions} weather
*/
/**
* @returns {DailyWeather}
*/
function dailyParser(data, limit) {

@@ -47,2 +126,3 @@ if (!data.daily) return []

newElement.weather.condition_id = element.weather.id
newElement.weather.main = element.weather.main
newElement.weather.description = element.weather.description

@@ -49,0 +129,0 @@ newElement.weather.icon.url = `http://openweathermap.org/img/wn/${element.weather.icon}@2x.png`

const getWeatherModel = require("../../models/weather-model")
/**
* @typedef {Object} Temperatures
* @property {Number} cur Current temperature or estimated temperature (in hourly forecast)
*/
/**
* @typedef {Object} FeelsLike
* @property {Number} cur Current temperature or estimated temperature (in hourly forecast)
*/
/**
* @typedef {Object} WindData
* @property {Number} speed Wind speed
* @property {Number} gust Wind gust
* @property {Number} deg Wind direction, degrees (meteorological)
*/
/**
* @typedef {Object} Icon
* @property {String} url Weather icon url
* @property {String} raw Weather icon id
*/
/**
* @typedef {Object} Conditions
* @property {Temperatures} temp Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {FeelsLike} feels_like This accounts for the human perception of weather. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {Number} pressure Atmospheric pressure on the sea level, hPa
* @property {Number} humidity Humidity, %
* @property {Number} dew_point Atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {Number} clouds Cloudiness, %
* @property {Number} uvi The maximum value of UV index for the day
* @property {Number} visibility Average visibility, metres
* @property {WindData} wind Wind statistics. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour.
* @property {Number} pop Probability of precipitation
* @property {Number} rain Precipitation volume, mm
* @property {Number} snow Snow volume, mm
* @property {Number} condition_id Weather condition id (https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2)
* @property {String} main Group of weather parameters (Rain, Snow, Extreme etc.)
* @property {String} description Description of the weather
* @property {Icon} icon
*/
/**
* @typedef {Object} HourlyWeather
* @property {Number} lat Geographical coordinates of the location (latitude)
* @property {Number} lon Geographical coordinates of the location (longitude)
* @property {Date} dt Date and time, UTC
* @property {Number} dt_raw Date and time, Unix, UTC
* @property {String} timezone Date and time, Unix, UTC
* @property {Number} timezone_offset Date and time, Unix, UTC
* @property {{}} astronomical
* @property {Conditions} weather
*/
/**
* @returns {HourlyWeather}
*/
function hourlyParser(data, limit) {

@@ -31,2 +89,3 @@ if (!data.hourly) return []

newElement.weather.condition_id = element.weather.id
newElement.weather.main = element.weather.main
newElement.weather.description = element.weather.description

@@ -33,0 +92,0 @@ newElement.weather.icon.url = `http://openweathermap.org/img/wn/${element.weather.icon}@2x.png`

const getWeatherModel = require("../../models/weather-model")
/**
* @typedef {Object} Conditions
* @property {{}} temp Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {{}} feels_like This accounts for the human perception of weather. Units – default: kelvin, metric: Celsius, imperial: Fahrenheit.
* @property {{}} wind Wind statistics. Units – default: metre/sec, metric: metre/sec, imperial: miles/hour.
* @property {Number} rain Precipitation volume, mm
* @property {{}} icon
*/
/**
* @typedef {Object} MinutelyWeather
* @property {Number} lat Geographical coordinates of the location (latitude)
* @property {Number} lon Geographical coordinates of the location (longitude)
* @property {Date} dt Date and time, UTC
* @property {Number} dt_raw Date and time, Unix, UTC
* @property {String} timezone Date and time, Unix, UTC
* @property {Number} timezone_offset Date and time, Unix, UTC
* @property {{}} astronomical
* @property {Conditions} weather
*/
/**
* @returns {MinutelyWeather}
*/
function minutelyParser(data, limit) {

@@ -4,0 +28,0 @@ if (!data.minutely) return []

@@ -18,3 +18,3 @@ <br>

</a>
<a href="https://npmjs.org/package/openweather-api-node">
<a href="https://github.com/loloToster/openweather-api-node/issues">
<img src="https://img.shields.io/github/issues-raw/loloToster/openweather-api-node?style=flat-square" alt="Issues">

@@ -44,2 +44,3 @@ </a>

# Simple Example
## JS:
```js

@@ -66,2 +67,26 @@ const OpenWeatherAPI = require("openweather-api-node")

## TS:
```ts
import OpenWeatherAPI from "openweather-api-node"
// or `import * as OpenWeatherAPI from "openweather-api-node"`
// if there is no `"esModuleInterop": true` in tsconfig.json
let weather = new OpenWeatherAPI({
key: "put-key-here",
locationName: "New York",
units: "imperial"
})
/*
you can use setters as well:
weather.setKey("put-key-here")
weather.setLocationByName("New York")
...
*/
weather.getCurrent().then(data => {
console.log(`Current temperature in New York is: ${data.weather.temp.cur}\u00B0F`)
})
```
# Docs

@@ -100,2 +125,4 @@

* [Air Pollution Object][apobj]
* [Alert Object][aobj]
* [Location Object][lobj]

@@ -291,3 +318,3 @@ # Methods:

location - `Object`
[Location Object][lobj] - `Object`

@@ -432,3 +459,3 @@ **Example:**

Alerts (`undefined` if API returned no info about alerts) - `Object`
Array of [Alert Objects][aobj] - `Array`

@@ -439,3 +466,3 @@ **Example:**

```
*See also:* [options][opt]
*See also:* [options][opt], [Alert Object][aobj]

@@ -464,3 +491,3 @@ ## `async` getEverything(options = {})

daily: array of daily weather objects,
alerts: alerts
alerts: array of alert objects
}

@@ -476,3 +503,3 @@ ```

```
*See also:* [options][opt], [Weather Object][wobj]
*See also:* [options][opt], [Weather Object][wobj], [Alert Object][aobj]

@@ -694,2 +721,20 @@ ## `async` getHistory(dt, options = {})

## Location Object
```js
// property: "Description" - type
{
lat: "Geographical coordinates of the found location (latitude)" - Number,
lon: "Geographical coordinates of the found location (longitude)" - Number,
name: "Name of the found location" - String,
country: "Country of the found location" - Number,
state: "State of the found location (where available) " - String | undefined,
aqi_name: "String substitute of aqi field (only english)" - String,
local_names: {
[language_code]: "Name of the found location in different languages. The list of names can be different for different locations" - String,
ascii: "Internal field" - String,
feature_name: "Сoncentration of NO2 (Nitrogen dioxide), μg/m3" - String
}
}
```
## Air Pollution Object

@@ -718,6 +763,22 @@ ```js

## Alert Object
```js
// property: "Description" - type
{
sender_name: "Name of the alert source. Please read here the full list of alert sources: https://openweathermap.org/api/one-call-api#listsource" - String,
event: "Alert event name" - Number,
start: "Date and time of the start of the alert, Unix, UTC" - Number,
end: "Date and time of the start of the alert, Unix, UTC" - Number,
description: "Description of the alert" - String,
tags: "Type of severe weather" - Array
}
```
*made by loloToster* 🍞
[models]: #models
[opt]: #options
[wobj]: #weather-object
[lobj]: #location-object
[apobj]: #air-pollution-object
[aobj]: #alert-object
[methods]: #methods

@@ -724,0 +785,0 @@ [gglobalopt]: #getglobaloptions

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc