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

react-realtime-countdown-timer

v2.1.1

Published

### React RealTime CountDown Timer

Downloads

16

Readme

react-realtime-countdown-timer

React RealTime CountDown Timer

NPM Version License

A brief description of your package and its key features.

Installation

You can install this package via npm. Run the following command:

  • Using Node Package Manager (NPM)
npm install react-realtime-countdown-timer
  • Using Yarn
yarn add react-realtime-countdown-timer

How to use in react.js (using realtime starting & ending Date)

import CountdownTimer from "react-realtime-countdown-timer"

export default function App(){

  const { days, hours, minutes, seconds, nanoSeconds, status, message } =
    CountdownTimer(
      /** @param Staring time Parameter--- */
      "Wed Jun 28 2023 23:00:00 GMT+0600 (Bangladesh Standard Time)",

      /** @param Ending time Parameter--- */
      "Wed Jul 30 2023 18:00:00 GMT+0600 (Bangladesh Standard Time)",

      /** @param Time inter validation Duration--- */
      1000
    );

  const styles = {
    container: {
      padding:8
      fontSize:20,
      width:'100%',
      display:flex,
      height:'100vh',
      alignItems:'center',
      justifyContent:'center',
    }
  }

  return (
    <div style={styles.container}>
    <p>{message}</p><br/>
    <p>Days <strong style={{padding:'0px 8px'}}>{days}</strong></p>
    <p>Hours <strong style={{padding:'0px 8px'}}>{hours}</strong></p>
    <p>Minutes <strong style={{padding:'0px 8px'}}>{minutes}</strong></p>
    <p>Seconds <strong style={{padding:'0px 8px'}}>{seconds}</strong></p>
    </div>
  );
}

Simple working policy,

  • CountdownTimer() the function receive three parameters of starting count date, ending count date and interval time in milliseconds. and return the updated value of { days, hours, minutes, seconds, nanoSeconds, status, message } after every third parameter's inter validation time.

How to use (Using ms in 4th-param Duration)

  • if starting & ending time is not need for you then you can use duration in milliseconds.

  • Example :

const { days, hours, minutes, seconds, nanoSeconds, status, message } =
  CountdownTimer(null, null, 1000, 1000 * 60 * 10);
  • or

const { days, hours, minutes, seconds, nanoSeconds, status, message } =
  CountdownTimer(
    /** @param Staring time Parameter--- */
    'Wed Jun 28 2023 23:00:00 GMT+0600 (Bangladesh Standard Time)',

    /** @param Ending time Parameter--- */
    'Wed Jul 30 2023 18:00:00 GMT+0600 (Bangladesh Standard Time)',

    /** @param Time inter validation Duration--- */
    100,

    /** @param if starting & ending time is not need for you then you can use duration --- */
    600000
  );

- for 10 minutes.
  • N:B: if you are using a realtime timer to use starting and ending date and count down after one seconds donn't need to set the CountdownTimer() function's three an four parameters.

Using in HTML Pages

If you are use it in a html page or using others pages with <script></script> tag linking

  • Simply You can do (copy this code and paste your "index.html" file of the root directory.)
<script src="./node_modules/react-realtime-countdown-timer/js/countdown.js"></script>
<script>
  // Initialize your 'CountdownTimer' function.
</script>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>React Realtime Countdown Timer (NPM Packages - 'react-realtime-countdown-timer')</title>

  <style>
    body {
      width: 100%;
      display: flex;
      flex-direction: column;
      height: 100vh;
      align-items: center;
      justify-content: center;
      gap: 5px;
    }

    #message {
      margin-right: 20px;
    }

    #container p strong span {
      margin-right: 10px;
      color: red;
    }

    h1 {
      text-decoration: underline;
    }
  </style>
</head>

<body>
  <h1>Countdown Timer:</h1><br>
  <div id="container">
    <p>
      <span id="message"></span>
      <strong>Days: <span id="days"></span></strong>
      <strong>Hours: <span id="hours"></span></strong>
      <strong>Minutes: <span id="minutes"></span></strong>
      <strong>Seconds: <span id="seconds"></span></strong>
      <strong>Milliseconds: <span id="milliSeconds"></span></strong>
    </p>
  </div>

  <div id="container" realtime>
    <p>
      <span id="message"></span>
      <strong>Days: <span id="days"></span></strong>
      <strong>Hours: <span id="hours"></span></strong>
      <strong>Minutes: <span id="minutes"></span></strong>
      <strong>Seconds: <span id="seconds"></span></strong>
      <strong>Milliseconds: <span id="milliSeconds"></span></strong>
    </p>
  </div>

  <script src="./node_modules/react-realtime-countdown-timer/js/realtime-countdown-timer.js"></script>
  <script>
    CountdownTimer(
      {
        daysElement: document.querySelector('#days'),
        hoursElement: document.querySelector('#hours'),
        minutesElement: document.querySelector('#minutes'),
        secondsElement: document.querySelector('#seconds'),
        milliSecondsElement: document.querySelector('#milliSeconds'),
        messageElement: document.querySelector('#message'),
      },
      null,
      null,
      1000,
      1000 * 60 * 1
    );

    CountdownTimer(
      /** @param Define the DOM Elements--- */
      {
        daysElement: document.querySelector('[realtime] #days'),
        hoursElement: document.querySelector('[realtime] #hours'),
        minutesElement: document.querySelector('[realtime] #minutes'),
        secondsElement: document.querySelector('[realtime] #seconds'),
        milliSecondsElement: document.querySelector('[realtime] #milliSeconds'),
        messageElement: document.querySelector('[realtime] #message'),
      },
      /** @param Staring time Parameter--- */
      'Wed Jun 28 2023 23:00:00 GMT+0600 (Bangladesh Standard Time)',
      /** @param Ending time Parameter--- */
      'Wed Jul 30 2023 18:00:00 GMT+0600 (Bangladesh Standard Time)',
      /** @param Time inter validation Duration--- */
      1000,
    );

  </script>
</body>

</html>