ts-stopwatch is a convenient, stopwatch-inspired timer utility for measuring durations of time between different points of execution in code. It supports pausing, resuming, resetting, and recording multiple 'slices' of time, akin to a physical stopwatch's lap functionality. Written entirely in TypeScript, it provides 100% accurate type definitions, making it suitable for both TypeScript and JavaScript environments. The package, currently at version 0.0.4, appears to have an inactive development status, with no significant updates in recent years. A key feature is its ability to customize the underlying time source, allowing developers to opt for more precise or stable timers like `process.hrtime()` in Node.js, addressing potential inaccuracies from system clock adjustments that `Date.now()` might face. It ships with both CommonJS and ES modules.
npm install ts-stopwatchVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic stopwatch functionality: starting, stopping, getting time, pausing/resuming, and recording time slices (laps).
Consider using a more actively maintained alternative for critical projects. If using, thoroughly vet the code and consider vendoring it into your project for local maintenance.
For higher precision or robustness against system clock changes (especially in Node.js environments), provide a custom 'system time getter' function to the `Stopwatch` constructor, for example, by integrating `process.hrtime()`.
To stop the stopwatch and simultaneously record the final pending slice, call `stop(true)`.
In CommonJS, you must destructure the `Stopwatch` class: `const { Stopwatch } = require('ts-stopwatch');`Ensure you have `import { Stopwatch } from 'ts-stopwatch';` at the top of your ES Module/TypeScript file, or `const { Stopwatch } = require('ts-stopwatch');` in your CommonJS file, and that the variable is accessible in the current scope.No dependency data recorded yet.