# stopwatch-node

> stopwatch for nodejs inspired by Spring Stopwatch

Latest version **1.1.0** (published 2020-11-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install stopwatch-node
pnpm add stopwatch-node
yarn add stopwatch-node
bun add stopwatch-node
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-11-11 |
| First published | 2019-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Han Li |
| Maintainers | vcfvct |
| Keywords | stopwatch, nodejs, typescript, javascript, time, timer |

## Links

- npm: https://www.npmjs.com/package/stopwatch-node
- Repository: https://github.com/vcfvct/stopwatch-node
- Homepage: https://github.com/vcfvct/stopwatch-node#readme
- Issues: https://github.com/vcfvct/stopwatch-node/issues
- npm.io page: https://npm.io/package/stopwatch-node

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-11-11
- 1.0.2 — 2019-10-29
- 1.0.1 — 2019-07-28
- 1.0.0 — 2019-01-28

## README

![Stopwatch](https://cdn.iconscout.com/icon/premium/png-256-thumb/stopwatch-13-111965.png)

## A simple JS/TS Stopwatch with 0 dependency.
This is inspired by the [Spring-Stopwatch](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/StopWatch.html). Written in `Typescript`, 100%` Test Coverage.

### Install
> npm install stopwatch-node

### Example
```javascript
import { StopWatch } from 'stopwatch-node';

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

(async () => {
  const sw = new StopWatch('sw');
  sw.start('Task 1');
  await sleep(1000);
  sw.stop();
  // whether the stop watch is currently running
  console.info(sw.isRunning());

  const task2Name = 'Task 2';
  sw.start(task2Name);
  await sleep(1500);
  sw.stop();

  sw.start('Task 3');
  await sleep(500);
  sw.stop();

  sw.start('Task 4');
  await sleep(300);
  sw.stop();

  console.info(`Short Summary: ${sw.shortSummary()}`);
  console.info(`Task Count: ${sw.getTaskCount()}`);
  // a table describing all tasks performed
  sw.prettyPrint();

  const task2 = sw.getTask(task2Name);
  console.info(`'${task2Name}' took ${task2?.timeMills} and percentage is ${task2?.percentage}`);
})();
```

#### Output
```
------------------------------------------
ms 		 % 		 Task name
------------------------------------------
1000 		 30.21 		 Task 1
1504 		 45.44 		 Task 2
505 		 15.26 		 Task 3
301 		 9.09 		 Task 4


'Task 2' took 1506 and percentage is 45.47
```

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