Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
pretty-time
Advanced tools
Easily format the time from node.js `process.hrtime`. Works with timescales ranging from weeks to nanoseconds.
The pretty-time npm package is designed to format and display time durations in a human-readable format. It is particularly useful for converting raw time measurements in milliseconds into a more digestible format, which can be helpful in logging, monitoring, or displaying elapsed time in applications.
Convert milliseconds to human-readable format
This feature allows developers to measure the duration of operations and display it in a format that is easy to read. The example shows how to use pretty-time to measure the time taken by an operation and print it in a human-readable format.
const prettyTime = require('pretty-time');
// Start a timer
const start = process.hrtime();
// Perform some operations...
// End the timer
const end = process.hrtime(start);
// Convert process time to a human-readable string
console.log('Operation took: ' + prettyTime(end));
Moment.js is a comprehensive date handling library that can also format durations. Unlike pretty-time, which focuses solely on formatting durations, Moment.js offers extensive capabilities for date and time manipulation, making it more versatile if your project requires handling of dates along with formatting durations.
Day.js is a lightweight alternative to Moment.js that includes plugins for duration handling. It is similar to pretty-time in its simplicity and focus on minimalism but extends its utility to date manipulation as well.
The ms package is another simple utility for converting various time formats to milliseconds and vice versa. It is similar to pretty-time in its simplicity and focus on time conversion, but it does not provide the same level of human-readable formatting.
Easily format the time from node.js
process.hrtime
. Works with timescales ranging from weeks to nanoseconds.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
$ npm install --save pretty-time
var pretty = require('pretty-time');
var start = process.hrtime();
var time = process.hrtime(start);
console.log(pretty(time));
//=> 3μs
By default, when no time increment is given as the second argument, the closest timescale is used (e.g. most granular without being less than zero).
Examples:
pretty([1200708, 795428088]);
//=> '2w'
pretty([800708, 795428088]);
//=> '1w'
pretty([400708, 795428088]);
//=> '5d'
pretty([70708, 795428088]);
//=> '20h'
pretty([12708, 795428088]);
//=> '4h'
pretty([3708, 795428088]);
//=> '1h'
pretty([208, 795428088]);
//=> '3m'
pretty([20, 795428088]);
//=> '21s'
pretty([0, 795428088]);
//=> '795ms'
pretty([0, 000428088]);
//=> '428μs'
pretty([0, 000000088]);
//=> '88ns'
pretty([0, 000000018]);
//=> '18ns'
(All of the following examples use [6740, 795428088]
as the hrtime array.)
This value is passed as the second argument and determines how granular to make the time.
Examples
pretty(time, 'h');
//=> '2h'
pretty(time, 'm');
//=> '1h 52m'
pretty(time, 's');
//=> '1h 52m 21s'
Valid time increments
Any of the following may be used:
ns
| nano
| nanosecond
| nanoseconds
μs
| micro
| microsecond
| microseconds
ms
| milli
| millisecond
| milliseconds
s
| sec
| second
| seconds
m
| min
| minute
| minutes
h
| hr
| hour
| hours
d
| day
| days
w
| wk
| week
| weeks
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
Commits | Contributor |
---|---|
14 | jonschlinkert |
5 | doowb |
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on July 12, 2018.
FAQs
Easily format the time from node.js `process.hrtime`. Works with timescales ranging from weeks to nanoseconds.
The npm package pretty-time receives a total of 907,545 weekly downloads. As such, pretty-time popularity was classified as popular.
We found that pretty-time demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.