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

climate.js

v1.1.0

Published

Lightweight JavaScript package to theme your website based on the current weather

Downloads

1

Readme

Climate.js

Build Status

Climate Banner

Climate.js takes raw weather data and offers a variety of customizable color schemes and visualizers to reflect the current weather. Add extra flair to location-based webapps, or perhaps give a homey feel with weather from your hometown- anything to help make your site more responsive :)

What's new in 1.1

  • Climate.js is now built for standalone use! The usage of <script> tags has changed to match the module usage (e.g. climate.initClimate() instead of initClimate()). See Usage for more information.
  • Toggle Mode: Instead of the usual 'color' mode, you can opt to show/hide elements based on the current weather.
  • Option to change background color instead of foreground color
  • Lots of bug fixes!

Features

  • Weather data collection (local or manual) from OpenWeatherMap
  • Get rough user location without prompt using ipinfo
  • Set custom configurations for class names, colors, and weather sets
  • Run once or at a specified interval
  • No dependencies!

Coming Soon

  • Seasons
  • Time (night vs. day)
  • Sunset/sunrise gradient skies
  • Wind/rain/snow effects
  • MOAR CUSTOMIZATION
  • Want something else? Create an issue!

Install

NPM: https://npm.js/package/climate.js npm install --save climate.js

Download: Get the latest version here!

CDN: Coming Soon!

Usage

IMPORTANT NOTE: climate.min.js is a standalone module for use in default environments. If you're using babel/browserify/webpack, import from climate.js instead.

  1. Include the script using your preferred method:

Script Tag

<script src="./path/to/climate.min.js"></script>

Require

const climate = require('climate.js');

es6

import * as climate from 'climate.js';
  1. Initialize the script.

If userLocation is set to true, the user will be prompted for location permissions when initClimate() is run. Note: Requires a web browser to access geolocation tools!

If userLocation is set to false, the location parameter is required.

climate.initClimate({
    theme: 'path/to/climate.json',
    userLocation: false,
    location: 'San Francisco',
    interval: 6000,
    mode: 'weather',
    weatherAPIKey: 'insertyourkeyherefromopenweatherapi'
})

This config will manually set the city to San Francisco, and update the color scheme every minute based on the type of weather (e.g. sunny or rainy). More config options can be found in Options.

  1. Create your divs.

Color Mode: Changes div colors based on weather.

<div class="climate-[indicator]">Content</div>

You can also opt to change the background-color instead:

<div class="climate-[indicator]-background">Background</div>

Replace [indicator] with your custom indicator as specified in climate.json. For example:

{
  "weather": {
    "clear": {
      "primary": "#FFFFFF"
    }
    ...
  }
}

will use the climate-primary class. You may add as many indicators as you wish, as long as all of your weather patterns have the same indicators.

Toggle Mode: Will show or hide divs based on the weather.

<div class="climate-toggle climate-clear">Content</div>
<div class="climate-toggle climate-clouds">More Content</div>

In the above example, if the weather is currently clear, only the top div will be visible.

Toggle mode can also be used for temperatures, if specified (e.g. climate-cold).

  1. Create climate.json. A default config is provided here if you want to get up and running ASAP. If you're too good for the default and want to make your own theme, go to Custom Theming.

Run Example Code

Examples are provided in the examples folder. In order to run them, clone this repository, npm install, then npm run example:<exampleName> where is replaced by the name of the example (e.g. nature).

Options

| Option | Description | Default | |--------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |----------------- | | theme | Path to your climate.json theme configuration. (Get the default config here) | null | | weatherAPIKey | API key to openweathermap. REQUIRED for use! | null | | userLocation | True if you wish to use the user's location; false if you want to use your own location. | false | | location | Default location (name of city). Required if userLocation is false, but it is also highly recommended as a fallback. | 'San Francisco' | | useIP | If true, uses ipinfo.io to get the user's location without needing to prompt for location permission. Requires API key. | false | | ipAPIKey | API key to ipinfo.io. Not required unless useIP and userLocation are both true. | null | | interval | Interval, in milliseconds, between each weather fetch. Set to 0 to only fetch once. | 0 | | mode | color mode changes the color of the elements, while toggle mode will show an element only if the weather pattern matches. all will use both. | 'all' |

Custom Theming

Top-level Fields

In terms of priority, sun > weather > temperature.

All indicators (e.g. primary or sky) are fully customizable and can be whatever you wish, as long as they are consistent throughout each weather pattern.

A default config for reference is provided here

| Field | Description | |------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | defaults | Specifies the default weather/temperature if an unconfigured weather pattern appears. | | use | Specifies what OpenWeatherMap parameter to use for differentiating weather patterns. Valid inputs are id, main, and description for weather; temp, pressure, humidity, temp_min, or temp_max for temperature. See the OpenWeatherMap API list for more info. | | weather | Specifies color themes for weather patterns, using the specified parameter from use.weather. See the OpenWeatherMap API list for valid parameters. | | temperature | Specifies color themes for temperature ranges, using the specified parameter from use.weather. See the OpenWeatherMap API list for valid parameters. Specify min and max temperature values inside each self-labeled temperature range. Also specify units (either Fahrenheit or Celsius). If temperature styles are given, they will be used over weather pattern styles. | | sun | Two parameters: rise and set, corresponding to sunrise and sunset colors. Specify timeRange which is the time, in minutes, before and after sunset/rise time to display sunset colors. |