use-weather-forecast 0.1.95 → 0.1.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/forecast.d.ts +2 -0
- package/dist/api/geolocation.d.ts +2 -0
- package/dist/components/WeatherForecast.d.ts +13 -0
- package/dist/hooks/useWeatherForecast.d.ts +6 -0
- package/dist/icons/BaseIcon.d.ts +5 -0
- package/dist/icons/WeatherIcon.d.ts +5 -0
- package/dist/icons/weather-icons.d.ts +15 -0
- package/dist/index.d.ts +8 -105
- package/dist/lib/cache.d.ts +5 -0
- package/dist/types.d.ts +72 -0
- package/dist/weatherCodes.d.ts +2 -0
- package/package.json +15 -15
- package/dist/index.d.cts +0 -105
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { WeatherForecastOptions } from '../types';
|
|
3
|
+
type Props = WeatherForecastOptions & {
|
|
4
|
+
className?: string;
|
|
5
|
+
style?: React.CSSProperties;
|
|
6
|
+
compact?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Weather forecast widget. When `locations` is provided, one forecast is
|
|
10
|
+
* rendered per location; otherwise a single auto-detected forecast is shown.
|
|
11
|
+
*/
|
|
12
|
+
export declare function WeatherForecast(props: Props): React.JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { IconProps } from '../types';
|
|
3
|
+
export declare const CloudBoltIcon: (props: IconProps) => React.JSX.Element;
|
|
4
|
+
export declare const CloudDrizzleIcon: (props: IconProps) => React.JSX.Element;
|
|
5
|
+
export declare const CloudFogIcon: (props: IconProps) => React.JSX.Element;
|
|
6
|
+
export declare const CloudHailIcon: (props: IconProps) => React.JSX.Element;
|
|
7
|
+
export declare const CloudShowersIcon: (props: IconProps) => React.JSX.Element;
|
|
8
|
+
export declare const CloudShowersHeavyIcon: (props: IconProps) => React.JSX.Element;
|
|
9
|
+
export declare const CloudSleetIcon: (props: IconProps) => React.JSX.Element;
|
|
10
|
+
export declare const CloudSnowIcon: (props: IconProps) => React.JSX.Element;
|
|
11
|
+
export declare const CloudSunIcon: (props: IconProps) => React.JSX.Element;
|
|
12
|
+
export declare const CloudsIcon: (props: IconProps) => React.JSX.Element;
|
|
13
|
+
export declare const SnowflakeIcon: (props: IconProps) => React.JSX.Element;
|
|
14
|
+
export declare const SunIcon: (props: IconProps) => React.JSX.Element;
|
|
15
|
+
export declare const WindIcon: (props: IconProps) => React.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,105 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
timezone?: string;
|
|
10
|
-
latitude: number;
|
|
11
|
-
longitude: number;
|
|
12
|
-
};
|
|
13
|
-
type WeatherLocationInput = {
|
|
14
|
-
label?: string;
|
|
15
|
-
latitude?: number;
|
|
16
|
-
longitude?: number;
|
|
17
|
-
timezone?: string;
|
|
18
|
-
};
|
|
19
|
-
type WeatherCondition = 'sun' | 'cloud-sun' | 'clouds' | 'cloud-fog' | 'cloud-drizzle' | 'cloud-showers' | 'cloud-showers-heavy' | 'cloud-sleet' | 'cloud-snow' | 'snowflake' | 'cloud-bolt' | 'cloud-hail';
|
|
20
|
-
type CurrentWeather = {
|
|
21
|
-
time: string;
|
|
22
|
-
temperature: number;
|
|
23
|
-
weatherCode: number;
|
|
24
|
-
icon: WeatherCondition;
|
|
25
|
-
isDay?: number;
|
|
26
|
-
rain?: number;
|
|
27
|
-
showers?: number;
|
|
28
|
-
snowfall?: number;
|
|
29
|
-
windSpeed?: number;
|
|
30
|
-
};
|
|
31
|
-
type HourlyWeather = {
|
|
32
|
-
time: string;
|
|
33
|
-
temperature: number;
|
|
34
|
-
weatherCode: number;
|
|
35
|
-
precipitationProbability?: number;
|
|
36
|
-
rain?: number;
|
|
37
|
-
showers?: number;
|
|
38
|
-
snowfall?: number;
|
|
39
|
-
icon: WeatherCondition;
|
|
40
|
-
};
|
|
41
|
-
type DailyWeather = {
|
|
42
|
-
date: string;
|
|
43
|
-
min: number;
|
|
44
|
-
max: number;
|
|
45
|
-
weatherCode: number;
|
|
46
|
-
precipitationProbabilityMax?: number;
|
|
47
|
-
/** Total precipitation for the day, in millimetres. */
|
|
48
|
-
precipitationSum?: number;
|
|
49
|
-
/** Peak wind speed for the day, in the requested wind speed unit. */
|
|
50
|
-
windSpeedMax?: number;
|
|
51
|
-
icon: WeatherCondition;
|
|
52
|
-
};
|
|
53
|
-
type WeatherForecastData = {
|
|
54
|
-
location?: WeatherLocation;
|
|
55
|
-
current: CurrentWeather;
|
|
56
|
-
hourly: HourlyWeather[];
|
|
57
|
-
daily: DailyWeather[];
|
|
58
|
-
};
|
|
59
|
-
type WeatherForecastOptions = {
|
|
60
|
-
latitude?: number;
|
|
61
|
-
longitude?: number;
|
|
62
|
-
location?: Partial<WeatherLocation>;
|
|
63
|
-
locations?: WeatherLocationInput[];
|
|
64
|
-
geoEndpoint?: string;
|
|
65
|
-
ip?: string;
|
|
66
|
-
forecastDays?: number;
|
|
67
|
-
forecastHours?: number;
|
|
68
|
-
temperatureUnit?: TemperatureUnit;
|
|
69
|
-
windSpeedUnit?: WindSpeedUnit;
|
|
70
|
-
};
|
|
71
|
-
type IconProps = React.SVGProps<SVGSVGElement> & {
|
|
72
|
-
title?: string;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
declare function getWeatherIcon(code: number, isDay?: number): WeatherCondition;
|
|
76
|
-
|
|
77
|
-
/** Clears all cached forecasts. Mainly useful for tests/debugging. */
|
|
78
|
-
declare function clearWeatherForecastCache(): void;
|
|
79
|
-
|
|
80
|
-
declare function getClientLocation(geoEndpoint?: string, ip?: string): Promise<WeatherLocation>;
|
|
81
|
-
|
|
82
|
-
declare function getWeatherForecast(options?: WeatherForecastOptions): Promise<WeatherForecastData>;
|
|
83
|
-
|
|
84
|
-
declare function useWeatherForecast(options?: WeatherForecastOptions): {
|
|
85
|
-
data: WeatherForecastData | null;
|
|
86
|
-
error: Error | null;
|
|
87
|
-
loading: boolean;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
declare function WeatherIcon({ condition, ...props }: IconProps & {
|
|
91
|
-
condition: WeatherCondition;
|
|
92
|
-
}): React.JSX.Element;
|
|
93
|
-
|
|
94
|
-
type Props = WeatherForecastOptions & {
|
|
95
|
-
className?: string;
|
|
96
|
-
style?: React.CSSProperties;
|
|
97
|
-
compact?: boolean;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Weather forecast widget. When `locations` is provided, one forecast is
|
|
101
|
-
* rendered per location; otherwise a single auto-detected forecast is shown.
|
|
102
|
-
*/
|
|
103
|
-
declare function WeatherForecast(props: Props): React.JSX.Element;
|
|
104
|
-
|
|
105
|
-
export { type CurrentWeather, type DailyWeather, type HourlyWeather, type IconProps, type TemperatureUnit, type WeatherCondition, WeatherForecast, type WeatherForecastData, type WeatherForecastOptions, WeatherIcon, type WeatherLocation, type WeatherLocationInput, type WindSpeedUnit, clearWeatherForecastCache, getClientLocation, getWeatherForecast, getWeatherIcon, useWeatherForecast };
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './weatherCodes';
|
|
3
|
+
export { clearWeatherForecastCache } from './lib/cache';
|
|
4
|
+
export * from './api/geolocation';
|
|
5
|
+
export * from './api/forecast';
|
|
6
|
+
export * from './hooks/useWeatherForecast';
|
|
7
|
+
export * from './icons/WeatherIcon';
|
|
8
|
+
export * from './components/WeatherForecast';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Returns the cached value for `key` if it was written within the last 30 minutes. */
|
|
2
|
+
export declare function readCachedForecast<T>(key: string): T | null;
|
|
3
|
+
export declare function writeCachedForecast<T>(key: string, data: T): void;
|
|
4
|
+
/** Clears all cached forecasts. Mainly useful for tests/debugging. */
|
|
5
|
+
export declare function clearWeatherForecastCache(): void;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export type TemperatureUnit = 'celsius' | 'fahrenheit';
|
|
3
|
+
export type WindSpeedUnit = 'kmh' | 'mph' | 'ms' | 'kn';
|
|
4
|
+
export type WeatherLocation = {
|
|
5
|
+
city?: string;
|
|
6
|
+
region?: string;
|
|
7
|
+
country?: string;
|
|
8
|
+
timezone?: string;
|
|
9
|
+
latitude: number;
|
|
10
|
+
longitude: number;
|
|
11
|
+
};
|
|
12
|
+
export type WeatherLocationInput = {
|
|
13
|
+
label?: string;
|
|
14
|
+
latitude?: number;
|
|
15
|
+
longitude?: number;
|
|
16
|
+
timezone?: string;
|
|
17
|
+
};
|
|
18
|
+
export type WeatherCondition = 'sun' | 'cloud-sun' | 'clouds' | 'cloud-fog' | 'cloud-drizzle' | 'cloud-showers' | 'cloud-showers-heavy' | 'cloud-sleet' | 'cloud-snow' | 'snowflake' | 'cloud-bolt' | 'cloud-hail';
|
|
19
|
+
export type CurrentWeather = {
|
|
20
|
+
time: string;
|
|
21
|
+
temperature: number;
|
|
22
|
+
weatherCode: number;
|
|
23
|
+
icon: WeatherCondition;
|
|
24
|
+
isDay?: number;
|
|
25
|
+
rain?: number;
|
|
26
|
+
showers?: number;
|
|
27
|
+
snowfall?: number;
|
|
28
|
+
windSpeed?: number;
|
|
29
|
+
};
|
|
30
|
+
export type HourlyWeather = {
|
|
31
|
+
time: string;
|
|
32
|
+
temperature: number;
|
|
33
|
+
weatherCode: number;
|
|
34
|
+
precipitationProbability?: number;
|
|
35
|
+
rain?: number;
|
|
36
|
+
showers?: number;
|
|
37
|
+
snowfall?: number;
|
|
38
|
+
icon: WeatherCondition;
|
|
39
|
+
};
|
|
40
|
+
export type DailyWeather = {
|
|
41
|
+
date: string;
|
|
42
|
+
min: number;
|
|
43
|
+
max: number;
|
|
44
|
+
weatherCode: number;
|
|
45
|
+
precipitationProbabilityMax?: number;
|
|
46
|
+
/** Total precipitation for the day, in millimetres. */
|
|
47
|
+
precipitationSum?: number;
|
|
48
|
+
/** Peak wind speed for the day, in the requested wind speed unit. */
|
|
49
|
+
windSpeedMax?: number;
|
|
50
|
+
icon: WeatherCondition;
|
|
51
|
+
};
|
|
52
|
+
export type WeatherForecastData = {
|
|
53
|
+
location?: WeatherLocation;
|
|
54
|
+
current: CurrentWeather;
|
|
55
|
+
hourly: HourlyWeather[];
|
|
56
|
+
daily: DailyWeather[];
|
|
57
|
+
};
|
|
58
|
+
export type WeatherForecastOptions = {
|
|
59
|
+
latitude?: number;
|
|
60
|
+
longitude?: number;
|
|
61
|
+
location?: Partial<WeatherLocation>;
|
|
62
|
+
locations?: WeatherLocationInput[];
|
|
63
|
+
geoEndpoint?: string;
|
|
64
|
+
ip?: string;
|
|
65
|
+
forecastDays?: number;
|
|
66
|
+
forecastHours?: number;
|
|
67
|
+
temperatureUnit?: TemperatureUnit;
|
|
68
|
+
windSpeedUnit?: WindSpeedUnit;
|
|
69
|
+
};
|
|
70
|
+
export type IconProps = React.SVGProps<SVGSVGElement> & {
|
|
71
|
+
title?: string;
|
|
72
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-weather-forecast",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.97",
|
|
4
4
|
"description": "React weather forecast component using Open-Meteo and IP geolocation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -38,22 +38,22 @@
|
|
|
38
38
|
"react-dom": "^18 || ^19"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@cloudflare/workers-types": "^
|
|
42
|
-
"@testing-library/react": "^16.
|
|
43
|
-
"@types/react": "^19.
|
|
44
|
-
"@types/react-dom": "^19.
|
|
45
|
-
"@vitejs/plugin-react": "^6.
|
|
46
|
-
"@vitest/coverage-v8": "^
|
|
47
|
-
"jsdom": "^
|
|
48
|
-
"react": "^19.2.
|
|
49
|
-
"react-dom": "^19.2.
|
|
50
|
-
"tsup": "^8.
|
|
51
|
-
"typescript": "^
|
|
52
|
-
"vitest": "^
|
|
53
|
-
"wrangler": "^
|
|
41
|
+
"@cloudflare/workers-types": "^5.20260908.1",
|
|
42
|
+
"@testing-library/react": "^16.3.3",
|
|
43
|
+
"@types/react": "^19.2.18",
|
|
44
|
+
"@types/react-dom": "^19.2.7",
|
|
45
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
46
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
47
|
+
"jsdom": "^30.0.1",
|
|
48
|
+
"react": "^19.2.8",
|
|
49
|
+
"react-dom": "^19.2.8",
|
|
50
|
+
"tsup": "^8.5.1",
|
|
51
|
+
"typescript": "^7.0.2",
|
|
52
|
+
"vitest": "^5.0.0",
|
|
53
|
+
"wrangler": "^4.130.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
|
-
"build": "tsup",
|
|
56
|
+
"build": "tsup && tsc --project tsconfig.build.json",
|
|
57
57
|
"typecheck": "tsc --noEmit",
|
|
58
58
|
"test": "vitest run",
|
|
59
59
|
"test:coverage": "vitest run --coverage",
|
package/dist/index.d.cts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
type TemperatureUnit = 'celsius' | 'fahrenheit';
|
|
4
|
-
type WindSpeedUnit = 'kmh' | 'mph' | 'ms' | 'kn';
|
|
5
|
-
type WeatherLocation = {
|
|
6
|
-
city?: string;
|
|
7
|
-
region?: string;
|
|
8
|
-
country?: string;
|
|
9
|
-
timezone?: string;
|
|
10
|
-
latitude: number;
|
|
11
|
-
longitude: number;
|
|
12
|
-
};
|
|
13
|
-
type WeatherLocationInput = {
|
|
14
|
-
label?: string;
|
|
15
|
-
latitude?: number;
|
|
16
|
-
longitude?: number;
|
|
17
|
-
timezone?: string;
|
|
18
|
-
};
|
|
19
|
-
type WeatherCondition = 'sun' | 'cloud-sun' | 'clouds' | 'cloud-fog' | 'cloud-drizzle' | 'cloud-showers' | 'cloud-showers-heavy' | 'cloud-sleet' | 'cloud-snow' | 'snowflake' | 'cloud-bolt' | 'cloud-hail';
|
|
20
|
-
type CurrentWeather = {
|
|
21
|
-
time: string;
|
|
22
|
-
temperature: number;
|
|
23
|
-
weatherCode: number;
|
|
24
|
-
icon: WeatherCondition;
|
|
25
|
-
isDay?: number;
|
|
26
|
-
rain?: number;
|
|
27
|
-
showers?: number;
|
|
28
|
-
snowfall?: number;
|
|
29
|
-
windSpeed?: number;
|
|
30
|
-
};
|
|
31
|
-
type HourlyWeather = {
|
|
32
|
-
time: string;
|
|
33
|
-
temperature: number;
|
|
34
|
-
weatherCode: number;
|
|
35
|
-
precipitationProbability?: number;
|
|
36
|
-
rain?: number;
|
|
37
|
-
showers?: number;
|
|
38
|
-
snowfall?: number;
|
|
39
|
-
icon: WeatherCondition;
|
|
40
|
-
};
|
|
41
|
-
type DailyWeather = {
|
|
42
|
-
date: string;
|
|
43
|
-
min: number;
|
|
44
|
-
max: number;
|
|
45
|
-
weatherCode: number;
|
|
46
|
-
precipitationProbabilityMax?: number;
|
|
47
|
-
/** Total precipitation for the day, in millimetres. */
|
|
48
|
-
precipitationSum?: number;
|
|
49
|
-
/** Peak wind speed for the day, in the requested wind speed unit. */
|
|
50
|
-
windSpeedMax?: number;
|
|
51
|
-
icon: WeatherCondition;
|
|
52
|
-
};
|
|
53
|
-
type WeatherForecastData = {
|
|
54
|
-
location?: WeatherLocation;
|
|
55
|
-
current: CurrentWeather;
|
|
56
|
-
hourly: HourlyWeather[];
|
|
57
|
-
daily: DailyWeather[];
|
|
58
|
-
};
|
|
59
|
-
type WeatherForecastOptions = {
|
|
60
|
-
latitude?: number;
|
|
61
|
-
longitude?: number;
|
|
62
|
-
location?: Partial<WeatherLocation>;
|
|
63
|
-
locations?: WeatherLocationInput[];
|
|
64
|
-
geoEndpoint?: string;
|
|
65
|
-
ip?: string;
|
|
66
|
-
forecastDays?: number;
|
|
67
|
-
forecastHours?: number;
|
|
68
|
-
temperatureUnit?: TemperatureUnit;
|
|
69
|
-
windSpeedUnit?: WindSpeedUnit;
|
|
70
|
-
};
|
|
71
|
-
type IconProps = React.SVGProps<SVGSVGElement> & {
|
|
72
|
-
title?: string;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
declare function getWeatherIcon(code: number, isDay?: number): WeatherCondition;
|
|
76
|
-
|
|
77
|
-
/** Clears all cached forecasts. Mainly useful for tests/debugging. */
|
|
78
|
-
declare function clearWeatherForecastCache(): void;
|
|
79
|
-
|
|
80
|
-
declare function getClientLocation(geoEndpoint?: string, ip?: string): Promise<WeatherLocation>;
|
|
81
|
-
|
|
82
|
-
declare function getWeatherForecast(options?: WeatherForecastOptions): Promise<WeatherForecastData>;
|
|
83
|
-
|
|
84
|
-
declare function useWeatherForecast(options?: WeatherForecastOptions): {
|
|
85
|
-
data: WeatherForecastData | null;
|
|
86
|
-
error: Error | null;
|
|
87
|
-
loading: boolean;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
declare function WeatherIcon({ condition, ...props }: IconProps & {
|
|
91
|
-
condition: WeatherCondition;
|
|
92
|
-
}): React.JSX.Element;
|
|
93
|
-
|
|
94
|
-
type Props = WeatherForecastOptions & {
|
|
95
|
-
className?: string;
|
|
96
|
-
style?: React.CSSProperties;
|
|
97
|
-
compact?: boolean;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Weather forecast widget. When `locations` is provided, one forecast is
|
|
101
|
-
* rendered per location; otherwise a single auto-detected forecast is shown.
|
|
102
|
-
*/
|
|
103
|
-
declare function WeatherForecast(props: Props): React.JSX.Element;
|
|
104
|
-
|
|
105
|
-
export { type CurrentWeather, type DailyWeather, type HourlyWeather, type IconProps, type TemperatureUnit, type WeatherCondition, WeatherForecast, type WeatherForecastData, type WeatherForecastOptions, WeatherIcon, type WeatherLocation, type WeatherLocationInput, type WindSpeedUnit, clearWeatherForecastCache, getClientLocation, getWeatherForecast, getWeatherIcon, useWeatherForecast };
|