npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dark-sky-client-ts

v1.0.16

Published

Simple typescript wrapper for dark sky weather api.

Downloads

13

Readme

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
}