# dr-strange

> A simple stopwatch utility package for measuring execution times of code snippets or functions in Node.js applications.

Latest version **1.0.1** (published 2023-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install dr-strange
pnpm add dr-strange
yarn add dr-strange
bun add dr-strange
```

## 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.0.1 |
| Published | 2023-04-16 |
| First published | 2023-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | German Eichemberger |
| Maintainers | eichemberger |
| Keywords | time-measuring, time, util |

## Links

- npm: https://www.npmjs.com/package/dr-strange
- Repository: https://github.com/eichemberger/dr-strange
- Homepage: https://github.com/eichemberger/dr-strange#readme
- Issues: https://github.com/eichemberger/dr-strange/issues
- npm.io page: https://npm.io/package/dr-strange

## 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.0.1 (latest) — 2023-04-16
- 1.0.0 — 2023-04-16

## README

# Dr Strange [![npm version](https://badge.fury.io/js/dr-strange.svg)](https://badge.fury.io/js/dr-strange)

Dr Strange is a simple stopwatch utility package for measuring execution times of code snippets or functions in Node.js applications. It is designed for use during development to help you optimize and analyze the performance of your code.

## Installation

Install Dr Strange as a development dependency:

```sh
npm install --save-dev dr-strange
```

## Usage

```javascript
const Stopwatch = require("dr-strange");

const stopwatch = new Stopwatch();

stopwatch.start();

// Your code here...

stopwatch.stop();

// Get the duration as a Duration object
const duration = stopwatch.getDuration();
console.log(
  `Duration: ${duration.hours} h ${duration.minutes} min ${duration.seconds} s ${duration.milliseconds.toFixed(2)} ms`
);

// Print the formatted duration
stopwatch.printDuration();

// Reset the stopwatch
stopwatch.reset();
```

### Stopwatch methods

- start(): Starts the stopwatch.
- stop(): Stops the stopwatch.
- getDuration(): Returns a Duration object representing the elapsed time. The object contains the properties hours, minutes, seconds, and milliseconds.
- printDuration(): Prints the formatted duration string, adjusting the format based on the elapsed time.
- reset(): Resets the stopwatch, setting the start and end times to null.

## TypeScript Support

This package includes TypeScript definitions for use in TypeScript projects.

```typescript
import Stopwatch from "dr-strange";
import Duration from "dr-strange/duration";

const stopwatch: Stopwatch = new Stopwatch();

stopwatch.start();
stopwatch.stop();

const duration: Duration = stopwatch.getDuration();

console.log(
  `Duration: ${duration.hours}h ${duration.minutes}m ${duration.seconds}s ${duration.milliseconds}ms`
);
```

## Testing

The package includes a suite of tests using the Jest testing framework. To run the tests, execute the following command:

```sh
npm test
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

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