Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
The parse-ms npm package is a utility for parsing milliseconds into an object with more readable time properties such as days, hours, minutes, and seconds. It is useful for converting a duration in milliseconds into a more human-readable format.
Parse milliseconds into an object
This feature allows you to convert a duration in milliseconds into an object with properties for days, hours, minutes, seconds, milliseconds, microseconds, and nanoseconds.
const parseMs = require('parse-ms');
const result = parseMs(1337000000);
console.log(result); // { days: 15, hours: 11, minutes: 23, seconds: 20, milliseconds: 0, microseconds: 0, nanoseconds: 0 }
Handle large durations
This feature demonstrates the ability to handle and accurately parse large durations, breaking them down into their respective time units.
const parseMs = require('parse-ms');
const result = parseMs(9876543210);
console.log(result); // { days: 114, hours: 1, minutes: 29, seconds: 3, milliseconds: 210, microseconds: 0, nanoseconds: 0 }
The 'ms' package is a utility for converting various time formats to milliseconds and vice versa. Unlike parse-ms, which focuses on breaking down milliseconds into an object with time properties, 'ms' can convert human-readable time formats (like '2 days', '1h', '5m') into milliseconds and back. It is more versatile in terms of input formats but does not provide the detailed breakdown that parse-ms does.
The 'pretty-ms' package is designed to convert milliseconds into a human-readable string format. It is similar to parse-ms in that it deals with milliseconds, but instead of returning an object, it returns a formatted string (e.g., '1d 3h 4m 5s'). It is useful for displaying durations in a user-friendly way but does not provide the detailed object breakdown that parse-ms offers.
Parse milliseconds into an object
npm install parse-ms
import parseMilliseconds from 'parse-ms';
parseMilliseconds(1337000001);
/*
{
days: 15,
hours: 11,
minutes: 23,
seconds: 20,
milliseconds: 1,
microseconds: 0,
nanoseconds: 0
}
*/
parseMilliseconds(1337000001n);
/*
{
days: 15n,
hours: 11n,
minutes: 23n,
seconds: 20n,
milliseconds: 1n,
microseconds: 0n,
nanoseconds: 0n
}
*/
FAQs
Parse milliseconds into an object
The npm package parse-ms receives a total of 4,662,589 weekly downloads. As such, parse-ms popularity was classified as popular.
We found that parse-ms demonstrated a healthy version release cadence and project activity because the last version was released less than 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.