1.0.9 • Published 5 months ago

count-to-day v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

count-to-day

It is a lightweight javascript package that calculates countdown to a particular day of the week.

Installation

npm install count-to-day --save
//or with yarn
yarn add count-to-day

Params

ParamsTypeDescription
dayOfWeek'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday'the day of the week you want to count down to
countDownCbfunctioncall back function whose params contains the countdown object: {days: number, hours: number, minutes: number, seconds: number }
timeToCountTostringnot mandatory. The time to count to, uses 24 hours clock time, e.g '12:00:00', '16:00:00', '1:00:00'. Defaults to '00:00:00' (12 midnight)
isInfinitebooleanA boolean flag that determines if the time should restart after the date to countdown to is reached. Defaults to false

Usage

import { CountDownToDay } from "count-to-day";

CountDownToDay("wednesday", (count) => console.log("count=", count), "10:42:00");
//=> count =  { days: number, hours: number, minutes: number, seconds: number }
//(logs an object like this that contains the countdown)

Or use in a custom hook

import { useEffect, useState } from "react";
import { CountDownToDay, StopCountdown } from "count-to-day";

const useCountdown = (dayOfWeek = "friday", timeToCountTo = "00:00:00") => {
  const [count, setCount] = useState({
    days: "",
    hours: "",
    minutes: "",
    seconds: ""
  });

  useEffect(() => {
    CountDownToDay(dayOfWeek, setCount, timeToCountTo);

    return () => {
      StopCountdown();
    };
  }, [dayOfWeek, timeToCountTo]);

  return { count };
};

export default useCountdown;
1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago