Git Product home page Git Product logo

millisecond's Introduction

millisecond

Made by unshiftVersion npmBuild StatusDependenciesCoverage StatusIRC channel

Parse strings that indicate a time to their millisecond equivalents.

Installation

This module is written with Node.js and Browserify in mind and can therefor be installed using the node package manager:

npm install --save millisecond

Usage

The module exposes one single function interface, so you simply require it using:

'use strict';

var ms = require('millisecond');

And to parse a string simply supply it as first argument and it will return a number. If we're unable to parse it, we will automatically return 0.

ms('1 second'); // returns 1000
ms('1 ms');     // returns 1
ms('10 cows');  // returns 0

It understands the following strings:

  • x milliseconds
  • x millisecond
  • x msecs
  • x msec
  • x ms
  • x seconds
  • x second
  • x secs
  • x sec
  • x s
  • x minutes
  • x minute
  • x mins
  • x min
  • x m
  • x hours
  • x hour
  • x hrs
  • x hr
  • x h
  • x days
  • x day
  • x d
  • x years
  • x year
  • x yrs
  • x yr
  • x y

The space after the number is optional so you can also write 1ms instead of 1 ms. In addition to that it also accepts numbers and strings which only includes numbers and we assume that these are always in milliseconds.

License

MIT

This module is heavily inspired by the ms module which is also licensed under MIT. If you also need to transform numbers back in to strings I suggest you look at that library.

millisecond's People

Contributors

3rd-eden avatar

Watchers

James Cloos avatar Luigi Pinca 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.