
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
@alwatr/parse-duration
Advanced tools
A simple utility to parse a duration string into milliseconds number.
A simple, efficient utility to parse time duration strings into milliseconds or other time units.
npm install @alwatr/parse-duration
# or
yarn add @alwatr/parse-duration
# or
pnpm add @alwatr/parse-duration
import {parseDuration} from '@alwatr/parse-duration';
// Basic usage - parse to milliseconds
parseDuration('10s'); // 10,000 (10 seconds in milliseconds)
parseDuration('5m'); // 300,000 (5 minutes in milliseconds)
parseDuration('2h'); // 7,200,000 (2 hours in milliseconds)
parseDuration('1.5d'); // 129,600,000 (1.5 days in milliseconds)
// Accept milliseconds as input
parseDuration(5000); // 5,000 (pass through)
// Convert to different units
parseDuration('10d', 'h'); // 240 (10 days in hours)
parseDuration('1h', 'm'); // 60 (1 hour in minutes)
parseDuration('120s', 'm'); // 2 (120 seconds in minutes)
parseDuration(3600000, 'h'); // 1 (3600000 milliseconds in hours)
Parse a duration string or millisecond number into the specified unit (or milliseconds by default).
duration: string | number - A duration string (like '10s', '5m') or a number (treated as milliseconds)toUnit: DurationUnit (optional) - The unit to convert to. If omitted, returns milliseconds.number: The duration in the specified unit (or milliseconds if no unit specified)Error('not_a_number'): If the duration string doesn't contain a valid numberError('invalid_unit'): If the unit is not recognizedError('invalid_format'): If the duration format is invalid| Unit | Description | Milliseconds Equivalent |
|---|---|---|
s | Second | 1,000 |
m | Minute | 60,000 |
h | Hour | 3,600,000 |
d | Day | 86,400,000 |
w | Week | 604,800,000 |
M | Month (30d) | 2,592,000,000 |
y | Year (365d) | 31,536,000,000 |
import {parseDuration, DurationUnit, Duration} from '@alwatr/parse-duration';
// Type-safe unit parameter
function waitFor(time: Duration): Promise<void> {
const ms = parseDuration(time);
return new Promise((resolve) => setTimeout(resolve, ms));
}
// Usage
await waitFor('5s');
The following companies, organizations, and individuals support Nanolib ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.
Contributions are welcome! Please read our contribution guidelines before submitting a pull request.
FAQs
A simple utility to parse a duration string into milliseconds number.
The npm package @alwatr/parse-duration receives a total of 373 weekly downloads. As such, @alwatr/parse-duration popularity was classified as not popular.
We found that @alwatr/parse-duration 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
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.