Socket
Socket
Sign inDemoInstall

openweather-api-node

Package Overview
Dependencies
Maintainers
1
Versions
24
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.1.0 to 1.1.1

test/uncategorized_test.js

19

index.js

@@ -59,3 +59,3 @@ const SUP_LANGS = [

const axios = require("axios").default,
_ = require("lodash")
_ = require("lodash") //todo: remove need of lodash

@@ -224,4 +224,4 @@ const currentFormatter = require("./formaters/current-formatter"),

async #evaluateLocationByName(name) {
let response = await this.#fetch(`${API_ENDPOINT}${GEO_PATH}direct?q=${name}&limit=1&appid=${this.#globalOptions.key}`)
async #evaluateLocationByName(name, key) {
let response = await this.#fetch(`${API_ENDPOINT}${GEO_PATH}direct?q=${name}&limit=1&appid=${key}`)
let data = response.data

@@ -271,4 +271,4 @@ if (data.length == 0) throw new Error("Unknown location name: " + name)

async #evaluateLocationByZipCode(zipCode) {
let response = await this.#fetch(`${API_ENDPOINT}${GEO_PATH}zip?zip=${zipCode}&appid=${this.#globalOptions.key}`)
async #evaluateLocationByZipCode(zipCode, key) {
let response = await this.#fetch(`${API_ENDPOINT}${GEO_PATH}zip?zip=${zipCode}&appid=${key}`)
let data = response.data

@@ -446,5 +446,5 @@ return {

if (this.#globalOptions.locationName) {
this.#globalOptions.coordinates = await this.#evaluateLocationByName(this.#globalOptions.locationName)
this.#globalOptions.coordinates = await this.#evaluateLocationByName(this.#globalOptions.locationName, this.#globalOptions.key)
} else if (this.#globalOptions.zipCode) {
this.#globalOptions.coordinates = await this.#evaluateLocationByZipCode(this.#globalOptions.zipCode)
this.#globalOptions.coordinates = await this.#evaluateLocationByZipCode(this.#globalOptions.zipCode, this.#globalOptions.key)
}

@@ -470,2 +470,3 @@ }

async #fetch(url) {
// console.log(url)
let response

@@ -508,3 +509,3 @@ try {

case "locationName":
options.coordinates = await this.#evaluateLocationByName(value)
options.coordinates = await this.#evaluateLocationByName(value, options.key || this.#globalOptions.key)
break

@@ -517,3 +518,3 @@

case "zipCode":
options.coordinates = await this.#evaluateLocationByZipCode(value)
options.coordinates = await this.#evaluateLocationByZipCode(value, options.key || this.#globalOptions.key)
break

@@ -520,0 +521,0 @@

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

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -493,6 +493,18 @@ # openweather-api-node ☁️

This package use so called *options*, options define: API key, coordinates, units etc.
This package use so called *options*, options define: API key, coordinates, units etc. Structure of options:
```js
{
key: "your API key" - String,
language: "language to use" - String,
units: "units to use" - String,
locationName: "name of the location" - String,
zipCode: "'zip code' of the location" - String,
coordinates: {
lat: "latitude of the location" - Number,
lon: "longitude of the location" - Number
}
}
```
In the constructor of the class you can pass object that will define *global options*, they will be used by default in any method that uses options (ex. weather calls).
In the constructor of the class you can pass object that will define *global options*, they will be used by default in any method that uses options (ex. weather calls).
Some methods have `options` argument which can be used to specify options only for this call. Options specified in `options` argument will override global options. for example if your global options look like this:

@@ -499,0 +511,0 @@ ```js

@@ -40,3 +40,3 @@ const fs = require("fs")

it("gets hourly", async () => {
weather.setLocationByName("London")
weather.setLocationByZipCode("E14,GB")
let hourly = await weather.getHourlyForecast(10)

@@ -43,0 +43,0 @@ if (!hourly.length) {

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