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

countanimator

v1.2.1

Published

A lightweight and dependency-free number counter that animates numbers incrementing or decrementing.

Downloads

3

Readme

CountAnimator

A lightweight and dependency-free number counter that animates numbers incrementing or decrementing, which allows you to control the 'speed' too!

Usage

  1. Either include the CDN
https://unpkg.com/[email protected]/dist/countanimator.js

or install it as an NPM package.

npm i countanimator
  1. Import the package (you can skip this step if you've included the CDN script).
import CountAnimator from 'countanimator';
  1. Pass the necessary arguments to the constructor.

The constructor takes two arguments - an HTML element and an optional object (consists of the following keys: start, end, steps, delay).

  • selector - selector for the element that should output the number (required)

  • start - number to start counting from (default value is 0)

  • end - number to end counting at (default value is 100)

  • steps - number of steps to increment or decrement by. Only whole numbers are allowed (ie. 0, 1, 2, 3, 4, ...) (default value is 1)

  • delay - number to indicate the delay between increments or decrements. You can think of this as the "speed" of the number counter. Negative numbers cannot be used. Maximum value is 100 (default value is 50)

const options = {
   start: 0,
   end: 50,
   steps: 1,
   delay: 70
};
  1. Instantiate the CountAnimator class and pass in the arguments object.
const countAnimator = new CountAnimator(selector, options);
  1. Initialize the counter when you're ready by invoking .init().
countAnimator.init();

Example

Example of a simple program that counts from 0 to 50 when you click a button:

import CountAnimator from 'countanimator'; // not required if using CDN

const btn = document.querySelector('button');

const options = {
  start: 0,
  end: 50,
  steps: 1,
  delay: 70
};

const countAnimator = new CountAnimator('div', options);

btn.addEventListener('click', () => {
  countAnimator.init();
});