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

@bhirmbani/countdown-generator

v1.0.2

Published

an opinionated countdown generator for any javascript project.

Downloads

20

Readme

Countdown Generator

countdown generator is an opiniated javascript library that can be combined with any javascript lib/framework to create a timer or countdown functionality.

How to install

npm i @bhirmbani/countdown-generator

Features

  • Vanilla javascript.
  • No framework/library related. Can be extended to any library/UI library out there.
  • Timer and countdown mode.
  • Custom function to run for every interval provided.
  • Custom interval.
  • Custom label.

Demo

Curious? Simple codesandbox demo.

Examples

React Hooks

import CountdownGenerator from "@bhirmbani/countdown-generator";

function Component() {
  const [hour, setHour] = useState(0);
  const [minute, setMinute] = useState(0);
  const [second, setSecond] = useState(0);

  const backupPlan = (hour, minute, second) => {
    localStorage.setItem("hour", hour);
    localStorage.setItem("minute", minute);
    localStorage.setItem("second", second);
  };
  
  const onFinishFun = () => {
    console.log("finished!");
  };

  const countdown = new CountdownGenerator({
    hours: 1,
    minutes: 1,
    seconds: 5,
    listener: {
      hour: setHour,
      minute: setMinute,
      second: setSecond
    },
    backupPlan,
    onFinish: onFinishFun,
    customLabel: {
      hour: "hour",
      minute: "min"
      second: "sec"
    }
  });

  useEffect(() => countdown.run(), []);

  return (
    <div className="App">
      <h2>
        {hour} : {minute} : {second}
      </h2>
    </div>
  );
}

API

Name | Type | Description | Default value | Example --- | --- | --- | --- | --- hours | string | specify duration in hour. | 0 | '1' minutes | string | specify duration in minute. | 0 | '10' seconds | string | specify duration in second. | 0 | '15' onFinish | Function | a function to be called when finished. | - | - debug | Boolean | if true, print the process to the console. | false | - backupPlan | Function | Give you three paramaters: hour, minute and second. You can use this for keeping track every change to those parameter values. Example: store every change to localstorage or db so after user doing any state destroy activity, it will restored later. | - | function(h,m,s){console.log(h, m ,s)} listener | Object | Have three keys: hour, minute, second | - | - listener.hour | Function | A function that change state that related to the view in your application. It will change hour indicator for each hour passed. | - | - listener.minute | Function | A function that change state that related to the view in your application. It will change minute indicator for each minute passed. | - | - listener.second | Function | A function that change state that related to the view in your application. It will change second indicator for each second passed. | - | - type | string | choose one: timer or countdown. | countdown | - fun | Function | A custom function that you can provide that will be called for every interval that has been set. | - | - every | number | an interval that you can set to the generator (in miliseconds). Choose one: 1000, 500 or greater than 1000. | 1000 | - loop | Boolean | if true, start again after finished. | false | - customLabel | Object | Have three keys: hour, minute, second | - | - customLabel.hour | string | Label that will be provided after hour value | - | 'hr' will return ${hour} hr customLabel.minute | string | Label that will be provided after minute value | - | 'min' will return ${minute} min customLabel.second | string | Label that will be provided after second value | - | 'sec' will return ${second} sec

Feel Free to contribute! ✨

Fork this repo and create pull request. Open for any issues!

please use version 1.0.1 and above