Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
ts-stopwatch
Advanced tools
Stopwatch timer utility written in TypeScript
ts-stopwatch
is a convenient stopwatch-inspired timer utility for measuring durations of time between different points of execution in code. It can be paused, resumed, reset, and can record multiple "slices" of time (inspired by a stopwatch's "lap" functionality).
Because ts-stopwatch
is written in TypeScript, it comes with 100% accurate TypeScript type definitions.
No. The ts-stopwatch
NPM package includes both a standard NPM/CommonJS module and a ES module. The included TypeScript type definitions are just a bonus. Source maps are also included.
Install via NPM:
npm i -s ts-stopwatch
JavaScript:
const Stopwatch = require("ts-stopwatch").Stopwatch;
TypeScript/ES6:
import { Stopwatch } from "ts-stopwatch";
To begin recording time, create a new instance of Stopwatch
and call its
start()
method.
Pause the stopwatch via stop()
, then resume by calling
start()
again.
Use getTime()
to get the amount of time that the stopwatch has
recorded so far (ignoring durations of time that the Stopwatch was stopped).
There's no need to stop the stopwatch before doing this.
Similar to advanced physical stopwatches' abilities to record multiple lap times
Stopwatch supports recording multiple "slices" of time. See slice()
, getPendingSlice()
,
getCompletedSlices()
, and getCompletedAndPendingSlices()
.
NOTE: Call stop(true)
to simultaneously record the current pending "slice".
Use reset()
to reset the stopwatch to its initial state.
NOTE: Call start(true)
to force a reset before (re)starting.
See getState()
, isIdle()
, isRunning()
,
and isStopped()
for testing the current state of the Stopwatch.
By default, Stopwatch internally uses Date.now()
for tracking the amount of
time that has passed. This is the most compatible implementation, but has some limitations:
If your runtime environment supports a more reliable or higher precision method for obtaining system time or program execution time, then you can override this default implementation by either:
Stopwatch.setDefaultSystemTimeGetter()
to ensure that ALL future instances
of Stopwatch use your custom "system time getter" by default.NOTE: The unit of time/duration reported by Stopwatch is determined by the unit time returned by the "system time getter" function.
Stopwatch is not limited to recording durations of system time. It can record the "duration" (change) of any numeric value that may change over time, but is guaranteed to never decrease over time.
import { Stopwatch } from "ts-stopwatch";
const stopwatch = new Stopwatch();
stopwatch.start();
// imagine 100 ms worth of code execution
stopwatch.stop();
// imagine 100 ms worth of code execution (ignored)
stopwatch.start();
// imagine 100 ms worth of code execution
stopwatch.stop();
// imagine 100 ms worth of code execution (ignored)
stopwatch.getTime();
// returns 200
// (amount of time the stopwatch has been running)
import { Stopwatch } from "ts-stopwatch";
const stopwatch = new Stopwatch();
stopwatch.start();
// imagine 100 ms worth of code execution
stopwatch.slice();
// imagine 50 ms worth of code execution
stopwatch.stop();
// imagine 100 ms worth of code execution (ignored)
stopwatch.slice();
// imagine 100 ms worth of code execution (ignored)
stopwatch.start();
// imagine 150 ms worth of code execution
stopwatch.slice();
stopwatch.getCompletedSlices();
// returns [
// {
// startTime: 0,
// stopTime: 100,
// duration: 100
// },
// {
// startTime: 100,
// stopTime: 150,
// duration: 50
// },
// {
// startTime: 150,
// stopTime: 300,
// duration: 150
// }
// ]
Under construction.
View source code for exact method signatures and complete method/parameter documentation.
The distributed code and type definitions also include full documentation for convenience in IDEs that display documentation.
FAQs
Stopwatch timer utility written in TypeScript
The npm package ts-stopwatch receives a total of 4,620 weekly downloads. As such, ts-stopwatch popularity was classified as popular.
We found that ts-stopwatch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.