1.1.15 • Published 7 months ago

@angelrove/forecast-utils v1.1.15

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

@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>

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

ParamTypeDefault
latitudenumber
longitudenumber
dateDatenew Date()
languagestring"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

ParamTypeDefault
latitudenumber
longitudenumber
dateDatenew Date()
languagestring"es-ES"

Astronomy/MoonCalc.emoji(latitude, longitude, date) ⇒ string

Kind: static method of Astronomy/MoonCalc
Returns: string - Emoji of the moon phase

ParamTypeDefault
latitudenumber
longitudenumber
dateDatenew Date()

Astronomy/MoonCalc.times(latitude, longitude, timezoneId, date) ⇒ Object

Kind: static method of Astronomy/MoonCalc
Returns: Object - Moon times

ParamType
latitudenumber
longitudenumber
timezoneIdstring
dateDate

Astronomy/MoonCalc.getUpOrDown(altitude, highest) ⇒ string

Kind: static method of Astronomy/MoonCalc
Returns: string - - Up or down emoji

ParamType
altitudenumber
highestDate

Astronomy/MoonCalc.MoonDataExt : Object

Kind: static typedef of Astronomy/MoonCalc
Properties

NameType
datestring
timestring
illuminationstring
phasestring
phaseIdstring
emojistring
parallacticAnglenumber
anglenumber
positionAstroPosition
nextObject

Astronomy/MoonCalc.MoonData : Object

Kind: static typedef of Astronomy/MoonCalc
Properties

NameTypeDescription
positionAstroPosition
nextObject
next.newMoonstringDate of the next new moon.
next.fullMoonstringDate 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 }

ParamType
dateDate
latitudenumber
longitudenumber
timezoneIdstring

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 }

ParamType
dateDate
latitudenumber
longitudenumber
timezoneIdstring

Astronomy/SunCalc.getSolarTime(date, lng, offsetSign, offset) ⇒ string

Kind: static method of Astronomy/SunCalc
Returns: string - Local time in "HH:mm" format

ParamTypeDescription
dateDate
lngnumber
offsetSignstring"+" or "-"
offsetnumberUTC 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}

ParamType
latitudenumber
longitudenumber

Astronomy/SunCalc.getIsNight(lat, lon, timezoneId, date, dateStr) ⇒ boolean

Kind: static method of Astronomy/SunCalc
Returns: boolean - true if it's night, false otherwise

ParamType
latnumber
lonnumber
timezoneIdstring
datenumber | Date
dateStrstring

Astronomy/SunCalc.getPhase(altitude, noon) ⇒ string

Kind: static method of Astronomy/SunCalc
Returns: string - The phase of the sun based on its altitude

ParamType
altitudenumber
noonstring

Geolocation


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.
ParamTypeDescription
apiKeystringGoogleMaps API key.
latnumber
lngnumber

Geolocation.ResolvedLocation : Object

Kind: static typedef of Geolocation
Properties

NameTypeDescription
latitudenumber
longitudenumber// Address
sublocalitystring
localitystring
countrystring
country_shortstring
formatted_addressstring

Geolocation.LocalTimeData : Object

Kind: static typedef of Geolocation
Properties

NameTypeDescription
timeDateThe local time.
timeStrstringThe formatted local time string.
timezonestringThe timezone name.
timezoneIdstringThe timezone ID.
offsetnumberThe UTC offset in hours.
offsetSignstringThe sign of the offset ('+' or '-').
dstOffsetnumberThe DST offset in hours.

OpenMeteo

Use the OpenWeather forecast API


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}

ParamType
latnumber
lonnumber
refreshIntervalMinnumber

OpenMeteo.exports.useForecastDaily(lat, lon, refreshIntervalMin) ⇒ ForecastData

Custom hook to fetch daily forecast (10 days) data from OpenMeteo API.

https://api.open-meteo.com/v1/forecast?timezone=auto&latitude=36.6644363&longitude=-4.5108962&forecast_days=10&daily=weathercode

Kind: static method of OpenMeteo
Returns: ForecastData - {data, isLoading, isError, apiUrl}

ParamType
latnumber
lonnumber
refreshIntervalMinnumber

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}

ParamTypeDescription
locationObject
dayNumnumberNumber 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 }

ParamType
codeany
precipitationnumber
nightboolean
darkboolean

OpenMeteo.ForecastData : Object

Kind: static typedef of OpenMeteo
Properties

NameTypeDescription
dataanyForecast data
isLoadingbooleanLoading state
isErroranyError state
apiUrlstringAPI URL

Utils


Utils.directions : Array.<Compass>

English compass designations

Kind: static constant of Utils
Properties

NameTypeDescription
shortstringShort compass designation
fullstringFull compass designation

Utils.directionsEs : Array.<Compass>

Spanish compass designations

Kind: static constant of Utils
Properties

NameTypeDescription
shortstringShort compass designation
fullstringFull 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}

ParamTypeDescription
degreesnumber
languagestringLanguage 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}

ParamType
precipitationSumTodaynumber
precipitationSumTomorrownumber
showersSumTodaynumber
showersSumTomorrownumber

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}

ParamType
precipitationnumber
showersnumber

Utils.exports.WindArrow(props)

SVG arrow indicating wind direction.

Kind: static method of Utils
Component: JSX

ParamTypeDescription
propsObjectComponent props.
props.degnumberWind direction in degrees (0 = North, 90 = East, etc.).
props.sizestringTailwind CSS size class (e.g., 'size-10')
props.strokeWidthnumberStroke width of the arrow (range: 1–6).
props.classNamestringAdditional 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.

ParamTypeDescription
degnumberWind 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

ParamTypeDescription
speednumberWind speed in km/h

Utils.Compass : Object

Kind: static typedef of Utils
Properties

NameTypeDescription
shortstringShort compass designation
fullstringFull compass designation

Utils.AlertLevel : Object

Kind: static typedef of Utils
Properties

NameTypeDescription
levelNumnumberThe alert level number.
levelstringThe alert level string (e.g., "red", "orange", "yellow").
precipitationnumberThe precipitation threshold for the alert level.
showersnumberThe showers threshold for the alert level.

Utils.WindLevel : Object

Kind: static typedef of Utils
Properties

NameTypeDescription
idnumberLevel ID
speednumberMinimum wind speed for this level
colorstringColor representing this level
txstringText representing this level
txEnstringText representing this level

Utils/TimeDateStr

Helpers for get date and time formeted strings


Utils/TimeDateStr.dateFormat(date) ⇒ string

Returns a date as a formated string.

Kind: static method of Utils/TimeDateStr
Returns: string - La fecha formateada.

ParamTypeDefaultDescription
dateDatenew 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.

ParamTypeDefault
dateDate
secbooleanfalse

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

ParamTypeDefault
secbooleanfalse

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.

ParamTypeDefaultDescription
timeZonestringThe timezone string (e.g., 'America/New_York').
dateDate | numbernew Date()The date object to format. Defaults to the current date.

1.1.15

7 months ago

1.1.14

7 months ago

1.1.13

7 months ago

1.1.12

7 months ago

1.1.11

7 months ago

1.1.10

7 months ago

1.1.9

7 months ago

1.1.8

7 months ago

1.1.7

7 months ago

1.1.6

7 months ago

1.1.5

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago