@angelrove/forecast-utils 1.1.18 → 1.1.20

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.
Files changed (65) hide show
  1. package/dist/types/OpenMeteo/current/transformer.d.ts +2 -2
  2. package/dist/types/OpenMeteo/current/useForecastCurrent.d.ts +2 -7
  3. package/dist/types/OpenMeteo/daily/transformer.d.ts +2 -2
  4. package/dist/types/OpenMeteo/daily/useForecastDaily.d.ts +2 -8
  5. package/dist/types/OpenMeteo/hourly/useForecastHourly.d.ts +2 -9
  6. package/dist/types/OpenMeteo/index.d.ts +10 -4
  7. package/dist/types/OpenMeteo/types.d.ts +9 -15
  8. package/dist/types/OpenMeteo/weatherSymbol/lib/WeatherCodesEn.d.ts +1 -1
  9. package/dist/types/OpenMeteo/weatherSymbol/lib/WeatherCodesEs.d.ts +1 -1
  10. package/dist/types/OpenMeteo/weatherSymbol/weatherSymbol.d.ts +2 -12
  11. package/dist/types/astronomy/index.d.ts +7 -2
  12. package/dist/types/astronomy/moon/MoonCalc.d.ts +23 -77
  13. package/dist/types/astronomy/moon/types.d.ts +33 -0
  14. package/dist/types/astronomy/sun/SunCalc.d.ts +18 -25
  15. package/dist/types/geolocation/getGeolocation.d.ts +3 -27
  16. package/dist/types/geolocation/index.d.ts +6 -2
  17. package/dist/types/geolocation/lib/reversegeocoding.d.ts +3 -11
  18. package/dist/types/geolocation/timeFromLocation.d.ts +1 -3
  19. package/dist/types/geolocation/types.d.ts +16 -0
  20. package/dist/types/index.d.ts +4 -4
  21. package/dist/types/utils/degreesToCompass.d.ts +0 -1
  22. package/dist/types/utils/index.d.ts +10 -6
  23. package/dist/types/utils/timehelpers.d.ts +2 -6
  24. package/dist/types/utils/warning.d.ts +0 -3
  25. package/dist/types/utils/wind/WindArrow.d.ts +1 -3
  26. package/dist/types/utils/wind/windArrowTx.d.ts +0 -1
  27. package/dist/types/utils/wind/windLevel.d.ts +7 -23
  28. package/package.json +8 -6
  29. package/src/OpenMeteo/conf.js +1 -1
  30. package/src/OpenMeteo/current/transformer.js +1 -1
  31. package/src/OpenMeteo/current/{useForecastCurrent.js → useForecastCurrent.ts} +9 -9
  32. package/src/OpenMeteo/daily/transformer.js +1 -1
  33. package/src/OpenMeteo/daily/{useForecastDaily.js → useForecastDaily.ts} +7 -10
  34. package/src/OpenMeteo/hourly/{useForecastHourly.js → useForecastHourly.ts} +11 -10
  35. package/src/OpenMeteo/index.ts +12 -0
  36. package/src/OpenMeteo/types.ts +14 -0
  37. package/src/OpenMeteo/weatherSymbol/lib/WeatherCodesEn.js +1 -1
  38. package/src/OpenMeteo/weatherSymbol/lib/WeatherCodesEs.js +1 -1
  39. package/src/OpenMeteo/weatherSymbol/{weatherSymbol.js → weatherSymbol.ts} +7 -13
  40. package/src/astronomy/index.ts +9 -0
  41. package/src/astronomy/moon/{MoonCalc.js → MoonCalc.ts} +35 -92
  42. package/src/astronomy/moon/parseBasicData.js +2 -2
  43. package/src/astronomy/moon/types.ts +36 -0
  44. package/src/astronomy/sun/SunCalc.js +16 -18
  45. package/src/geolocation/{getGeolocation.js → getGeolocation.ts} +10 -27
  46. package/src/geolocation/index.ts +8 -0
  47. package/src/geolocation/lib/{geolocation.js → geolocation.ts} +5 -5
  48. package/src/geolocation/lib/{reversegeocoding.js → reversegeocoding.ts} +11 -11
  49. package/src/geolocation/timeFromLocation.js +2 -4
  50. package/src/geolocation/types.ts +18 -0
  51. package/src/{index.js → index.ts} +3 -3
  52. package/src/utils/degreesToCompass.js +1 -5
  53. package/src/utils/index.ts +12 -0
  54. package/src/utils/timehelpers.js +2 -7
  55. package/src/utils/warning.js +1 -6
  56. package/src/utils/wind/WindArrow.jsx +2 -5
  57. package/src/utils/wind/windArrowTx.js +0 -1
  58. package/src/utils/wind/{windLevel.js → windLevel.ts} +11 -20
  59. package/README.md +0 -789
  60. package/src/OpenMeteo/index.js +0 -10
  61. package/src/OpenMeteo/types.js +0 -8
  62. package/src/astronomy/index.js +0 -2
  63. package/src/geolocation/index.js +0 -6
  64. package/src/utils/index.js +0 -10
  65. /package/src/geolocation/lib/{geolocationCapacitor.js → geolocationCapacitor.ts} +0 -0
