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

counterup2

v2.0.2

Published

Counter-Up2 is a lightweight module that counts up to a targeted number when the number becomes visible.

Downloads

14,254

Readme

Counter-Up2

Build Status

Counter-Up2 demo gif

Example Pen: https://codepen.io/bfintal/pen/zYzOGpZ

Counter-Up is a lightweight (only 1.3kb gzipped) module with zero dependencies that counts up to a targeted number when the number becomes visible.

What Can You Count Up?

  • Floats: 1.234
  • Integers: 1234
  • With commas: 1,234.56
  • Commas and dots: 12.345,67
  • With non-numeric characters: $1,234.56
  • Multiple countable values: 604,800 seconds in 10,080 minutes in 168 hours in 7 days

Usage

Usage as Module

Install

npm install --save counterup2

HTML

<div class="counter">1,123,456 downloads</div>

JS

Importing as a module will import the modern JavaScript code.

import counterUp from 'counterup2'

const el = document.querySelector( '.counter' )

// Start counting, do this on DOM ready or with Waypoints.
counterUp( el, {
    duration: 1000,
    delay: 16,
} )

If you want to stop the counter immediately:

// Stop counting. This brings back the original value.
counterUp( el, { action: 'stop' } )

Usage in Browser

Example Pen: https://codepen.io/bfintal/pen/zYzOGpZ

HTML

<script src="https://unpkg.com/[email protected]/dist/index.js">	</script>

<div class="counter">1,123,456.78</div>

JS

const { counterUp } = window.counterUp

const el = document.querySelector( '.counter' )

// Start counting, typically you need to call this when the 
// element becomes visible, or whenever you like.
counterUp( el, {
    duration: 5000,
    delay: 16,
} )

CDN

Triggering the Counter

It is up to you to perform the triggering on when to start the count up. Here are some common ways on how to do it:

Trigger when the element becomes visible with Intersection Observer

Example Pen: https://codepen.io/bfintal/pen/zYzOGpZ

const callback = entries => {
	entries.forEach( entry => {
		const el = entry.target
		if ( entry.isIntersecting ) ) {
			counterUp( el, {
				duration: 2000,
				delay: 16,
			} )
		}
	} )
}

const IO = new IntersectionObserver( callback, { threshold: 1 } )

const el = document.querySelector( '.counter' )
IO.observe( el )

Trigger when the element becomes visible with Waypoints

The counting is performed when counterUp is called. To make the counting start when the element becomes visible, use a visibility library like Waypoints

For example:

// On DOM ready.
require( 'waypoints/lib/noframework.waypoints.js' )
const el = document.querySelector( '.counter' )
new Waypoint( {
    element: el,
    handler: function() { 
        counterUp( el ) 
        this.destroy()
    },
    offset: 'bottom-in-view',
} )

Footnotes

An improvement to https://github.com/bfintal/Counter-Up