mstytn / timespan-nodejs

A Class for measuring time between operations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

timespan-nodejs

Contributors Forks Stargazers Issues MIT License


Logo

TimeSpan

project_description
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

![Product Name Screen Shot][product-screenshot]

Here's a blank template to get started: To avoid retyping too much info. Do a search and replace with your text editor for the following: github_username, repo_name, twitter_handle, email, project_title, project_description

Getting Started

To get a local copy up and running follow these simple steps.

Usage

Copy this file to project dir. Or subfolder. There is no npm package to install. First import Timespan.

const TimeSpan = require('./timespan');

Then reference the Timespan. Every methods returns the class itself. So you can chain mathods.

const timespan = new TimeSpan();

Constructor gets a boolean parameter to define if it will work or not. Passing the parameter false, TimeSpan only allocates private properties and doesn't work. When TimeSpan referenced, time starts to count. If you want to start time in place use:

timespan.setStart();

To record laps use: timspan.lap() This will reset the timer and adds the current elapsed time to laps. You can use getLaps()or logLaps() ind this state.

timespan.lap();

To stop the counter simply use stop() method. This will stop the timer and add laps data to log. If you continue using this. Every laps will be stored ing log.

Example usage:

const TimeSpan = require('./timespan');

const timespan = new TimeSpan();

//USING FOR ONCE
timespan.setStart() //reset the start time
SomeLongOperation()
timespan.stop().logLaps().reset() // Sample Output: [ "8.102 s" ]

//CONTINUOUS USE
timespan.setStart() //reset the start time
SomeLongOperation()
timespan.lap()
SomeOtherLongOperation()
timespan.lap()
SomeOtherLongOperation()
timespan.stop().logLaps() // Sample Output: [ '0.117 s', '5.007 s', '8.146 s' ]

SomeOtherOperation()

timespan.setStart()
SomeOtherLongOperation()
timespan.lap()
SomeOtherLongOperation()
timespan.stop().logLog().reset() 
// Sample Output: [ [ '0.117 s', '5.007 s', '8.146 s' ], [ '5.007 s', '8.146 s' ] ]
// OR
timespan.stop().getLog(console.log).reset() //Or don't reset and go on...
// Sample Output: [ [ '0.117 s', '5.007 s', '8.146 s' ], [ '5.007 s', '8.146 s' ] ]

Roadmap

See the open issues for a list of proposed features (and known issues).

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Project Link: https://github.com/mstytn/timespan-nodejs

About

A Class for measuring time between operations

License:MIT License


Languages

Language:JavaScript 100.0%