Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DarkSky

A class based wrapper for a DarkSkyClient

Example usage:

const darkSky = new DarkSky("api-token")

const current = async () => {
  const result = await darkSky.currentConditions(42, -42, { units: Units.CA })
  // ... Handle result
}

Example chaining usage:

const darkSky = new DarkSky("api-token")

const hourlyForecast = darkSky.chain(42, -42).extendHourly().onlyHourly()

async function getHourlyForecast(lat: number, long: number): HourlyDataBlock {
  const result = await hourlyForecast.execute()
  if (!result.hourly) {
    throw Error("Hourly can still be undefined if DarkSky doesn't return it")
  }
  return result.hourly
}

Hierarchy

  • DarkSkyBase
    • DarkSky

Index

Constructors

constructor

  • new DarkSky(token: string, __namedParameters?: { exclude: undefined | Exclude[]; extendHourly: boolean; lang: Language; requestConfig: undefined | AxiosRequestConfig; units: Units }): DarkSky
  • Create the base class.

    Parameters

    • token: string

      DarkSky developer API token.

    • Default value __namedParameters: { exclude: undefined | Exclude[]; extendHourly: boolean; lang: Language; requestConfig: undefined | AxiosRequestConfig; units: Units } = {}
      • exclude: undefined | Exclude[]
      • extendHourly: boolean
      • lang: Language
      • requestConfig: undefined | AxiosRequestConfig
      • units: Units

    Returns DarkSky

Properties

Protected Readonly client

Client for interacting with the API.

Protected requestParams

requestParams: RequestParams

Optional request paramaters.

Protected Readonly token

token: string

DarkSky developer API token.

Methods

chain

  • Create a DarkSky request using method chaining.

    see

    createRequestChain

    Parameters

    • latitude: NumberString

      The latitude of a location (in decimal degrees).

    • longitude: NumberString

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns DarkSkyRequestChain

current

  • Gets the current weather conditions, excluding all other datablocks.

    Helper function for setting exclude=minutely,daily,hourly

    • Note: Will throw an error if DarkSky doesn't return a currently data block for the request.
    throws

    HttpException if Forecast.currently doesn't exist.

    Parameters

    • latitude: number

      The latitude of a location (in decimal degrees).

    • longitude: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<CurrentForecast>

    Current forecast conditions.

day

  • Get the forecast for day, excluding all other datablocks.

    Helper function for setting exclude=currently,daily,minutely

    • Note: Will throw an error if DarkSky doesn't return a hourly data block for the request.
    throws

    HttpException if Forecast.hourly doesn't exist.

    Parameters

    • latitude: number

      The latitude of a location (in decimal degrees).

    • longitude: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<DayForecast>

    Forecast for the day.

forecast

  • Gets the current forecast.

    Parameters

    • latitude: number

      The latitude of a location (in decimal degrees).

    • longitude: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<Forecast>

    Current forecast.

hour

  • Get the forecast for hour, excluding all other datablocks.

    Helper function for setting exclude=currently,daily,hourly

    • Note: Will throw an error if DarkSky doesn't return a Minutely data block for the request.
    throws

    HttpException if [[Forecast.Minutely]] doesn't exist.

    Parameters

    • latitude: number

      The latitude of a location (in decimal degrees).

    • longitude: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<HourForecast>

    Forecast for the hour.

timeMachine

  • Gets the forecast for a specified date.

    Parameters

    • latitude: number

      The latitude of a location (in decimal degrees).

    • longitude: number

      The longitude of a location (in decimal degrees).

    • time: TimeMachineDate

      Specific time to get the weather for.

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<Forecast>

    Forecast for the specified date.

week

  • Get the forecast for week, excluding all other datablocks.

    Helper function for setting exclude=currently,minutely,hourly

    • Note: Will throw an error if DarkSky doesn't return a daily data block for the request.
    throws

    HttpException if Forecast.daily doesn't exist.

    Parameters

    • latitude: number

      The latitude of a location (in decimal degrees).

    • longitude: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<WeekForecast>

    Forecast for the week.

Generated using TypeDoc