@@ -1,30 +1,14 @@
1
- /**
2
- * Return the wind level based on the speed.
3
- *
4
- * @param {number} speed Wind speed in km/h
5
- * @return {WindLevel | null} Wind level object or null if speed is null
6
- * @memberof module:Utils
7
- */
8
- export function getWindLevel(speed: number): WindLevel | null;
9
1
  export type WindLevel = {
10
- /**
11
- * - Level ID
12
- */
13
2
  id: number;
14
- /**
15
- * - Minimum wind speed for this level
16
- */
17
3
  speed: number;
18
- /**
19
- * - Color representing this level
20
- */
21
4
  color: string;
22
- /**
23
- * - Text representing this level
24
- */
25
5
  tx: string;
26
- /**
27
- * - Text representing this level
28
- */
29
6
  txEn: string;
30
7
  };
8
+ /**
9
+ * Return the wind level based on the speed.
10
+ *
11
+ * @param speed Wind speed in km/h
12
+ * @return Wind level object or null if speed is null
13
+ */
14
+ export declare function getWindLevel(speed: number): WindLevel | null;
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.18",
4
+ "version": "1.1.20",
5
5
  "description": "Utilities for obtaining weather and astronomy forecast data.",
6
6
  "license": "MIT",
7
7
  "publishConfig": {
@@ -10,7 +10,7 @@
10
10
  "homepage": "https://github.com/angelrove/forecast-utils",
11
11
  "type": "module",
12
12
  "scripts": {
13
- "docs:md": "bunx jsdoc2md --separators $(cat jsdoc-files.txt) > README.md ; cat README_HEAD.md README.md > temp && mv temp README.md; echo Remember add new files to - jsdoc-files.txt -!!!"
13
+ "docs": "typedoc"
14
14
  },
15
15
  "types": "dist/types/index.d.ts",
16
16
  "exports": {
@@ -32,17 +32,19 @@
32
32
  "JavaScript"
33
33
  ],
34
34
  "peerDependencies": {
35
+ "@capacitor/geolocation": "^7.1.2",
35
36
  "react": "^19.1.0",
36
37
  "suncalc3": "^2.0.5",
37
- "swr": "^2.3.3",
38
- "@capacitor/geolocation": "^7.1.2"
38
+ "swr": "^2.3.3"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@biomejs/biome": "2.2.4",
42
42
  "@types/react": "^19.1.12",
43
43
  "@types/react-dom": "^19.1.9",
44
- "jsdoc-to-markdown": "^9.1.2",
45
44
  "typescript": "^5.9.2"
46
45
  },
47
- "dependencies": {}
46
+ "dependencies": {
47
+ "typedoc": "^0.28.12",
48
+ "typedoc-plugin-markdown": "^4.8.1"
49
+ }
48
50
  }
