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

darkskyjs-lite

v0.1.6

Published

A promise-based wrapper for requesting weather data from DarkSky.net

Downloads

38

Readme

darkSkyjs-lite

A javascript api for darksky.net

Build Status


Special notice

This is a smaller version of DarkSkyJS that only deals with current (the currently endpoint) weather conditions, rather than the hourly and daily ones.

The purpose of this version is to reduce the file size of the library and remove the dependencies, specifically:

  • Moment.JS, which could be considered quite large in proportion to the number of its features that are used
  • Promise polyfill, which is now supported in most browsers with the exception of IE11 and Opera Mini.

Features

This package is designed to provide:

  • A simple API for making multiple simultaneous requests
  • A promised-based request that only returns data when all requests are successful
  • A callback that outputs the data

It differs from the original library in three ways:

  • It only accepts, and returns, arrays of locations/conditions - this is a breaking change
  • Each get function's name matches the property name of what the DarkSky service returns
  • Missing data points have been included, see Recent Updates seciton below:

Recent updates

14/10/2019 In v0.1.0 there's improved error checking for the PROXY_SCRIPT URL - Invalid URLs now return warning. The response JSON is also checked for validity.

The following data points have been added since 29/07/2017:

  • moonPhase
  • precipAccumulation
  • apparentTemperatureMax
  • apparentTemperatureMaxTime
  • apparentTemperatureMin
  • apparentTemperatureMinTime
  • precipIntensityMax
  • precipIntensityMaxTime
  • temperatureMaxTime
  • temperatureMinTime
  • uvIndex
  • uvIndexTime
  • windGust
  • windGustTime

The following data points were added when first published on NPM

  • nearestStormDistance
  • nearestStormBearing

Getting Started

If you haven't already, create a developer account here https://darksky.net/dev/.

It is recommended you install via NPM where dependencies will be loaded automatically.

npm install darkskyjs

darkskyjs is configured to work with both AMD and CJS applications.

If you're using Webpack, Browserify or some other CJS module loader simply require the module like so

var Darksky = require('darkskyjs');

or using ES6 import, like so

import Darksky from 'darkskyjs'

and use the Darksky constructor like so:

var darkSky = new DarkSky()

You can then use the method listed below to retrieve location specific weather data.

  • getCurrentConditions

If you're using Require.JS you will need to download momentjs and es6-promise.

A server side proxy is required for this to work. So create a file that will contain your key and be careful not to commit it to a public code base.

Here's an example PHP one. Replace the value of $api_key with your valid key.

<?php
// File Name: proxy.php

$api_key = 'b962d5ee80be5293a234b69fb975629c';

$API_ENDPOINT = 'https://api.darksky.net/forecast/';
$url = $API_ENDPOINT . $api_key . '/';

if(!isset($_GET['url'])) die();
$url = $url . $_GET['url'];
$url = file_get_contents($url);

print_r($url);

Location data

darkskyjs can handle multiple location requests. Simply pass in an array of requests (to one of the three methods listed above) to get data for multiple locations.

Each request must comprise of two key/value pairs: latitude and longitude. Optionally you can pass in a place name as a reference which will be returned should the request be successful e.g.

[{latitude: 51.507351, longitude: -0.127758, name: 'London'}]

If you don't pass an array it will create one for you, but it's best to do so for consistency and to avoid confusion as an array is what you'll get back.

Returned data

This API returns a set of functions that allow you to access the raw data, rather then the raw data itself. Each function is named in exactly the same way as its respective data point e.g. ozone() will return the value for ozone.

getCurrentConditions returns an array of condition arrays. Each array represents one of locations you requested data for.

In order to match the locations that were supplied with what's returned it is recommended that the name property be used. A callback is then used to supply the returned data. For example:

darkSky.getCurrentConditions(
  [
    // location object(s)
    {
      latitude: 51.507351,
      longitude: -0.127758,
      name: 'London'
    }
  ],
  // callback
  function(conditions) {
    for (var i = 0, length = conditions.length; i < length; i++) {
      if (conditions[i].name === 'London') {
        console.log(conditions[i].cloudCover());
      }
    }
  }
);

Dependencies

This package has no dependencies

Plans

Add a method for retrieving alerts