@angelrove/forecast-utils 1.1.25 → 1.1.28

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Jose Angel Romero Vegas",
3
3
  "name": "@angelrove/forecast-utils",
4
- "version": "1.1.25",
4
+ "version": "1.1.28",
5
5
  "description": "Utilities for obtaining weather and astronomy forecast data.",
6
6
  "license": "MIT",
7
7
  "publishConfig": {
@@ -32,19 +32,19 @@
32
32
  "JavaScript"
33
33
  ],
34
34
  "peerDependencies": {
35
- "@capacitor/geolocation": "^7.1.2",
36
- "react": "^19.1.0",
35
+ "@capacitor/geolocation": "^7.1.8",
36
+ "react": "^19.2.5",
37
37
  "suncalc3": "^2.0.5",
38
- "swr": "^2.3.3"
38
+ "swr": "^2.4.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@biomejs/biome": "2.2.4",
42
- "@types/react": "^19.1.12",
43
- "@types/react-dom": "^19.1.9",
44
- "typescript": "^5.9.2"
41
+ "@biomejs/biome": "^2.4.10",
42
+ "@types/react": "^19.2.14",
43
+ "@types/react-dom": "^19.2.3",
44
+ "typescript": "^6.0.2"
45
45
  },
46
46
  "dependencies": {
47
- "typedoc": "^0.28.12",
48
- "typedoc-plugin-markdown": "^4.8.1"
47
+ "typedoc": "^0.28.18",
48
+ "typedoc-plugin-markdown": "^4.11.0"
49
49
  }
50
50
  }
@@ -8,31 +8,29 @@ import { fetchParams } from "./fetchParams.js";
8
8
  * Custom hook to fetch hourly forecast data for a given location and number of days from OpenMeteo API.
9
9
  */
10
10
  export function useForecastHourly(
11
- lat: number,
12
- lon: number,
13
- dayNum: number): ForecastData
11
+ lat: number | false,
12
+ lon: number | false,
13
+ dayNum: number | false
14
+ ): ForecastData | null
14
15
  {
15
16
 
16
17
  // Validate --
18
+ const shouldFetch = lat !== false && lon !== false && dayNum !== false;
19
+
17
20
  if (lat == null || lon == null) {
18
- throw new Error("useForecastHourly: invalid coordinates: ["+lon+"]["+lat+"]");
21
+ throw new Error("useForecastHourly: invalid coordinates");
19
22
  }
20
23
 
21
24
  // Fetch ---
22
- const dates = getDatesFromNumDays(dayNum);
23
-
24
- let apiUrl =
25
- "start_date=" +
26
- dates.startDate +
27
- "&" +
28
- "end_date=" +
29
- dates.endDate +
30
- "&" +
31
- fetchParams;
32
- apiUrl = getPath(lat, lon, apiUrl);
25
+ const apiUrl = shouldFetch
26
+ ? getApiUrl(lat, lon, dayNum) : null;
33
27
 
34
28
  const { data, error, isLoading } = useSWR(apiUrl, fetcher);
35
29
 
30
+ if (!shouldFetch) {
31
+ return null;
32
+ }
33
+
36
34
  return {
37
35
  data: data,
38
36
  apiUrl: apiUrl,
@@ -40,3 +38,17 @@ export function useForecastHourly(
40
38
  isError: error,
41
39
  };
42
40
  }
41
+
42
+ function getApiUrl(lat: number, lon: number, dayNum: number) {
43
+ const dates = getDatesFromNumDays(dayNum);
44
+ const basicApiUrl =
45
+ "start_date=" +
46
+ dates.startDate +
47
+ "&" +
48
+ "end_date=" +
49
+ dates.endDate +
50
+ "&" +
51
+ fetchParams;
52
+
53
+ return getPath(lat, lon, basicApiUrl);
54
+ }
@@ -3,7 +3,7 @@
3
3
 
4
4
  export type ForecastData = {
5
5
  data: any; // 👈 Cambiar al tipo real que devuelve `transformer`
6
- apiUrl: string;
6
+ apiUrl: string | null;
7
7
  isLoading: boolean;
8
8
  isError: unknown;
9
9
  };