@angelrove/forecast-utils v1.1.15
@forecast-utils
Several utility libraries for my "tierracolora.com" project.
Includes directory images/ws with weather images (symbols)
I use private libraries for the following:
- Astronomy calculations:
suncalc3
Documentation
Modules
Astronomy/MoonCalc
MoonCalc for calculating moon times, positions, and phases.
import { MoonCalc } from ...
Importante!: ¡Solo proporcionar HORA LOCAL DEL SISTEMA!: 'new Date()'
- Astronomy/MoonCalc
- .phasesES : Object.<string, string>
- .data(latitude, longitude, [date], [language]) ⇒ MoonData
- .dataExt(latitude, longitude, [date], [language]) ⇒ MoonDataExt
- .emoji(latitude, longitude, [date]) ⇒ string
- .times(latitude, longitude, timezoneId, date) ⇒ Object
- .getUpOrDown(altitude, highest) ⇒ string
- .MoonDataExt : Object
- .MoonData : Object
Astronomy/MoonCalc.phasesES : Object.<string, string>
Mapa de fases lunares. { phaseId, phaseName }
Kind: static constant of Astronomy/MoonCalc
Astronomy/MoonCalc.data(latitude, longitude, date, language) ⇒ MoonData
Kind: static method of Astronomy/MoonCalc
Returns: MoonData - Moon info object
| Param | Type | Default |
|---|---|---|
| latitude | number | |
| longitude | number | |
| date | Date | new Date() |
| language | string | "es-ES" |
Astronomy/MoonCalc.dataExt(latitude, longitude, date, language) ⇒ MoonDataExt
Información de la luna para una fecha y hora dadas. La fecha y hora se devolverán en la zona horaria local.
Kind: static method of Astronomy/MoonCalc
Returns: MoonDataExt - Full information
| Param | Type | Default |
|---|---|---|
| latitude | number | |
| longitude | number | |
| date | Date | new Date() |
| language | string | "es-ES" |
Astronomy/MoonCalc.emoji(latitude, longitude, date) ⇒ string
Kind: static method of Astronomy/MoonCalc
Returns: string - Emoji of the moon phase
| Param | Type | Default |
|---|---|---|
| latitude | number | |
| longitude | number | |
| date | Date | new Date() |
Astronomy/MoonCalc.times(latitude, longitude, timezoneId, date) ⇒ Object
Kind: static method of Astronomy/MoonCalc
Returns: Object - Moon times
| Param | Type |
|---|---|
| latitude | number |
| longitude | number |
| timezoneId | string |
| date | Date |
Astronomy/MoonCalc.getUpOrDown(altitude, highest) ⇒ string
Kind: static method of Astronomy/MoonCalc
Returns: string - - Up or down emoji
| Param | Type |
|---|---|
| altitude | number |
| highest | Date |
Astronomy/MoonCalc.MoonDataExt : Object
Kind: static typedef of Astronomy/MoonCalc
Properties
| Name | Type |
|---|---|
| date | string |
| time | string |
| illumination | string |
| phase | string |
| phaseId | string |
| emoji | string |
| parallacticAngle | number |
| angle | number |
| position | AstroPosition |
| next | Object |
Astronomy/MoonCalc.MoonData : Object
Kind: static typedef of Astronomy/MoonCalc
Properties
| Name | Type | Description |
|---|---|---|
| position | AstroPosition | |
| next | Object | |
| next.newMoon | string | Date of the next new moon. |
| next.fullMoon | string | Date of the next full moon. |
Astronomy/SunCalc
SunCalc for calculating solar times, positions, and phases.
import { SunCalc } from ...
Importante: ¡Solo proporcionar HORA LOCAL DEL SISTEMA!: 'new Date()' Con excepción de 'getSolarTime()': recibe la hora local correspondiente a la localización dada.
Astronomy/SunCalc.all(date, latitude, longitude, timezoneId) ⇒ Object
Kind: static method of Astronomy/SunCalc
Returns: Object - { sunTimes: Object, sunPosition: Object, sunPhase: string }
| Param | Type |
|---|---|
| date | Date |
| latitude | number |
| longitude | number |
| timezoneId | string |
Astronomy/SunCalc.times(date, latitude, longitude, timezoneId) ⇒ Object
Kind: static method of Astronomy/SunCalc
Returns: Object - { date: Date, sunrise: string, sunset: string, noon: string, dawn: string, dusk: string }
| Param | Type |
|---|---|
| date | Date |
| latitude | number |
| longitude | number |
| timezoneId | string |
Astronomy/SunCalc.getSolarTime(date, lng, offsetSign, offset) ⇒ string
Kind: static method of Astronomy/SunCalc
Returns: string - Local time in "HH:mm" format
| Param | Type | Description |
|---|---|---|
| date | Date | |
| lng | number | |
| offsetSign | string | "+" or "-" |
| offset | number | UTC offset in hours |
Astronomy/SunCalc.position(latitude, longitude) ⇒ Object
Kind: static method of Astronomy/SunCalc
Returns: Object - {date: string, azimuth: number, direction: string, direction_full: string, altitude: number, zenith: number, declination: number}
| Param | Type |
|---|---|
| latitude | number |
| longitude | number |
Astronomy/SunCalc.getIsNight(lat, lon, timezoneId, date, dateStr) ⇒ boolean
Kind: static method of Astronomy/SunCalc
Returns: boolean - true if it's night, false otherwise
| Param | Type |
|---|---|
| lat | number |
| lon | number |
| timezoneId | string |
| date | number | Date |
| dateStr | string |
Astronomy/SunCalc.getPhase(altitude, noon) ⇒ string
Kind: static method of Astronomy/SunCalc
Returns: string - The phase of the sun based on its altitude
| Param | Type |
|---|---|
| altitude | number |
| noon | string |
Geolocation
- Geolocation
- .exports.getGeolocation() ⇒ Promise.<ResolvedLocation>
- .exports.timeFromLocation(apiKey, lat, lng) ⇒ Promise.<(any|LocalTimeData)>
- .ResolvedLocation : Object
- .LocalTimeData : Object
Geolocation.exports.getGeolocation() ⇒ Promise.<ResolvedLocation>
Get the current geolocation of the device and reverse geocode it to get the address.
Kind: static method of Geolocation
Returns: Promise.<ResolvedLocation> - Promise
Throws:
- Error If geolocation is not supported or permission is denied.
Geolocation.exports.timeFromLocation(apiKey, lat, lng) ⇒ Promise.<(any|LocalTimeData)>
Get local time from a given location (lat, lng) using 'GoogleMaps TimeZone' API.
Kind: static method of Geolocation
Returns: Promise.<(any|LocalTimeData)> - An object containing the local time and timezone information:
Throws:
- Error If the API request fails or returns an error status.
| Param | Type | Description |
|---|---|---|
| apiKey | string | GoogleMaps API key. |
| lat | number | |
| lng | number |
Geolocation.ResolvedLocation : Object
Kind: static typedef of Geolocation
Properties
| Name | Type | Description |
|---|---|---|
| latitude | number | |
| longitude | number | // Address |
| sublocality | string | |
| locality | string | |
| country | string | |
| country_short | string | |
| formatted_address | string |
Geolocation.LocalTimeData : Object
Kind: static typedef of Geolocation
Properties
| Name | Type | Description |
|---|---|---|
| time | Date | The local time. |
| timeStr | string | The formatted local time string. |
| timezone | string | The timezone name. |
| timezoneId | string | The timezone ID. |
| offset | number | The UTC offset in hours. |
| offsetSign | string | The sign of the offset ('+' or '-'). |
| dstOffset | number | The DST offset in hours. |
OpenMeteo
Use the OpenWeather forecast API
- OpenMeteo
- .exports.useForecastCurrent(lat, lon, refreshIntervalMin) ⇒ ForecastData
- .exports.useForecastDaily(lat, lon, refreshIntervalMin) ⇒ ForecastData
- .exports.useForecastHourly(location, dayNum) ⇒ ForecastData
- .exports.weatherSymbol(code, [precipitation], night, dark) ⇒ Object
- .ForecastData : Object
OpenMeteo.exports.useForecastCurrent(lat, lon, refreshIntervalMin) ⇒ ForecastData
Custom hook to fetch current weather data from OpenMeteo API.
Kind: static method of OpenMeteo
Returns: ForecastData - {data, isLoading, isError, apiUrl}
| Param | Type |
|---|---|
| lat | number |
| lon | number |
| refreshIntervalMin | number |
OpenMeteo.exports.useForecastDaily(lat, lon, refreshIntervalMin) ⇒ ForecastData
Custom hook to fetch daily forecast (10 days) data from OpenMeteo API.
Kind: static method of OpenMeteo
Returns: ForecastData - {data, isLoading, isError, apiUrl}
| Param | Type |
|---|---|
| lat | number |
| lon | number |
| refreshIntervalMin | number |
OpenMeteo.exports.useForecastHourly(location, dayNum) ⇒ ForecastData
Custom hook to fetch hourly forecast data for a given location and number of days from OpenMeteo API.
Kind: static method of OpenMeteo
Returns: ForecastData - {data, isLoading, isError, apiUrl}
| Param | Type | Description |
|---|---|---|
| location | Object | |
| dayNum | number | Number of days from today: -1 = 24 hours, 0 = today, 1 = tomorrow, ... |
OpenMeteo.exports.weatherSymbol(code, precipitation, night, dark) ⇒ Object
Get weather symbol and description based on the weather code.
Kind: static method of OpenMeteo
Returns: Object - { icon: string, description: string }
| Param | Type |
|---|---|
| code | any |
| precipitation | number |
| night | boolean |
| dark | boolean |
OpenMeteo.ForecastData : Object
Kind: static typedef of OpenMeteo
Properties
| Name | Type | Description |
|---|---|---|
| data | any | Forecast data |
| isLoading | boolean | Loading state |
| isError | any | Error state |
| apiUrl | string | API URL |
Utils
- Utils
- .directions : Array.<Compass>
- .directionsEs : Array.<Compass>
- .ALERT_LEVEL : Array.<AlertLevel>
- .WIND_LEVELS : Array.<WindLevel>
- .exports.degreesToCompass(degrees, language) ⇒ Object
- .exports.getWarningByDays(precipitationSumToday, precipitationSumTomorrow, showersSumToday, showersSumTomorrow) ⇒ Object | null
- .exports.getWarning(precipitation, showers) ⇒ Object | null
- .exports.WindArrow(props)
- .exports.windArrowTx(deg) ⇒ string
- .exports.getWindLevel(speed) ⇒ WindLevel | null
- .Compass : Object
- .AlertLevel : Object
- .WindLevel : Object
Utils.directions : Array.<Compass>
English compass designations
Kind: static constant of Utils
Properties
| Name | Type | Description |
|---|---|---|
| short | string | Short compass designation |
| full | string | Full compass designation |
Utils.directionsEs : Array.<Compass>
Spanish compass designations
Kind: static constant of Utils
Properties
| Name | Type | Description |
|---|---|---|
| short | string | Short compass designation |
| full | string | Full compass designation |
Utils.ALERT_LEVEL : Array.<AlertLevel>
Alert levels for rain and showers
Kind: static constant of Utils
Utils.WIND_LEVELS : Array.<WindLevel>
Ordered list of wind levels.
Kind: static constant of Utils
Utils.exports.degreesToCompass(degrees, language) ⇒ Object
Convert degrees to compass designation
Kind: static method of Utils
Returns: Object - {short: string, full: string}
| Param | Type | Description |
|---|---|---|
| degrees | number | |
| language | string | Language code ("en-US", "es-ES", "auto") |
Utils.exports.getWarningByDays(precipitationSumToday, precipitationSumTomorrow, showersSumToday, showersSumTomorrow) ⇒ Object | null
Get warning by today and tomorrow
Kind: static method of Utils
Returns: Object | null - {{ levelNum: number, level: string, message: string, day: number } | null}
| Param | Type |
|---|---|
| precipitationSumToday | number |
| precipitationSumTomorrow | number |
| showersSumToday | number |
| showersSumTomorrow | number |
Utils.exports.getWarning(precipitation, showers) ⇒ Object | null
Get warning by precipitation and showers
Kind: static method of Utils
Returns: Object | null - {{ levelNum: number, level: string, message: string } | null}
| Param | Type |
|---|---|
| precipitation | number |
| showers | number |
Utils.exports.WindArrow(props)
SVG arrow indicating wind direction.
Kind: static method of Utils
Component: JSX
| Param | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.deg | number | Wind direction in degrees (0 = North, 90 = East, etc.). |
| props.size | string | Tailwind CSS size class (e.g., 'size-10') |
| props.strokeWidth | number | Stroke width of the arrow (range: 1–6). |
| props.className | string | Additional CSS classes. |
Utils.exports.windArrowTx(deg) ⇒ string
Convert wind direction in degrees to an arrow representation.
Kind: static method of Utils
Returns: string - Arrow representation of the wind direction.
| Param | Type | Description |
|---|---|---|
| deg | number | Wind direction in degrees. |
Utils.exports.getWindLevel(speed) ⇒ WindLevel | null
Return the wind level based on the speed.
Kind: static method of Utils
Returns: WindLevel | null - Wind level object or null if speed is null
| Param | Type | Description |
|---|---|---|
| speed | number | Wind speed in km/h |
Utils.Compass : Object
Kind: static typedef of Utils
Properties
| Name | Type | Description |
|---|---|---|
| short | string | Short compass designation |
| full | string | Full compass designation |
Utils.AlertLevel : Object
Kind: static typedef of Utils
Properties
| Name | Type | Description |
|---|---|---|
| levelNum | number | The alert level number. |
| level | string | The alert level string (e.g., "red", "orange", "yellow"). |
| precipitation | number | The precipitation threshold for the alert level. |
| showers | number | The showers threshold for the alert level. |
Utils.WindLevel : Object
Kind: static typedef of Utils
Properties
| Name | Type | Description |
|---|---|---|
| id | number | Level ID |
| speed | number | Minimum wind speed for this level |
| color | string | Color representing this level |
| tx | string | Text representing this level |
| txEn | string | Text representing this level |
Utils/TimeDateStr
Helpers for get date and time formeted strings
- Utils/TimeDateStr
- .dateFormat([date]) ⇒ string
- .timeString([date], [sec]) ⇒ string
- .nowString(sec) ⇒ String
- .getLocalTimeFromTz(timeZone, [date]) ⇒ string
Utils/TimeDateStr.dateFormat(date) ⇒ string
Returns a date as a formated string.
Kind: static method of Utils/TimeDateStr
Returns: string - La fecha formateada.
| Param | Type | Default | Description |
|---|---|---|---|
| date | Date | new Date() | La fecha a formatear. |
Utils/TimeDateStr.timeString(date, sec) ⇒ string
Returns a time as a formated string.
Kind: static method of Utils/TimeDateStr
Returns: string - La fecha formateada.
| Param | Type | Default |
|---|---|---|
| date | Date | |
| sec | boolean | false |
Utils/TimeDateStr.nowString(sec) ⇒ String
Returns a now time as a formated string.
Kind: static method of Utils/TimeDateStr
Returns: String - now time as a formated string
| Param | Type | Default |
|---|---|---|
| sec | boolean | false |
Utils/TimeDateStr.getLocalTimeFromTz(timeZone, date) ⇒ string
Return the local time string from a given timezone.
Kind: static method of Utils/TimeDateStr
Returns: string - - The formatted local time string.
| Param | Type | Default | Description |
|---|---|---|---|
| timeZone | string | The timezone string (e.g., 'America/New_York'). | |
| date | Date | number | new Date() | The date object to format. Defaults to the current date. |