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

angular-dark-sky

v0.0.5

Published

angular.js provider for fetching current weather and forecast data using the dark sky api

Downloads

7

Readme

angular-dark-sky

Angular.js 1.x provider for fetching current and forecasted (7 days) weather data using the Dark Sky API.

An API key from darksky.net/dev/ is required in order to use this provider. See https://darksky.net/dev/ for further information.

A directive is also included that maps the Dark Sky weather condition IDs to the excellent weather-icons by Erik Flowers.

Getting started

  • Include Scripts - the provider script should be included after the AngularJS script:

     <script type='text/javascript' src='path/to/angular.min.js'></script>
     <script type='text/javascript' src='path/to/angular-dark-sky.js'></script>
  • Configure the provider by setting the API key:

     angular.module('app', ['app.weather']);
    
     ... 
    
     angular.module('app').config(['darkSkyProvider', function(darkSkyProvider) {
     	darkSkyProvider.setApiKey('XXXXXXX');
     }]);
  • Specify dependency - ensure that your module specifies dark-sky as a dependency:

     angular.module('app.weather', ['dark-sky'])
     ...
  • inject service - inject darkSky service into your controller/directive/service/etc:

     angular.module('app.weather', ['dark-sky'])
     	.controller('WeatherCtrl', WeatherCtrl);
    
     WeatherCtrl.$inject = ['$q', 'darkSky'];
    		
     function WeatherCtrl($q, darkSky) {
     	activate();
    
     	// log current weather data
     	function activate() {
     		getNavigatorCoords()
     			.then(function(position) {
     				darkSky.getCurrent(position.latitude, position.longitude)
     					.then(console.log)
     					.catch(console.warn);
     			})
     			.catch(console.warn);
     	}
    
     	// Get current location coordinates if supported by browser
     	function getNavigatorCoords() {
     		var deferred = $q.defer();
    
     		// check for browser support
     		if ("geolocation" in navigator) {
     			// get position / prompt for access
     			navigator.geolocation.getCurrentPosition(function(position) {
     				deferred.resolve(position.coords);
     			});
     		} else {
     			deferred.reject('geolocation not supported');
     		}
     		return deferred.promise;
     	}
     });

Provider API

The darkSky provider exposes the following Dark Sky API methods to fetch data:

  • darkSky.getCurrent(43.0667, 89.4000): Get current weather data.
  • darkSky.getDailyForecast(43.0667, 89.4000): Get forecasted weather data in days.
  • darkSky.getHourlyForecast(43.0667, 89.4000): Get forecasted weather data in hours.
  • darkSky.getMinutelyForecast(43.0667, 89.4000): Get forecasted weather data in minutes.
  • darkSky.getAlerts(43.0667, 89.4000): Get alerts data.
  • darkSky.getFlags(43.0667, 89.4000): Get flags data.
  • darkSky.getUnits(): Get response units object (i.e. { temperature: 'f', windSpeed: 'mph', [...] }).

Both methods take latitude and longitude and return an angular Promise which resolves with the data object as retrieved from Dark Sky. The promise is rejected if there was an error. See data points for an explaination of the data structure retrieved.

Options

All API methods (except getUnits) take an additional options object as the 3rd parameter.

i.e: darkSky.getCurrent(43.0667, 89.4000, { extend: true })

Supported options include:

Configuration

  • darkSkyProvider.setApiKey('XXXXXXX'): Set Dark Sky API key.
  • darkSkyProvider.setUnits('us'): Set unit type for response formatting, see the list of supported units. Defaults to 'us'.
  • darkSkyProvider.setLanguage('en'): Set language for response summaries, see the list of supported languages. Defaults to 'en'.

Directive

Using the directive is simple, just pass the weather condition ID:

<dark-sky-icon icon="{{ item.icon }}"></dark-sky-icon>

For the directive to be able to display any icons, please install the weather-icons package.