@@ -39,7 +39,7 @@ export function getPath(lat, lon, path) {
39
39
  * @param {string} url
40
40
  */
41
41
  function devLog(title, url) {
42
- // @ts-ignore
42
+ /* @ts-expect-error */
43
43
  if (import.meta.env.MODE === "development") {
44
44
  // console.log('%c> fetch [' + title + ']:', 'color:#9e9', url);
45
45
  console.log("> fetch [" + title + "]:", url);
@@ -2,7 +2,7 @@
2
2
  * Transforms the OpenMeteo API data into a more usable format.
3
3
  *
4
4
  * @param {{current: any, daily: any, hourly: any, latitude: number, longitude: number}} data - The data object to transform.
5
- * @returns {Object|null} - The transformed data object or null if the input is invalid.
5
+ * @returns {object|null} - The transformed data object or null if the input is invalid.
6
6
  */
7
7
  export default function transformer(data) {
8
8
  if (!data) return null;
@@ -1,23 +1,23 @@
1
- // @ts-nocheck
2
1
  import useSWR from "swr";
3
2
  import { fetcher, getPath } from "../conf.js";
3
+ import type { ForecastData } from "../types";
4
4
  import { fetchParams } from "./fetchParams.js";
5
5
  import transformer from "./transformer.js";
6
6
 
7
7
  /**
8
8
  * Custom hook to fetch current weather data from OpenMeteo API.
9
- *
10
- * @param {number} lat
11
- * @param {number} lon
12
- * @param {number} refreshIntervalMin
13
- * @returns {ForecastData} {data, isLoading, isError, apiUrl}
14
- * @memberof module:OpenMeteo
15
9
  */
16
- export function useForecastCurrent(lat, lon, refreshIntervalMin = 0) {
17
- if (!lat || !lon) {
10
+ export function useForecastCurrent(
11
+ lat: number | undefined,
12
+ lon: number | undefined,
13
+ refreshIntervalMin: number = 0): ForecastData
14
+ {
15
+ // Validate --
16
+ if (lat == null || lon == null) {
18
17
  throw new Error("useForecastCurrent: invalid coordinates");
19
18
  }
20
19
 
20
+ // Fetch ---
21
21
  const apiUrl = getPath(lat, lon, fetchParams);
22
22
  const { data, error, isLoading } = useSWR(apiUrl, fetcher, {
23
23
  refreshInterval: refreshIntervalMin * 60 * 1000,
@@ -2,7 +2,7 @@
2
2
  * Transforms the OpenMeteo API data into a more usable format.
3
3
  *
4
4
  * @param {{daily: any}} data - The data object to transform.
5
- * @returns {Object|null} - The transformed data object or null if the input is invalid.
5
+ * @returns {object|null} - The transformed data object or null if the input is invalid.
6
6
  */
7
7
  export default function transformer(data) {
8
8
  if (!data) return null;
@@ -1,23 +1,20 @@
1
- // @ts-nocheck
2
1
  import useSWR from "swr";
3
2
  import { fetcher, getPath } from "../conf.js";
3
+ import type { ForecastData } from "../types";
4
4
  import { fetchParams } from "./fetchParams.js";
5
5
  import transformer from "./transformer.js";
6
6
 
7
7
  /**
8
8
  * Custom hook to fetch daily forecast (10 days) data from OpenMeteo API.
9
- *
10
9
  * https://api.open-meteo.com/v1/forecast?timezone=auto&latitude=36.6644363&longitude=-4.5108962&forecast_days=10&daily=weathercode
11
- *
12
- * @param {number} lat
13
- * @param {number} lon
14
- * @param {number} refreshIntervalMin
15
- * @returns {ForecastData} {data, isLoading, isError, apiUrl}
16
- * @memberof module:OpenMeteo
17
10
  */
18
- export function useForecastDaily(lat, lon, refreshIntervalMin = 0) {
11
+ export function useForecastDaily(
12
+ lat: number | undefined,
13
+ lon: number | undefined,
14
+ refreshIntervalMin: number = 0): ForecastData
15
+ {
19
16
  // Validate --
20
- if (!lat || !lon) {
17
+ if (lat == null || lon == null) {
21
18
  throw new Error("useForecastDaily: invalid coordinates");
22
19
  }
23
20
 
@@ -1,20 +1,21 @@
1
- // @ts-nocheck
2
1
  import useSWR from "swr";
3
2
  import { fetcher, getPath } from "../conf.js";
4
3
  import { getDatesFromNumDays } from "../helpers.js";
4
+ import type { ForecastData } from "../types";
5
5
  import { fetchParams } from "./fetchParams.js";
6
6
 
7
7
  /**
8
8
  * Custom hook to fetch hourly forecast data for a given location and number of days from OpenMeteo API.
9
- *
10
- * @param {{ latitude: number, longitude: number }} location
11
- * @param {number} dayNum Number of days from today: -1 = 24 hours, 0 = today, 1 = tomorrow, ...
12
- * @returns {ForecastData} {data, isLoading, isError, apiUrl}
13
- * @memberof module:OpenMeteo
14
9
  */
15
- export function useForecastHourly(location, dayNum) {
16
- if (!location.latitude || !location.longitude) {
17
- throw new Error("useForecastHourly: invalid coordinates");
10
+ export function useForecastHourly(
11
+ lat: number,
12
+ lon: number,
13
+ dayNum: number): ForecastData
14
+ {
15
+
16
+ // Validate --
17
+ if (lat == null || lon == null) {
18
+ throw new Error("useForecastHourly: invalid coordinates: ["+lon+"]["+lat+"]");
18
19
  }
19
20
 
20
21
  // Fetch ---
@@ -28,7 +29,7 @@ export function useForecastHourly(location, dayNum) {
28
29
  dates.endDate +
29
30
  "&" +
30
31
  fetchParams;
31
- apiUrl = getPath(location.latitude, location.longitude, apiUrl);
32
+ apiUrl = getPath(lat, lon, apiUrl);
32
33
 
33
34
  const { data, error, isLoading } = useSWR(apiUrl, fetcher);
34
35
 
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Use the OpenWeather forecast API
3
+ * @module OpenMeteo
4
+ *
5
+ */
6
+
7
+ export { useForecastCurrent } from "./current/useForecastCurrent";
8
+ export { useForecastDaily } from "./daily/useForecastDaily";
9
+ export { useForecastHourly } from "./hourly/useForecastHourly";
10
+ export type { ForecastData, WeatherSymbol } from "./types";
11
+ export { weatherSymbol } from "./weatherSymbol/weatherSymbol";
12
+
@@ -0,0 +1,14 @@
1
+ /**
2
+ */
3
+
4
+ export type ForecastData = {
5
+ data: any; // 👈 Cambiar al tipo real que devuelve `transformer`
6
+ apiUrl: string;
7
+ isLoading: boolean;
8
+ isError: unknown;
9
+ };
10
+
11
+ export type WeatherSymbol = {
12
+ icon: string;
13
+ description: string;
14
+ };
@@ -21,7 +21,7 @@
21
21
  */
22
22
 
23
23
  /**
24
- * @typedef {Object} WeatherCodeEntry
24
+ * @typedef {object} WeatherCodeEntry
25
25
  * @property {number} code - WMO Weather interpretation codes (WW).
26
26
  * @property {string} icon - Icon name.
27
27
  * @property {string} description - Description.
@@ -21,7 +21,7 @@
21
21
  */
22
22
 
23
23
  /**
24
- * @typedef {Object} WeatherCodeEntry
24
+ * @typedef {object} WeatherCodeEntry
25
25
  * @property {number} code - WMO Weather interpretation codes (WW).
26
26
  * @property {string} icon - Icon name.
27
27
  * @property {string} description - Description.
@@ -1,22 +1,16 @@
1
+ import type { WeatherSymbol } from "../types";
1
2
  import { getWeatherCodeEntry } from "./lib/getWeatherCodeEntry.js";
2
3
 
3
4
  /**
4
5
  * Get weather symbol and description based on the weather code.
5
- *
6
- * @param {any} code
7
- * @param {number} [precipitation]
8
- * @param {boolean} night
9
- * @param {boolean} dark
10
- * @returns {{ icon: string, description: string }}
11
- * { icon: string, description: string }
12
- * @memberof module:OpenMeteo
13
6
  */
14
7
  export function weatherSymbol(
15
- code,
16
- precipitation = undefined,
17
- night = false,
18
- dark = false,
19
- ) {
8
+ code: any,
9
+ precipitation: number | undefined = undefined,
10
+ night: boolean = false,
11
+ dark: boolean = false,
12
+ ): WeatherSymbol
13
+ {
20
14
  // Parse code ---
21
15
  let msgPlus = "";
22
16
  let theCode = code;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module Astronomy
3
+ *
4
+ */
5
+
6
+ export { MoonCalc } from "./moon/MoonCalc";
7
+ export type { AstroPosition, MoonData, MoonDataExt, MoonTimes } from "./moon/types";
8
+ export { SunCalc } from "./sun/SunCalc";
9
+
@@ -6,66 +6,27 @@
6
6
  * Importante!:
7
7
  * ¡Solo proporcionar HORA LOCAL DEL SISTEMA!: 'new Date()'
8
8
  *
9
- * @module Astronomy/MoonCalc
10
9
  */
11
10
 
12
- // @ts-ignore
11
+ /* @ts-expect-error */
13
12
  import SunCalc from "suncalc3";
14
- import TimeDateStr from "../../utils/timehelpers.js";
13
+ import { TimeDateStr } from "../../utils/timehelpers.js";
15
14
  import { parseBasicData } from "./parseBasicData.js";
15
+ import type { MoonData, MoonDataExt, MoonTimes } from "./types.js";
16
16
 
17
17
  /**
18
18
  * MoonCalc.
19
19
  * @ignore
20
20
  */
21
- const MoonCalc = {
22
- data,
23
- dataExt,
24
- times,
25
- emoji,
26
- getUpOrDown,
21
+ export const MoonCalc = {
22
+ data, dataExt, times, emoji, getUpOrDown,
27
23
  };
28
- export default MoonCalc;
29
-
30
- /**
31
- * @memberof module:Astronomy
32
- * @typedef {Object} AstroPosition
33
- * @property {number} altitude
34
- * @property {number} azimuth
35
- * @property {string} direction
36
- * @property {string} direction_full``
37
- */
38
-
39
- /**
40
- * @memberof module:Astronomy/MoonCalc
41
- * @typedef {Object} MoonDataExt
42
- * @property {string} date
43
- * @property {string} time
44
- * @property {string} illumination
45
- * @property {string} phase
46
- * @property {string} phaseId
47
- * @property {string} emoji
48
- * @property {number} parallacticAngle
49
- * @property {number} angle
50
- * @property {AstroPosition} position
51
- * @property {Object} next
52
- */
53
-
54
- /**
55
- * @memberof module:Astronomy/MoonCalc
56
- * @typedef {Object} MoonData
57
- * @property {AstroPosition} position
58
- * @property {Object} next
59
- * @property {string} next.newMoon - Date of the next new moon.
60
- * @property {string} next.fullMoon - Date of the next full moon.
61
- */
62
24
 
63
25
  /**
64
26
  * Mapa de fases lunares.
65
27
  * { phaseId, phaseName }
66
28
  *
67
29
  * @type {Object.<string, string>}
68
- * @memberof module:Astronomy/MoonCalc
69
30
  */
70
31
  const phasesES = {
71
32
  newMoon: "Luna Nueva",
@@ -78,16 +39,15 @@ const phasesES = {
78
39
  waningCrescentMoon: "Luna Menguante",
79
40
  };
80
41
 
42
+ type PhaseId = keyof typeof phasesES;
43
+
81
44
  //--------------------------------------------------------------------
82
- /**
83
- * @param {number} latitude
84
- * @param {number} longitude
85
- * @param {Date} [date=new Date()]
86
- * @param {string} [language=es-ES]
87
- * @returns {MoonData} Moon info object
88
- * @memberof module:Astronomy/MoonCalc
89
- */
90
- function data(latitude, longitude, date = new Date(), language = "es-ES") {
45
+ export function data(
46
+ latitude: number,
47
+ longitude: number,
48
+ date: Date = new Date(),
49
+ language: string = "es-ES"): MoonData
50
+ {
91
51
  // date.setHours(date.getHours() + 0); // debug
92
52
  const data = SunCalc.getMoonData(date, latitude, longitude);
93
53
  // console.log("%cdebug:", "color:yellow", data.illumination.next.newMoon.value);
@@ -99,14 +59,13 @@ function data(latitude, longitude, date = new Date(), language = "es-ES") {
99
59
  * Información de la luna para una fecha y hora dadas.
100
60
  * La fecha y hora se devolverán en la zona horaria local.
101
61
  *
102
- * @param {number} latitude
103
- * @param {number} longitude
104
- * @param {Date} [date=new Date()]
105
- * @param {string} [language=es-ES]
106
- * @returns {MoonDataExt} Full information
107
- * @memberof module:Astronomy/MoonCalc
108
62
  */
109
- function dataExt(latitude, longitude, date = new Date(), language = "es-ES") {
63
+ export function dataExt(
64
+ latitude: number,
65
+ longitude: number,
66
+ date: Date = new Date(),
67
+ language: string = "es-ES"): MoonDataExt
68
+ {
110
69
  const data = SunCalc.getMoonData(date, latitude, longitude);
111
70
 
112
71
  // Illumination
@@ -114,8 +73,8 @@ function dataExt(latitude, longitude, date = new Date(), language = "es-ES") {
114
73
  Number((data.illumination.fraction * 100).toFixed(1)) + "%";
115
74
 
116
75
  // Phase
117
- const emoji = data.illumination.phase.emoji;
118
- const phaseId = String(data.illumination.phase.id);
76
+ const emojiStr = data.illumination.phase.emoji;
77
+ const phaseId = String(data.illumination.phase.id) as PhaseId;
119
78
  const phase = phasesES[phaseId];
120
79
 
121
80
  // Angle
@@ -133,7 +92,7 @@ function dataExt(latitude, longitude, date = new Date(), language = "es-ES") {
133
92
  illumination: illumination,
134
93
  phase: phase,
135
94
  phaseId: phaseId,
136
- emoji: emoji,
95
+ emoji: emojiStr,
137
96
  parallacticAngle: parallacticAngle,
138
97
  angle: Math.round(angle),
139
98
  position: basicData.position,
@@ -141,32 +100,22 @@ function dataExt(latitude, longitude, date = new Date(), language = "es-ES") {
141
100
  };
142
101
  }
143
102
  //--------------------------------------------------------------------
144
- /**
145
- * @param {number} latitude
146
- * @param {number} longitude
147
- * @param {Date} [date=new Date()]
148
- * @returns {string} Emoji of the moon phase
149
- * @memberof module:Astronomy/MoonCalc
150
- */
151
- function emoji(latitude, longitude, date = new Date()) {
103
+ export function emoji(
104
+ latitude: number,
105
+ longitude: number,
106
+ date: Date = new Date()): string
107
+ {
152
108
  const data = SunCalc.getMoonData(date, latitude, longitude);
153
109
  return data.illumination.phase.emoji;
154
110
  }
155
111
  //--------------------------------------------------------------------
156
- /**
157
- * @param {number} latitude
158
- * @param {number} longitude
159
- * @param {string} timezoneId
160
- * @param {Date} date
161
- * @returns {{rise: string, set: string, highest: string}} Moon times
162
- * @memberof module:Astronomy/MoonCalc
163
- */
164
- function times(latitude, longitude, timezoneId, date = new Date()) {
165
- const ret = {
166
- rise: "",
167
- set: "",
168
- highest: "",
169
- };
112
+ export function times(
113
+ latitude: number,
114
+ longitude: number,
115
+ timezoneId: string,
116
+ date: Date = new Date()): MoonTimes
117
+ {
118
+ const ret = {} as MoonTimes;
170
119
 
171
120
  const times = SunCalc.getMoonTimes(date, latitude, longitude);
172
121
  if (times.alwaysUp) {
@@ -189,13 +138,7 @@ function times(latitude, longitude, timezoneId, date = new Date()) {
189
138
  return ret;
190
139
  }
191
140
  //--------------------------------------------------------------------
192
- /**
193
- * @param {number} altitude
194
- * @param {Date} highest
195
- * @returns {string} - Up or down emoji
196
- * @memberof module:Astronomy/MoonCalc
197
- */
198
- function getUpOrDown(altitude, highest) {
141
+ export function getUpOrDown(altitude: number, highest: Date): string {
199
142
  const now = new Date();
200
143
  let upOrDown = ""; // ◓ ◒
201
144
 
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
- import { degreesToCompass } from "../../utils/degreesToCompass.js";
3
- import TimeDateStr from "../../utils/timehelpers.js";
2
+ import { degreesToCompass } from "../../utils/degreesToCompass";
3
+ import { TimeDateStr } from "../../utils/timehelpers";
4
4
 
5
5
  /**
6
6
  * Parse basic data from SunCalc
@@ -0,0 +1,36 @@
1
+ export type AstroPosition = {
2
+ altitude: number;
3
+ azimuth: number;
4
+ direction: string;
5
+ direction_full: string;
6
+ };
7
+
8
+ export type MoonDataExt = {
9
+ date: string;
10
+ time: string;
11
+ illumination: string;
12
+ phase: string;
13
+ phaseId: string;
14
+ emoji: string;
15
+ parallacticAngle: number;
16
+ angle: number;
17
+ position: AstroPosition;
18
+ next: {
19
+ newMoon: string;
20
+ fullMoon: string;
21
+ };
22
+ }
23
+
24
+ export type MoonData = {
25
+ position: AstroPosition;
26
+ next: {
27
+ newMoon: string;
28
+ fullMoon: string;
29
+ };
30
+ };
31
+
32
+ export type MoonTimes = {
33
+ rise: string;
34
+ set: string;
35
+ highest: string;
36
+ };
@@ -10,16 +10,16 @@
10
10
  * @module Astronomy/SunCalc
11
11
  */
12
12
 
13
- // @ts-ignore
13
+ /* @ts-expect-error */
14
14
  import { default as SunCalc3 } from "suncalc3";
15
15
  import { degreesToCompass } from "../../utils/degreesToCompass.js";
16
- import TimeDateStr from "../../utils/timehelpers.js";
16
+ import { TimeDateStr } from "../../utils/timehelpers.js";
17
17
 
18
18
  /**
19
19
  * SunCalc.
20
20
  * @ignore
21
21
  */
22
- const SunCalc = {
22
+ export const SunCalc = {
23
23
  all,
24
24
  times,
25
25
  getSolarTime,
@@ -27,7 +27,6 @@ const SunCalc = {
27
27
  getIsNight,
28
28
  getPhase,
29
29
  };
30
- export default SunCalc;
31
30
 
32
31
  //-------------------------------------------------------
33
32
  /**
@@ -35,11 +34,10 @@ export default SunCalc;
35
34
  * @param {number} latitude
36
35
  * @param {number} longitude
37
36
  * @param {string} timezoneId
38
- * @returns {{ sunTimes: Object, sunPosition: Object, sunPhase: string }}
39
- * { sunTimes: Object, sunPosition: Object, sunPhase: string }
40
- * @memberof module:Astronomy/SunCalc
37
+ * @returns {{ sunTimes: object, sunPosition: object, sunPhase: string }}
38
+ * { sunTimes: object, sunPosition: object, sunPhase: string }
41
39
  */
42
- function all(date, latitude, longitude, timezoneId) {
40
+ export function all(date, latitude, longitude, timezoneId) {
43
41
  const sunTimes = SunCalc.times(date, latitude, longitude, timezoneId);
44
42
  const sunPosition = SunCalc.position(latitude, longitude, date);
45
43
  const sunPhase = SunCalc.getPhase(sunPosition.altitude, sunTimes.noon);
@@ -59,9 +57,8 @@ function all(date, latitude, longitude, timezoneId) {
59
57
  * @param {string} timezoneId
60
58
  * @returns {{ date: Date, sunrise: string, sunset: string, noon: string, dawn: string, dusk: string }}
61
59
  * { date: Date, sunrise: string, sunset: string, noon: string, dawn: string, dusk: string }
62
- * @memberof module:Astronomy/SunCalc
63
60
  */
64
- function times(date, latitude, longitude, timezoneId) {
61
+ export function times(date, latitude, longitude, timezoneId) {
65
62
  const times = SunCalc3.getSunTimes(date, latitude, longitude);
66
63
 
67
64
  const sunTimes = {
@@ -86,9 +83,8 @@ function times(date, latitude, longitude, timezoneId) {
86
83
  * @param {string} offsetSign "+" or "-"
87
84
  * @param {number} offset UTC offset in hours
88
85
  * @returns {string} Local time in "HH:mm" format
89
- * @memberof module:Astronomy/SunCalc
90
86
  */
91
- function getSolarTime(date, lng, offsetSign, offset) {
87
+ export function getSolarTime(date, lng, offsetSign, offset) {
92
88
  // Convert offsetSign and offset to a numeric UTC offset (e.g., -3, +2)
93
89
  const utcOffset = (offsetSign === "-" ? -1 : 1) * Math.abs(Number(offset));
94
90
  const solarTime = SunCalc3.getSolarTime(date, lng, utcOffset);
@@ -100,9 +96,13 @@ function getSolarTime(date, lng, offsetSign, offset) {
100
96
  * @param {number} longitude
101
97
  * @returns {{date: string, azimuth: number, direction: string, direction_full: string, altitude: number, zenith: number, declination: number}}
102
98
  * {date: string, azimuth: number, direction: string, direction_full: string, altitude: number, zenith: number, declination: number}
103
- * @memberof module:Astronomy/SunCalc
104
99
  */
105
- function position(latitude, longitude, date = new Date(), language = "es-ES") {
100
+ export function position(
101
+ latitude,
102
+ longitude,
103
+ date = new Date(),
104
+ language = "es-ES",
105
+ ) {
106
106
  const position = SunCalc3.getPosition(date, latitude, longitude);
107
107
 
108
108
  // Get text
@@ -128,9 +128,8 @@ function position(latitude, longitude, date = new Date(), language = "es-ES") {
128
128
  * @param {number | Date} date
129
129
  * @param {string} dateStr
130
130
  * @returns {boolean} true if it's night, false otherwise
131
- * @memberof module:Astronomy/SunCalc
132
131
  */
133
- function getIsNight(lat, lon, timezoneId, date, dateStr) {
132
+ export function getIsNight(lat, lon, timezoneId, date, dateStr) {
134
133
  const times = SunCalc3.getSunTimes(date, lat, lon);
135
134
 
136
135
  // se pueden comparar horas(hh:mm) estando en formato texto
@@ -151,9 +150,8 @@ function getIsNight(lat, lon, timezoneId, date, dateStr) {
151
150
  * @param {number} altitude
152
151
  * @param {string} noon
153
152
  * @returns {string} The phase of the sun based on its altitude
154
- * @memberof module:Astronomy/SunCalc
155
153
  */
156
- function getPhase(altitude, noon) {
154
+ export function getPhase(altitude, noon) {
157
155
  const nowTime = TimeDateStr.nowString();
158
156
 
159
157
  let phase = "day";