
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
dark-sky-client-ts
Advanced tools
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.
npm install dark-sky-client-ts --save
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"
});
}
const dsApi = new DarkSkyApiClient(apiKey, params);
string
) - Dark Sky API key.DarkSkyRequestObject
) - optional params for API request.async get(
field?: DarkSkyRootField, // Which section of the data you want. If ommitted, returns all.
params?: DarkSkyRequestObject // If ommitted, uses client's declared params.
)
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.
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.
time
is used for Time Machine requests and is reset to null after each call.{
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.
}
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
}
FAQs
Simple typescript wrapper for dark sky weather api.
We found that dark-sky-client-ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.