@angelrove/forecast-utils 1.1.2 → 1.1.3
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/README.md +357 -716
- package/dist/types/OpenMeteo/current/useForecastCurrent.d.ts +1 -0
- package/dist/types/OpenMeteo/daily/useForecastDaily.d.ts +1 -0
- package/dist/types/OpenMeteo/hourly/useForecastHourly.d.ts +1 -0
- package/dist/types/OpenMeteo/index.d.ts +4 -0
- package/dist/types/OpenMeteo/weatherSymbol/weatherSymbol.d.ts +1 -0
- package/dist/types/astronomy/index.d.ts +4 -0
- package/dist/types/astronomy/moon/MoonCalc.d.ts +12 -0
- package/dist/types/astronomy/moon/parseBasicData.d.ts +2 -1
- package/dist/types/astronomy/sun/SunCalc.d.ts +6 -0
- package/dist/types/astronomy/timeZoneInfo.d.ts +2 -1
- package/dist/types/astronomy/timehelpers.d.ts +9 -3
- package/dist/types/astronomy/types.d.ts +0 -7
- package/dist/types/geolocation/getGeolocation.d.ts +2 -2
- package/dist/types/geolocation/index.d.ts +1 -0
- package/dist/types/utils/degreesToCompass.d.ts +11 -0
- package/dist/types/utils/index.d.ts +5 -0
- package/dist/types/utils/warning.d.ts +2 -0
- package/dist/types/utils/wind/WindArrow.d.ts +2 -1
- package/dist/types/utils/wind/windArrowTx.d.ts +2 -1
- package/dist/types/utils/wind/windLevel.d.ts +1 -0
- package/package.json +2 -2
- package/src/OpenMeteo/current/useForecastCurrent.js +2 -1
- package/src/OpenMeteo/daily/useForecastDaily.js +2 -1
- package/src/OpenMeteo/hourly/useForecastHourly.js +2 -1
- package/src/OpenMeteo/index.js +9 -0
- package/src/OpenMeteo/weatherSymbol/weatherSymbol.js +2 -1
- package/src/astronomy/index.js +13 -0
- package/src/astronomy/moon/MoonCalc.js +33 -14
- package/src/astronomy/moon/parseBasicData.js +2 -0
- package/src/astronomy/sun/SunCalc.js +17 -10
- package/src/astronomy/timeZoneInfo.js +5 -2
- package/src/astronomy/timehelpers.js +9 -4
- package/src/astronomy/types.js +2 -12
- package/src/geolocation/getGeolocation.js +7 -5
- package/src/geolocation/index.js +5 -0
- package/src/index.js +2 -3
- package/src/utils/degreesToCompass.js +25 -1
- package/src/utils/index.js +9 -0
- package/src/utils/warning.js +6 -7
- package/src/utils/wind/WindArrow.jsx +2 -1
- package/src/utils/wind/windArrowTx.js +2 -1
- package/src/utils/wind/windLevel.js +4 -1
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module astronomy/time-date
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
//------------------------------------------------------
|
|
6
2
|
/**
|
|
7
3
|
* Formatea una fecha a un string legible.
|
|
@@ -9,6 +5,7 @@
|
|
|
9
5
|
* @param {Date} [date]
|
|
10
6
|
* @param {boolean} [sec=false]
|
|
11
7
|
* @returns {string} La fecha formateada.
|
|
8
|
+
* @memberof module:Astronomy
|
|
12
9
|
*/
|
|
13
10
|
export function timeString(date = new Date(), sec = false) {
|
|
14
11
|
if (sec) {
|
|
@@ -27,6 +24,12 @@ export function timeString(date = new Date(), sec = false) {
|
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
26
|
//------------------------------------------------------
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param {boolean} sec
|
|
30
|
+
* @returns {String}
|
|
31
|
+
* @memberof module:Astronomy
|
|
32
|
+
*/
|
|
30
33
|
export function nowString(sec = false) {
|
|
31
34
|
return timeString(new Date(), sec);
|
|
32
35
|
}
|
|
@@ -36,6 +39,7 @@ export function nowString(sec = false) {
|
|
|
36
39
|
*
|
|
37
40
|
* @param {Date} [date=new Date()] La fecha a formatear.
|
|
38
41
|
* @returns {string} La fecha formateada.
|
|
42
|
+
* @memberof module:Astronomy
|
|
39
43
|
*/
|
|
40
44
|
export function dateFormat(date = new Date()) {
|
|
41
45
|
const options = {
|
|
@@ -53,6 +57,7 @@ export function dateFormat(date = new Date()) {
|
|
|
53
57
|
* @param {string} timeZone - The timezone string (e.g., 'America/New_York').
|
|
54
58
|
* @param {Date | number} [date=new Date()] - The date object to format. Defaults to the current date.
|
|
55
59
|
* @returns {string} - The formatted local time string.
|
|
60
|
+
* @memberof module:Astronomy
|
|
56
61
|
*/
|
|
57
62
|
export function getLocalTimeFromTz(timeZone, date = new Date()) {
|
|
58
63
|
// Timezone example
|
package/src/astronomy/types.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @module
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
2
|
+
* @memberof module:Astronomy
|
|
6
3
|
* @typedef {Object} AstroPosition
|
|
7
4
|
* @property {number} altitude
|
|
8
5
|
* @property {number} azimuth
|
|
@@ -11,14 +8,7 @@
|
|
|
11
8
|
*/
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
|
-
* @
|
|
15
|
-
* @property {AstroPosition} position
|
|
16
|
-
* @property {Object} next
|
|
17
|
-
* @property {string} next.newMoon - Date of the next new moon.
|
|
18
|
-
* @property {string} next.fullMoon - Date of the next full moon.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
11
|
+
* @memberof module:Astronomy
|
|
22
12
|
* @typedef {Object} LocalTimeData
|
|
23
13
|
* @property {Date} time - The local time.
|
|
24
14
|
* @property {string} timeStr - The formatted local time string.
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Get the current geolocation of the device and reverse geocode it to get the address.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import geolocationCapacitor from "./lib/geolocation.js";
|
|
6
6
|
import reverseGeocoding from "./lib/reversegeocoding.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Get the current geolocation of the device and reverse
|
|
10
|
-
* geocode it to get the address.
|
|
9
|
+
* Get the current geolocation of the device and reverse geocode it to get the address.
|
|
11
10
|
*
|
|
12
11
|
* @returns {Promise<{latitude: number, longitude: number, formatted_address: string}>}
|
|
13
12
|
* @throws {Error} If geolocation is not supported or permission is denied.
|
|
13
|
+
* @memberof module:Geolocation
|
|
14
14
|
*/
|
|
15
15
|
export async function getGeolocation() {
|
|
16
16
|
let location = null;
|
|
@@ -21,7 +21,8 @@ export async function getGeolocation() {
|
|
|
21
21
|
location = await geolocationCapacitor();
|
|
22
22
|
// location.latitude = '25.90197748117876'; location.longitude = '-65.71650426928204';
|
|
23
23
|
} catch (error) {
|
|
24
|
-
|
|
24
|
+
const message = error instanceof Error ? error.message : error;
|
|
25
|
+
throw new Error("Geolocation error: " + message);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
// Address ---
|
|
@@ -33,7 +34,8 @@ export async function getGeolocation() {
|
|
|
33
34
|
import.meta.env.VITE_googlemaps_api_key,
|
|
34
35
|
);
|
|
35
36
|
} catch (error) {
|
|
36
|
-
|
|
37
|
+
const message = error instanceof Error ? error.message : error;
|
|
38
|
+
console.log("reverseGeocoding - error: ", message);
|
|
37
39
|
address = {
|
|
38
40
|
formatted_address:
|
|
39
41
|
"[" + location.latitude + ", " + location.longitude + "]",
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @author: Jose Angel Romero Vegas
|
|
3
|
-
* @license: MIT
|
|
4
|
-
* @description:
|
|
5
2
|
* Several utility libraries for the Tierracolora project:
|
|
6
3
|
* - Forecast API (OpenWeather)
|
|
7
4
|
* - Astronomy utilities
|
|
5
|
+
* - Geolocation
|
|
6
|
+
* - Another utilities.
|
|
8
7
|
*
|
|
9
8
|
* I use public libraries for the following:
|
|
10
9
|
* - Astronomy calculations: suncalc3
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Convert degrees to compass designation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} Compass
|
|
7
|
+
* @property {string} short - Short compass designation
|
|
8
|
+
* @property {string} full - Full compass designation
|
|
9
|
+
* @memberof module:Utils
|
|
3
10
|
*/
|
|
4
11
|
|
|
12
|
+
/**
|
|
13
|
+
* English compass designations
|
|
14
|
+
* @type {Compass[]}
|
|
15
|
+
* @constant
|
|
16
|
+
* @property {string} short - Short compass designation
|
|
17
|
+
* @property {string} full - Full compass designation
|
|
18
|
+
* @memberof module:Utils
|
|
19
|
+
*/
|
|
5
20
|
const directions = [
|
|
6
21
|
{ short: "N", full: "North" },
|
|
7
22
|
{ short: "NE", full: "Northeast" },
|
|
@@ -13,6 +28,14 @@ const directions = [
|
|
|
13
28
|
{ short: "NW", full: "Northwest" },
|
|
14
29
|
];
|
|
15
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Spanish compass designations
|
|
33
|
+
* @type {Compass[]}
|
|
34
|
+
* @constant
|
|
35
|
+
* @property {string} short - Short compass designation
|
|
36
|
+
* @property {string} full - Full compass designation
|
|
37
|
+
* @memberof module:Utils
|
|
38
|
+
*/
|
|
16
39
|
const directionsEs = [
|
|
17
40
|
{ short: "N", full: "Norte" },
|
|
18
41
|
{ short: "NE", full: "Noreste" },
|
|
@@ -30,6 +53,7 @@ const directionsEs = [
|
|
|
30
53
|
* @param {number} degrees
|
|
31
54
|
* @param {string} language - Language code ("en-US", "es-ES", "auto")
|
|
32
55
|
* @returns {{short: string, full: string}}
|
|
56
|
+
* @memberof module:Utils
|
|
33
57
|
*/
|
|
34
58
|
export function degreesToCompass(degrees, language = "auto") {
|
|
35
59
|
if (degrees == null) return { short: "?", full: "?" };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { degreesToCompass } from "./degreesToCompass.js";
|
|
6
|
+
export { getWarning, getWarningByDays } from "./warning.js";
|
|
7
|
+
export { WindArrow } from "./wind/WindArrow.jsx";
|
|
8
|
+
export { windArrowTx } from "./wind/windArrowTx.js";
|
|
9
|
+
export { getWindLevel } from "./wind/windLevel.js";
|
package/src/utils/warning.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module utils
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// AEMET (12 horas)
|
|
6
|
-
|
|
7
1
|
/**
|
|
8
2
|
* @typedef {Object} AlertLevel
|
|
9
3
|
* @property {number} levelNum - The alert level number.
|
|
10
4
|
* @property {string} level - The alert level string (e.g., "red", "orange", "yellow").
|
|
11
5
|
* @property {number} precipitation - The precipitation threshold for the alert level.
|
|
12
6
|
* @property {number} showers - The showers threshold for the alert level.
|
|
7
|
+
* @memberof module:Utils
|
|
13
8
|
*/
|
|
14
9
|
|
|
15
10
|
/**
|
|
16
11
|
* Alert levels for rain and showers
|
|
17
12
|
*
|
|
18
13
|
* @type {AlertLevel[]}
|
|
14
|
+
* @memberof module:Utils
|
|
19
15
|
*/
|
|
20
16
|
const ALERT_LEVEL = [
|
|
21
17
|
{ levelNum: 3, level: "red", precipitation: 120, showers: 60 },
|
|
@@ -31,6 +27,7 @@ const ALERT_LEVEL = [
|
|
|
31
27
|
* @param {number} showersSumToday
|
|
32
28
|
* @param {number} showersSumTomorrow
|
|
33
29
|
* @returns {{ levelNum: number, level: string, message: string, day: number } | null}
|
|
30
|
+
* @memberof module:Utils
|
|
34
31
|
*/
|
|
35
32
|
export function getWarningByDays(
|
|
36
33
|
precipitationSumToday,
|
|
@@ -66,6 +63,7 @@ export function getWarningByDays(
|
|
|
66
63
|
* @param {number} precipitation
|
|
67
64
|
* @param {number} showers
|
|
68
65
|
* @returns {{ levelNum: number, level: string, message: string } | null}
|
|
66
|
+
* @memberof module:Utils
|
|
69
67
|
*/
|
|
70
68
|
export function getWarning(precipitation, showers) {
|
|
71
69
|
const warningRain = getWarningRain(precipitation);
|
|
@@ -93,7 +91,7 @@ export function getWarning(precipitation, showers) {
|
|
|
93
91
|
//----------------------------------------------------------------
|
|
94
92
|
/**
|
|
95
93
|
* Get warning by rain
|
|
96
|
-
*
|
|
94
|
+
* @private
|
|
97
95
|
* @param {number} precipitation
|
|
98
96
|
* @returns {{ levelNum: number, level: string, message: string } | null}
|
|
99
97
|
*/
|
|
@@ -113,6 +111,7 @@ function getWarningRain(precipitation) {
|
|
|
113
111
|
/**
|
|
114
112
|
* Get warning by showers
|
|
115
113
|
*
|
|
114
|
+
* @private
|
|
116
115
|
* @param {number} showers
|
|
117
116
|
* @returns {{ levelNum: number, level: string, message: string } | null}
|
|
118
117
|
*/
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Convert wind direction in degrees to an arrow representation.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Convert wind direction in degrees to an arrow representation.
|
|
7
7
|
*
|
|
8
8
|
* @param {number} deg - Wind direction in degrees.
|
|
9
|
+
* @memberof module:Utils
|
|
9
10
|
*/
|
|
10
11
|
export function windArrowTx(deg) {
|
|
11
12
|
if (deg == null) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Ordered list of wind levels.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
* @property {string} color - Color representing this level
|
|
10
10
|
* @property {string} tx - Text representing this level
|
|
11
11
|
* @property {string} txEn - Text representing this level
|
|
12
|
+
* @memberof module:Utils
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Ordered list of wind levels.
|
|
16
17
|
*
|
|
17
18
|
* @type {WindLevel[]}
|
|
19
|
+
* @memberof module:Utils
|
|
18
20
|
*/
|
|
19
21
|
const WIND_LEVELS = [
|
|
20
22
|
{ id: 1, speed: 8, color: "green", tx: "Brisa", txEn: "Breeze" },
|
|
@@ -36,6 +38,7 @@ const WIND_LEVELS = [
|
|
|
36
38
|
*
|
|
37
39
|
* @param {number} speed Wind speed in km/h
|
|
38
40
|
* @return {WindLevel | null} Wind level object or null if speed is null
|
|
41
|
+
* @memberof module:Utils
|
|
39
42
|
*/
|
|
40
43
|
export function getWindLevel(speed) {
|
|
41
44
|
if (typeof speed !== "number") return null;
|