# countdown-pulse

> It is timer that calculates the countdown time from the given time.

Latest version **3.2.1** (published 2023-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install countdown-pulse
pnpm add countdown-pulse
yarn add countdown-pulse
bun add countdown-pulse
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.1 |
| Published | 2023-03-28 |
| First published | 2022-02-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ashik Sarkar |
| Maintainers | ashiksarkar |
| Keywords | countdown, timer, pulse |

## Links

- npm: https://www.npmjs.com/package/countdown-pulse
- Repository: https://github.com/imashiksarkar/countdown-pulse
- Homepage: https://github.com/imashiksarkar/countdown-pulse#readme
- Issues: https://github.com/imashiksarkar/countdown-pulse/issues
- npm.io page: https://npm.io/package/countdown-pulse

## Recent versions

- 3.2.1 (latest) — 2023-03-28
- 3.2.0 — 2023-03-28
- 3.1.5 — 2023-02-23
- 3.1.4 — 2023-02-20
- 2.1.4 — 2022-12-10
- 2.1.2 — 2022-12-06
- 2.1.1 — 2022-12-06
- 2.1.0 — 2022-03-09
- 2.0.0 — 2022-03-06
- 1.0.0 — 2022-02-16

## README

# ⤴️ Installation

```javascript
$ npm i countdown-pulse
```

# 📃 How to use

```javascript
import CdnTimer from "countdown-pulse";

try {
  const cdn = new CdnTimer({
    date: 30,
    month: "JANUARY",
    year: 2025,
    hour: 0,
    minute: 0,
    second: 0,
  });

  // only runs when days change
  cdn.calcDays((res) => {
    console.log("Days =>", res);
  });

  // only runs when hours change
  cdn.calcHours((res) => {
    console.log("Hours =>", res);
  });

  // only runs when minutes change
  cdn.calcMinutes((res) => {
    console.log("Minutes =>", res);
  });

  // only runs when seconds change
  cdn.calcSeconds((res) => {
    console.log("Seconds =>", res);
  });
} catch (error) {
  console.log(error);
}
```

# 📃 How to use With React

```typescript
import Countdown, { cdnReducer, initState } from "countdown-pulse";
import { MouseEvent, useCallback, useEffect, useReducer } from "react";

interface CustomEvent {
  target: {
    name: string;
  };
}
type extendedMouseEvent = MouseEvent<HTMLButtonElement> & CustomEvent;

function App() {
  const [cdnState, cdnDispatch] = useReducer(cdnReducer, initState);
  const { days, hours, minutes, seconds } = cdnState;
  let cdn: Countdown | null = null;

  useEffect(() => {
    try {
      cdn = new Countdown({
        date: 5,
        hour: 0,
        minute: 0,
        month: "FEBRUARY",
        second: 0,
        year: 2024,
      });

      cdn.cdnDispatch(cdnDispatch);
    } catch (error) {
      cdn?.stop();
    }
    // cleanup
    return () => cdn?.stop();
  }, []);

  const handleBtnClick = useCallback((e: extendedMouseEvent) => {
    if (e.target.name === "start") cdn?.start();
    if (e.target.name === "stop") cdn?.stop();
  }, []);

  return (
    <div>
      <span>
        Days: {days} | Hours: {hours} | Minutes: {minutes} | Seconds: {seconds}
        <button type="button" name="stop" onClick={handleBtnClick}>
          Stop Timer
        </button>
        <button type="button" name="start" onClick={handleBtnClick}>
          Start Timer
        </button>
      </span>
    </div>
  );
}

export default App;
```

---
_Source: https://npm.io/package/countdown-pulse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
