New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

openmeteo

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openmeteo - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

2

package.json
{
"name": "openmeteo",
"version": "1.1.1",
"version": "1.1.2",
"description": "Open-Meteo Weather API",

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

@@ -14,2 +14,9 @@ # Open-Meteo API Typescript SDK

Features:
- Simple access to weather data
- Get weather data for multiple locations in one call
- Automatic retry on error
- Reduced bandwidth and fast parsing using FlatBuffers and Zero Copy
- Type annotated
## Install

@@ -29,3 +36,5 @@

longitude: [13.41],
hourly: ['temperature_2m', 'precipitation'],
current: 'temperature_2m,weather_code,wind_speed_10m,wind_direction_10m',
hourly: 'temperature_2m,precipitation',
daily: 'weather_code,temperature_2m_max,temperature_2m_min'
};

@@ -35,8 +44,50 @@ const url = 'https://api.open-meteo.com/v1/forecast';

// Helper function to form time range
export const range = (start: number, stop: number, step: number) =>
Array.from({ length: (stop - start) / step }, (_, i) => start + i * step);
// Process first location. Add a for-loop for multiple locations or weather models
const response = responses[0];
// Attributes for timezone and location
const utcOffsetSeconds = response.utcOffsetSeconds();
const timezone = response.timezone();
const timezoneAbbreviation = response.timezoneAbbreviation();
const latitude = response.latitude();
const longitude = response.longitude();
const current = response.current()!;
const hourly = response.hourly()!;
const temperature_2m = hourly.variables(0)!.valuesArray();
const precipitation = hourly.variables(1)!.valuesArray();
const daily = response.daily()!;
// Note: The order of weather variables in the URL query and the indices below need to match!
const weatherData = {
current: {
time: new Date((Number(current.time()) + utcOffsetSeconds) * 1000),
temperature: current.variables(0)!.value(), // Current is only 1 value, therefore `.value()`
weatherCode: current.variables(1)!.value(),
windSpeed: current.variables(2)!.value(),
windDirection: current.variables(3)!.value()
},
hourly: {
time: range(Number(hourly.time()), Number(hourly.timeEnd()), hourly.interval()).map(
(t) => new Date((t + utcOffsetSeconds) * 1000)
),
temperature: hourly.variables(0)!.valuesArray()!, // `.valuesArray()` get an array of floats
precipitation: hourly.variables(1)!.valuesArray()!,
},
daily: {
time: range(Number(daily.time()), Number(daily.timeEnd()), daily.interval()).map(
(t) => new Date((t + utcOffsetSeconds) * 1000)
),
weatherCode: daily.variables(0)!.valuesArray()!,
temperatureMax: daily.variables(1)!.valuesArray()!,
temperatureMin: daily.variables(2)!.valuesArray()!,
}
};
// `weatherData` now contains a simple structure with arrays for datetime and weather data
for (let i = 0; i < daily.time.length; i++) {
console.log(daily.time[i].toISOString(), daily.weatherCode[i], daily.temperatureMax[i], daily.temperatureMin[i]);
}
```

@@ -43,0 +94,0 @@

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