Socket
Socket
Sign inDemoInstall

dark-sky-client-ts

Package Overview
Dependencies
2
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dark-sky-client-ts

Simple typescript wrapper for dark sky weather api.


Version published
Weekly downloads
12
increased by20%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

dark-sky-client-ts

A simple typescript client for Dark Sky API.

All types based off what is found in the official API documentation.

DISCLAIMER: This does not use a proxy and as such does not hide your api key during requests. If you would like to use a proxy approach there are several other packages that offer it.

Installation

npm install dark-sky-client-ts --save

Usage

import { DarkSkyApiClient } from "dark-sky-client-ts"; // And any other types needed.

const dsApi = new DarkSkyApiClient(apiKey, params);

async getWeather() {
    const weatherIsh = await dsApi.get(); // requires type assertion.
    const weather = await dsApi.getWeather(); // resolves type.
}

async getHourly() {
    const hourlyIsh = await dsApi.get("hourly"); // requires type assertion.
    const hourly = await dsApi.getHourly(); // resolves type.
}

async getDaily() {
    const daily = await dsApi.get("daily", {
        latitude: -38.590451,
        longitude: 175.541561,
        lang: "zh",
        units: "uk2"
    });
}

DarkSkyApiClient

const dsApi = new DarkSkyApiClient(apiKey, params);
  • apiKey (string) - Dark Sky API key.
  • params (DarkSkyRequestObject) - optional params for API request.
Methods
async get(
    field?: DarkSkyRootField, // Which section of the data you want. If ommitted, returns all.
    params?: DarkSkyRequestObject // If ommitted, uses client's declared params.
  )
Note: Responses are stored for the duration of the refresh rate, unless it is a Time Machine request.
getWeather(): Promise<DarkSkyResponseObject> // Returns full api response.
getCurrently(): Promise<DarkSkyCurrentlyResponse> // Returns currently field from api response.
getMinutely(): Promise<DarkSkyDataBlockObject> // Returns minutely field from api response.
getHourly(): Promise<DarkSkyHourlyBlockObject> // Returns hourly field from api response.
getDaily(): Promise<DarkSkyDailyBlockObject> // Returns daily field from api response.
getAlerts(): Promise<DarkSkyAlertObject[]> // Returns alerts field from api response.
getFlags(): Promise<DarkSkyFlagsObject> // Returns flags field from api response.
getRequestParams(): DarkSkyRequestObject // Returns current request params.
setRequestParams(request: DarkSkyRequestObject) // Sets current request params.
getRefreshRate(): number // Gets current refresh rate for data in minutes.
setRefreshRate(refreshRate: number) // Sets current refresh rate for data in minutes. Minimum is 30.
setCoords(lat: number, lng: number) // Sets current request latitude & longitude.
setExcludes(excludes: DarkSkyRootField[]) // Sets which root field to exclude from response.
Note: minutely is excluded by default, because c'mon, really?
setLang(lang: DarkSkySupportedLanguage) // Sets the preferred language from supported languages.
setUnits(units: DarkSkyUnitType) // Sets the preferred units of measurements from supported units.
setTime(time: number | string) // Sets time for Time Machine requests, parsed internally.
                                // Number should be milliseconds.
                                // String should be ISO string.
Note: time is used for Time Machine requests and is reset to null after each call.

DarkSkyRequestObject

{
  latitude?: number; // Required. Set either in constructor or using setCoords client method.
  longitude?: number; // Required. Set either in constructor or using setCoords client method.
  exclude?: DarkSkyRootField[]; // List of root fields to exclude from returned data.
  lang?: DarkSkySupportedLanguage; // Language string that matches supported list.
  units?: DarkSkyUnitType; // Unit of measurement that matches supported list.
  timeSeconds?: number; // Used for time machine requests. Pass in milliseconds,
                        // as conversion to UNIX is handled internally.
  timeString?: string;  // Used for time machine requests. Pass in ISO string.
                        // Setting of this field and timeSeconds are exclusive to each other.
}

DarkSkyResponseObject

For the sake of brevity, I'm going to go ahead and say that all reponses should match what is outlined in the official API documentation. But for a general type skeleton:

DarkSkyResponseObject {
    ...
    DarkSkyCurrentlyResponse // currently
    DarkSkyDataBlockObject { // minutely
        ...
        DarkSkyDataPointObject[]
    }
    DarkSkyHourlyBlockObject { // hourly
        ...
        DarkSkyHourlyResponse[]
    }
    DarkSkyDailyBlockObject { // daily
        ...
        DarkSkyDailyResponse[]
    }
    DarkSkyAlertObject[] // alerts
    DarkSkyFlagsObject // flags
}

Keywords

FAQs

Last updated on 29 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc