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

animated-weather-icon

v1.2.0

Published

Add an animated weather icon to a render target

Downloads

12

Readme

Animated Weather Icon

Demo: https://animated-weather-icon.netlify.com/

GitHub release Travis tests Codacy Badge GitHub issues GitHub pull requests Github last commit

Install

You can install via npm or yarn.

npm

npm install --save animated-weather-icon

yarn

yarn add animated-weather-icon

Usage

Importing

You can import using ES6 imports.

import { AnimatedWeatherIcon } from 'animated-weather-icon';

Initialisation

To use the animated weather icon, you must create a new instance of the icon and provide it with a render target.

import { AnimatedWeatherIcon } from 'animated-weather-icon';

const renderTarget = document.querySelector('.my-render-target');

const icon = new AnimatedWeatherIcon(renderTarget);

Displaying a weather type

To display a weather type you must call setType on your icon instance.

The setType method takes three arguments type, and optionally time and disableAnimations. It returns a Promise that resolves when the icon finished animating in.

If using TypeScript you can import enums for the type and time and pass them as arguments like so:

import { AnimatedWeatherIcon, AnimatedWeatherTypes, AnimatedWeatherTimes } from 'animated-weather-icon';

const icon = new AnimatedWeatherIcon(renderTarget);

icon.setType(AnimatedWeatherTypes.Clear, AnimatedWeatherTimes.Day);

AnimatedWeatherTypes

| TypeScript enum | Vanilla JS string | | -------------------------- | ------------------------------- | | Clear | 'Clear' | | Overcast | 'Overcast' | | BrokenClouds | 'Broken Clouds' | | Cloudy | 'Cloudy' | | Fog | 'Fog' | | LightDrizzle | 'Light Drizzle' | | Drizzle | 'Drizzle' | | HeavyDrizzle | 'Heavy Drizzle' | | LightDrizzleShowers | 'Light Drizzle Showers' | | DrizzleShowers | 'Drizzle Showers' | | HeavyDrizzleShowers | 'Heavy Drizzle Showers' | | LightRain | 'Light Rain' | | Rain | 'Rain' | | HeavyRain | 'Heavy Rain' | | LightRainShowers | 'Light Rain Showers' | | RainShowers | 'Rain Showers' | | HeavyRainShowers | 'Heavy Rain Showers' | | ThunderStorm | 'Thunder Storm' | | ThunderStormLightRain | 'Thunder Storm Light Rain' | | ThunderStormRain | 'Thunder Storm Rain' | | ThunderStormHeavyRain | 'Thunder Storm Heavy Rain' | | ThunderStormLightDrizzle | 'Thunder Storm Light Drizzle' | | ThunderStormDrizzle | 'Thunder Storm Drizzle' | | ThunderStormHeavyDrizzle | 'Thunder Storm Heavy Drizzle' | | Hail | 'Hail' | | Sleet | 'Sleet' | | SleetShowers | 'Sleet Showers' | | LightSnow | 'Light Snow' | | Snow | 'Snow' | | HeavySnow | 'Heavy Snow' | | LightSnowShowers | 'Light Snow Showers' | | SnowShowers | 'Snow Showers' | | HeavySnowShowers | 'Heavy Snow Showers' |

AnimatedWeatherTimes

| TypeScript enum | Vanilla JS string | | --------------- | ----------------- | | Day | 'Day' | | Night | 'Night' |

Hiding the weather icon

To display a hide then weather icon you need to call unsetIcon on your icon instance.

The unsetIcon method returns a Promise that resolves when the icon finished animating out.

In this example we will wrap our calls in an async function so we can use await on the promise instances that setType and unsetIcon return. We can use this to wait for the setType animation to finish, wait for 2 seconds, and then hide the icon using unsetIcon.

import { AnimatedWeatherIcon, AnimatedWeatherTypes, AnimatedWeatherTimes } from 'animated-weather-icon';

async function myFunction() {
  const icon = new AnimatedWeatherIcon(renderTarget);

  await icon.setType(AnimatedWeatherTypes.Clear, AnimatedWeatherTimes.Day);

  setTimeout(async () => {
    await icon.unsetIcon();

    // do something
  }, 2000);
}

myFunction();

Changing the weather icon after one has been set

You can change the weather type after it has been set, as if the icon knows it already has a different icon set, it will call unsetIcon for you.

import { AnimatedWeatherIcon, AnimatedWeatherTypes, AnimatedWeatherTimes } from 'animated-weather-icon';

async function myFunction() {
  const icon = new AnimatedWeatherIcon(renderTarget);

  await icon.setType(AnimatedWeatherTypes.Clear, AnimatedWeatherTimes.Day);

  setTimeout(() => {
    icon.setType(AnimatedWeatherTypes.Overcast, AnimatedWeatherTimes.Day);
  }, 2000);
}

myFunction();

Forcing icons to remove immediately

The unsetIcon method has an optional force argument that you can pass to force the icon to hide immediately without animating out.

import { AnimatedWeatherIcon, AnimatedWeatherTypes, AnimatedWeatherTimes } from 'animated-weather-icon';

async function myFunction() {
  const icon = new AnimatedWeatherIcon(renderTarget);

  await icon.setType(AnimatedWeatherTypes.Clear, AnimatedWeatherTimes.Day);

  setTimeout(() => {
    void icon.unsetIcon(true);

    // do something
  }, 2000);
}

myFunction();

Disabling animations

You can disable animations by passing true as the third argument to setType.

import { AnimatedWeatherIcon, AnimatedWeatherTypes, AnimatedWeatherTimes } from 'animated-weather-icon';

async function myFunction() {
  const icon = new AnimatedWeatherIcon(renderTarget);

  await icon.setType(AnimatedWeatherTypes.Clear, AnimatedWeatherTimes.Day, true);

  // do something
}