Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dhms

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dhms

Parses `dhms` string to number of milliseconds

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36
increased by111.76%
Maintainers
1
Weekly downloads
 
Created
Source

dhms

Parses dhms string to number of milliseconds or seconds

Build Status NPM version

Install

npm i dhms

Usage

const dhms = require('dhms');

// milliseconds
dhms('123'); // 123
dhms('1s'); // 1000
dhms('1m'); // 60000
dhms('1h'); // 3600000
dhms('1d'); // 86400000
dhms('1d2h30m45s123'); // 95445123
dhms('2h 30 m4 5s12 3') === dhms('2h30m45s123'); // true
dhms('1h1h1h') === dhms('3h'); // true
dhms('-123'); // -123
dhms('-1h'); // -3600000
dhms('1h-30m') === dhms('30m'); // true
dhms('1s-400') === dhms('600'); // true

// seconds
dhms('123', true); // 123
dhms('1s', true); // 1
dhms('1m', true); // 60
dhms('1h', true); // 3600
dhms('1d', true); // 86400
dhms('1d2h30m45s123', true); // 95568
dhms('2h 30 m4 5s12 3', true) === dhms('2h30m45s123', true); // true
dhms('1h1h1h', true) === dhms('3h', true)); // true
dhms('-123', true); // -123
dhms('-1h', true); // -3600
dhms('1h-30m', true) === dhms('30m', true); // true
dhms('1m-40', true) === dhms('20', true); // true

// zero
dhms('000'); // 0
dhms('bad'); // 0
dhms('dhms'); // 0
dhms('123x'); // 0
dhms(''); // 0
dhms(true); // 0
dhms(false); // 0
dhms(null); // 0
dhms(); // 0
dhms(0); // 0
dhms(123); // 0
dhms([123]); // 0
dhms('000', true); // 0
dhms('bad', true); // 0
dhms('dhms', true); // 0
dhms('123x', true); // 0
dhms('', true); // 0
dhms(true, true); // 0
dhms(false, true); // 0
dhms(null, true); // 0
dhms(undefined, true); // 0
dhms(0, true); // 0
dhms(123, true); // 0
dhms([123], true); // 0

License

MIT

Keywords

FAQs

Package last updated on 31 Mar 2021

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