3.1.0 • Published 8 years ago
util-time v3.1.0
A simple, lightweight library for facilitate work with time in JavaScript.
Note:
- Library wrote on TypeScript and include in self declaration file.
- Main file (i.e. index.js) use modular system CommonJS.
Including util-time
Browser
Module for browser is located in folder dist.
<script src="node_modules/util-time/dist/util-time.js"></script>
Node.js
Install from npm as dependence:
npm i util-time --save
Importing...
import * as time from 'util-time';
How to use?
import * as time from 'util-time';
/**
* Create timer/interval. Each instance of class is separeted
* timer or interval (independend from class).
*/
let timer = new time.Timer(),
interval = new time.Interval();
/**
* To launch timer/interval necessary call method start
* from instance.
*/
timer.start(1000, () => console.log('Hello world!'));
// ...
interval.start(1000, iter => console.log(iter));
/**
* To reset timer/interval necessary call method reset from instance
*/
timer.reset();
// ...
interval.reset();
/**
* You can also pause/continue.
*/
timer.pause();
// ...
timer.continue();
/**
* Pause can be set for a specific time.
*/
interval.pause(1000);
/**
* You can add time to timer or add iteraions to interval.
*/
timer.add(2000);
// ...
interval.add(10);
/**
* Also reduce...
*/
timer.reduce(2000);
// ...
interval.reduce(10);
Documentation
Detail you can read in documentation