Socket
Socket
Sign inDemoInstall

parse-duration

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-duration

convert a human readable duration string to a duration format


Version published
Weekly downloads
322K
increased by7.15%
Maintainers
3
Weekly downloads
 
Created

What is parse-duration?

The parse-duration npm package is a utility for parsing human-readable duration strings into milliseconds. It is useful for converting time durations specified in various formats (like '2h', '1d', '5m', etc.) into a standard numerical format that can be used programmatically.

What are parse-duration's main functionalities?

Parse human-readable duration strings

This feature allows you to convert a human-readable duration string (e.g., '2h' for 2 hours) into milliseconds. The code sample demonstrates parsing '2h' into 7200000 milliseconds.

const parseDuration = require('parse-duration');
const duration = parseDuration('2h');
console.log(duration); // 7200000

Parse complex duration strings

This feature allows you to parse more complex duration strings that include multiple time units. The code sample shows how '1d 2h 30m' is parsed into 93600000 milliseconds.

const parseDuration = require('parse-duration');
const duration = parseDuration('1d 2h 30m');
console.log(duration); // 93600000

Handle invalid input gracefully

This feature ensures that invalid input strings are handled gracefully by returning null. The code sample demonstrates parsing an invalid string 'invalid', which results in null.

const parseDuration = require('parse-duration');
const duration = parseDuration('invalid');
console.log(duration); // null

Other packages similar to parse-duration

Keywords

FAQs

Package last updated on 10 May 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc