@angelrove/forecast-utils 1.1.13 → 1.1.15
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 +38 -4
- package/dist/types/geolocation/getGeolocation.d.ts +24 -4
- package/package.json +2 -2
- package/src/OpenMeteo/index.js +1 -0
- package/src/geolocation/getGeolocation.js +27 -5
- package/src/index.js +0 -11
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
# @forecast-utils
|
|
2
|
+
|
|
3
|
+
Several utility libraries for my "tierracolora.com" project.
|
|
4
|
+
|
|
5
|
+
Includes directory `images/ws` with weather images (symbols)
|
|
6
|
+
|
|
7
|
+
I use private libraries for the following:
|
|
8
|
+
- Astronomy calculations: `suncalc3`
|
|
9
|
+
|
|
10
|
+
# Documentation
|
|
1
11
|
## Modules
|
|
2
12
|
|
|
3
13
|
<dl>
|
|
@@ -17,7 +27,8 @@ Con excepción de 'getSolarTime()': recibe la hora local correspondiente
|
|
|
17
27
|
<dt><a href="#module_Geolocation">Geolocation</a></dt>
|
|
18
28
|
<dd></dd>
|
|
19
29
|
<dt><a href="#module_OpenMeteo">OpenMeteo</a></dt>
|
|
20
|
-
<dd
|
|
30
|
+
<dd><p>Use the OpenWeather forecast API</p>
|
|
31
|
+
</dd>
|
|
21
32
|
<dt><a href="#module_Utils">Utils</a></dt>
|
|
22
33
|
<dd></dd>
|
|
23
34
|
<dt><a href="#module_Utils/TimeDateStr">Utils/TimeDateStr</a></dt>
|
|
@@ -298,8 +309,9 @@ Con excepción de 'getSolarTime()': recibe la hora local correspondiente a la lo
|
|
|
298
309
|
## Geolocation
|
|
299
310
|
|
|
300
311
|
* [Geolocation](#module_Geolocation)
|
|
301
|
-
* [.exports.getGeolocation()](#module_Geolocation.exports.getGeolocation) ⇒ <code>Promise.<
|
|
312
|
+
* [.exports.getGeolocation()](#module_Geolocation.exports.getGeolocation) ⇒ <code>Promise.<ResolvedLocation></code>
|
|
302
313
|
* [.exports.timeFromLocation(apiKey, lat, lng)](#module_Geolocation.exports.timeFromLocation) ⇒ <code>Promise.<(any\|LocalTimeData)></code>
|
|
314
|
+
* [.ResolvedLocation](#module_Geolocation.ResolvedLocation) : <code>Object</code>
|
|
303
315
|
* [.LocalTimeData](#module_Geolocation.LocalTimeData) : <code>Object</code>
|
|
304
316
|
|
|
305
317
|
|
|
@@ -307,11 +319,11 @@ Con excepción de 'getSolarTime()': recibe la hora local correspondiente a la lo
|
|
|
307
319
|
|
|
308
320
|
<a name="module_Geolocation.exports.getGeolocation"></a>
|
|
309
321
|
|
|
310
|
-
### Geolocation.exports.getGeolocation() ⇒ <code>Promise.<
|
|
322
|
+
### Geolocation.exports.getGeolocation() ⇒ <code>Promise.<ResolvedLocation></code>
|
|
311
323
|
Get the current geolocation of the device and reverse geocode it to get the address.
|
|
312
324
|
|
|
313
325
|
**Kind**: static method of [<code>Geolocation</code>](#module_Geolocation)
|
|
314
|
-
**Returns**: <code>Promise.<
|
|
326
|
+
**Returns**: <code>Promise.<ResolvedLocation></code> - Promise
|
|
315
327
|
**Throws**:
|
|
316
328
|
|
|
317
329
|
- <code>Error</code> If geolocation is not supported or permission is denied.
|
|
@@ -338,6 +350,25 @@ Get local time from a given location (lat, lng) using 'GoogleMaps TimeZone' API.
|
|
|
338
350
|
| lng | <code>number</code> | |
|
|
339
351
|
|
|
340
352
|
|
|
353
|
+
* * *
|
|
354
|
+
|
|
355
|
+
<a name="module_Geolocation.ResolvedLocation"></a>
|
|
356
|
+
|
|
357
|
+
### Geolocation.ResolvedLocation : <code>Object</code>
|
|
358
|
+
**Kind**: static typedef of [<code>Geolocation</code>](#module_Geolocation)
|
|
359
|
+
**Properties**
|
|
360
|
+
|
|
361
|
+
| Name | Type | Description |
|
|
362
|
+
| --- | --- | --- |
|
|
363
|
+
| latitude | <code>number</code> | |
|
|
364
|
+
| longitude | <code>number</code> | // Address |
|
|
365
|
+
| sublocality | <code>string</code> | |
|
|
366
|
+
| locality | <code>string</code> | |
|
|
367
|
+
| country | <code>string</code> | |
|
|
368
|
+
| country_short | <code>string</code> | |
|
|
369
|
+
| formatted_address | <code>string</code> | |
|
|
370
|
+
|
|
371
|
+
|
|
341
372
|
* * *
|
|
342
373
|
|
|
343
374
|
<a name="module_Geolocation.LocalTimeData"></a>
|
|
@@ -362,6 +393,8 @@ Get local time from a given location (lat, lng) using 'GoogleMaps TimeZone' API.
|
|
|
362
393
|
<a name="module_OpenMeteo"></a>
|
|
363
394
|
|
|
364
395
|
## OpenMeteo
|
|
396
|
+
Use the OpenWeather forecast API
|
|
397
|
+
|
|
365
398
|
|
|
366
399
|
* [OpenMeteo](#module_OpenMeteo)
|
|
367
400
|
* [.exports.useForecastCurrent(lat, lon, refreshIntervalMin)](#module_OpenMeteo.exports.useForecastCurrent) ⇒ <code>ForecastData</code>
|
|
@@ -394,6 +427,7 @@ Custom hook to fetch current weather data from OpenMeteo API.
|
|
|
394
427
|
|
|
395
428
|
### OpenMeteo.exports.useForecastDaily(lat, lon, refreshIntervalMin) ⇒ <code>ForecastData</code>
|
|
396
429
|
Custom hook to fetch daily forecast (10 days) data from OpenMeteo API.
|
|
430
|
+
|
|
397
431
|
https://api.open-meteo.com/v1/forecast?timezone=auto&latitude=36.6644363&longitude=-4.5108962&forecast_days=10&daily=weathercode
|
|
398
432
|
|
|
399
433
|
**Kind**: static method of [<code>OpenMeteo</code>](#module_OpenMeteo)
|
|
@@ -1,12 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @memberof module:Geolocation
|
|
3
|
+
* @typedef {Object} ResolvedLocation
|
|
4
|
+
* @property {number} latitude
|
|
5
|
+
* @property {number} longitude
|
|
6
|
+
* // Address
|
|
7
|
+
* @property {string} sublocality
|
|
8
|
+
* @property {string} locality
|
|
9
|
+
* @property {string} country
|
|
10
|
+
* @property {string} country_short
|
|
11
|
+
* @property {string} formatted_address
|
|
12
|
+
*/
|
|
1
13
|
/**
|
|
2
14
|
* Get the current geolocation of the device and reverse geocode it to get the address.
|
|
3
15
|
*
|
|
4
|
-
* @returns {Promise<{latitude: number, longitude: number, formatted_address: string}>} Promise
|
|
5
|
-
* @throws {Error} If geolocation is not supported or permission is denied.
|
|
6
16
|
* @memberof module:Geolocation
|
|
17
|
+
* @returns {Promise<ResolvedLocation>} Promise
|
|
18
|
+
* @throws {Error} If geolocation is not supported or permission is denied.
|
|
7
19
|
*/
|
|
8
|
-
export function getGeolocation(): Promise<
|
|
20
|
+
export function getGeolocation(): Promise<ResolvedLocation>;
|
|
21
|
+
export type ResolvedLocation = {
|
|
9
22
|
latitude: number;
|
|
23
|
+
/**
|
|
24
|
+
* // Address
|
|
25
|
+
*/
|
|
10
26
|
longitude: number;
|
|
27
|
+
sublocality: string;
|
|
28
|
+
locality: string;
|
|
29
|
+
country: string;
|
|
30
|
+
country_short: string;
|
|
11
31
|
formatted_address: string;
|
|
12
|
-
}
|
|
32
|
+
};
|
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.
|
|
4
|
+
"version": "1.1.15",
|
|
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"
|
|
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 -!!!"
|
|
14
14
|
},
|
|
15
15
|
"types": "dist/types/index.d.ts",
|
|
16
16
|
"exports": {
|
package/src/OpenMeteo/index.js
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import geolocationCapacitor from "./lib/geolocation.js";
|
|
2
2
|
import reverseGeocoding from "./lib/reversegeocoding.js";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @memberof module:Geolocation
|
|
6
|
+
* @typedef {Object} ResolvedLocation
|
|
7
|
+
* @property {number} latitude
|
|
8
|
+
* @property {number} longitude
|
|
9
|
+
* // Address
|
|
10
|
+
* @property {string} sublocality
|
|
11
|
+
* @property {string} locality
|
|
12
|
+
* @property {string} country
|
|
13
|
+
* @property {string} country_short
|
|
14
|
+
* @property {string} formatted_address
|
|
15
|
+
*/
|
|
16
|
+
|
|
4
17
|
/**
|
|
5
18
|
* Get the current geolocation of the device and reverse geocode it to get the address.
|
|
6
19
|
*
|
|
7
|
-
* @returns {Promise<{latitude: number, longitude: number, formatted_address: string}>} Promise
|
|
8
|
-
* @throws {Error} If geolocation is not supported or permission is denied.
|
|
9
20
|
* @memberof module:Geolocation
|
|
21
|
+
* @returns {Promise<ResolvedLocation>} Promise
|
|
22
|
+
* @throws {Error} If geolocation is not supported or permission is denied.
|
|
10
23
|
*/
|
|
11
24
|
export async function getGeolocation() {
|
|
12
|
-
let location
|
|
25
|
+
let location;
|
|
13
26
|
let address = null;
|
|
14
27
|
|
|
15
28
|
// Location ---
|
|
@@ -33,6 +46,10 @@ export async function getGeolocation() {
|
|
|
33
46
|
const message = error instanceof Error ? error.message : error;
|
|
34
47
|
console.log("reverseGeocoding - error: ", message);
|
|
35
48
|
address = {
|
|
49
|
+
sublocality: "",
|
|
50
|
+
locality: "",
|
|
51
|
+
country: "",
|
|
52
|
+
country_short: "",
|
|
36
53
|
formatted_address:
|
|
37
54
|
"[" + location.latitude + ", " + location.longitude + "]",
|
|
38
55
|
};
|
|
@@ -40,8 +57,13 @@ export async function getGeolocation() {
|
|
|
40
57
|
|
|
41
58
|
// Return data ---
|
|
42
59
|
return {
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
latitude: location.latitude,
|
|
61
|
+
longitude: location.longitude,
|
|
62
|
+
sublocality: address.sublocality,
|
|
63
|
+
locality: address.locality,
|
|
64
|
+
country: address.country,
|
|
65
|
+
country_short: address.country_short,
|
|
66
|
+
formatted_address: address.formatted_address,
|
|
45
67
|
};
|
|
46
68
|
}
|
|
47
69
|
//--------------------------------------------
|
package/src/index.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Several utility libraries for the Tierracolora project:
|
|
3
|
-
* - Forecast API (OpenWeather)
|
|
4
|
-
* - Astronomy utilities
|
|
5
|
-
* - Geolocation
|
|
6
|
-
* - Another utilities.
|
|
7
|
-
*
|
|
8
|
-
* I use public libraries for the following:
|
|
9
|
-
* - Astronomy calculations: suncalc3
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
// Astronomy
|
|
13
2
|
export { default as MoonCalc } from "./astronomy/moon/MoonCalc.js";
|
|
14
3
|
export { default as SunCalc } from "./astronomy/sun/SunCalc.js";
|