Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
readable-elapsed-timer
Advanced tools
Readme
A tool for easily finding the time elapsed between two parts of your code.
Import the Timer
class at the top of your file. If your project uses ES6 modules then do the following.
import Timer from "readable-elapsed-timer";
If your poject uses CommonJS modules, then do the following.
const Timer = require('readable-elapsed-timer')
Then you can create a new timer object to keep track of time within your code. Call the elapsed()
method to return the time elapsed in a human readable format. To get the time between two different points without creating a new timer object, simply call the reset()
method.
// Delay function for demonstration purposes.
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
const main = async () => {
const timer = new Timer();
await delay(100);
console.log(timer.elapsed());
// "100 miliseconds"
timer.reset()
await delay(500);
console.log(timer.elapsed());
// "500 miliseconds"
await delay(1000);
console.log(timer.elapsed());
// "1.5 seconds"
// Notice we didn't reset the timer this time.
};
main()
npm install readable-elapsed-time
The constructor accepts an options
object as an argument.
const options = {
start: new Date('November 5, 1955').getTime(),
brief: true
}
All of the elapsed
family of methods accept an options
argument as well. In addition to the options available on the constructor, you can set an end
time. This allows you to get time elapsed without actually needing to wait.
const options = {
start: new Date("November 5, 1955").getTime(),
end: new Date("October 21, 2015").getTime(),
brief: false
};
const elapsed = timer.elapsed(options);
console.log(elapsed);
// "525600 hours"
Setting start
allows you to give the timer instance an arbitrary start time. Setting brief
changes the default function of the timer instance to show time formatted as abbreviations ("5s" instead of "5 seconds").
The following additional methods are available on an instance of Timer
.
elapsedVerbose()
This will return the time elapsed formatted to be human readable even if the timer is configured otherwise. If timer.elapsedVerbose()
is called after five seconds, 5 seconds
will be returned.elapsedBrief()
This will return the time elapsed formatted using abbreviations even if the timer is configured otherwise. If timer.elapsedBrief()
is called after five seconds, 5s
will be returned.elapsedRaw()
This will return the time elapsed in miliseconds without any additional formatting. If timer.elapsedRaw()
is called after five seconds, 5000
will be returned.elapsedRaw()
This will return the time elapsed in miliseconds without any additional formatting. If timer.elapsedRaw()
is called after five seconds, 5000
will be returned.FAQs
Easily get time elapsed. Returns human readable format by default.
The npm package readable-elapsed-timer receives a total of 202 weekly downloads. As such, readable-elapsed-timer popularity was classified as not popular.
We found that readable-elapsed-timer 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.