Giter Club home page Giter Club logo

dhms's Introduction

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

dhms's People

Contributors

astur avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.