Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dark-sky-skeleton

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dark-sky-skeleton

barebones dark sky weather api - for client or server side js

  • 0.1.41
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

dark-sky-skeleton

Based on Elias Hussary's dark-sky.

An isomorphic barebones js wrapper library for Dark Sky API (previously known as Forecast.io). See Dark Sky developer docs: https://darksky.net/dev/docs.

For a more robust solution see dark-sky-api.

Install it

 npm install dark-sky-skeleton

Client Side Setup

Import it

import DarkSkySkeleton from 'dark-sky-skeleton';

Initialize it

DarkSkySkeleton(apiKey, proxy)

const api = new DarkSkySkeleton('your-dark-sky-api-key');
Experimental (untested - help wanted)

The above is simple and great for testing, but it exposes your api key in client side requests. Using a server-side proxy to make the actual api call to dark sky and is highly suggested as this hides the API key from client side requests [ref].

The proxy in this would receive a request issued by dark-sky-api and attach this query to a base uri (like the following: https://api.darksky.net/forecast/your-api-key) prior to returning a final request.

import DarkSkySkeleton from 'dark-sky-skeleton';
const api = new DarkSkySkeleton(false, '//base-url-to-proxy/service');

Server Side Setup

Import it

const DarkSkySkeleton = require('dark-sky-skeleton');

Initialize it

DarkSkySkeleton(apiKey, proxy)

const api = new DarkSkySkeleton('your-dark-sky-api-key', true);

Passing true as the proxy parameter indicates that the caller is server-side (and essentially a proxy).

Use it

darkSky.latitude(lat)
  .longitude(long)
  .units('us')
  .language('en')
  .time('2000-04-06T12:20:05') // moment().year(2000).format('YYYY-MM-DDTHH:mm:ss')
  .extendHourly(true)
  .get();
  .then(data => console.log(data));

Feel free to omit setting of latitude and longitude for subsequent calls i.e.:

darkSky.latitude(lat)
  .longitude(long)
  .get()
  .then(data => console.log(data));

darkSky.get().then(data => console.log(data));

Make use of excludes

"Exclude some number of data blocks from the API response. This is useful for reducing latency and saving cache space (see 'Request Parameters')."

const excludes = ['alerts', 'currently', 'daily', 'flags', 'hourly', 'minutely'],
  exludesBlock = excludes.filter(val => val != 'currently').join(',')
darkSky.latitude(lat)
  .longitude(long)
  .exclude(excludesBlock)
  .get()
  .then(data => console.log(data));

Keywords

FAQs

Package last updated on 23 Jul 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc