0.8.2 • Published 5 years ago

time-calc v0.8.2

Weekly downloads
54
License
-
Repository
github
Last release
5 years ago

time-calc

Build status

Support for calculating time-unit like twitter You can use this both node and browsers.

Install

Install with npm:

    npm install time-calc

API

unit keys
Y, M, D, h, m, s, ms

- calculate time-unit

    var watcher = require('time-calc')();
    setTimeout(function(){
      console.log(watcher()); // => '30ms'
    }, 30);
    setTimeout(function(){
      console.log(watcher()); // => '1s'
    }, 1200);
    setTimeout(function(){
      console.log(watcher()); // => '1m'
    }, 61000);

- limit target unit

    var watcher = require('time-calc')();
    setTimeout(function({enable:{s:false}}){
      console.log(watcher()); // => '1100ms'
    }, 1100);
    setTimeout(function(){
      console.log(watcher({enable:{m:false}})); // => '60s'
    }, 61000);

- change display

    var watcher = timecalc({display:{s:'秒', m: '分'}});
    setTimeout(function(){
      console.log(watcher()); // => '1秒'
    }, 1000);
    setTimeout(function(){
      console.log(watcher()); // => '1分'
    }, 60000);

- change viewer

default

    function defaultDisp(diff, repl) {
      if(repl.indexOf('%d') >= 0)
        return repl.replace(/[^\\]%d/g, split3(diff));
      if(repl.indexOf('%D') == 0)
        return repl.substr(2);
      return split3(diff) + repl;
    }
    var watcher = require('time-calc');
    watcher.viewer(function(diff, repl){ return diff });
    console.log(typeof watcher()); // => 'number'

- set start position

    var watcher = require('time-calc')({basepoint: Date.now() + 5000});
    setTimeout(function(){
      console.log(watcher()); // => '1s'
    }, 6200);

- watcher can accept all same options as time-calc

    var watcher = require('time-calc')(), base = Date.now() + 5000;
    setTimeout(function(){
      console.log(watcher({basepoint: base})); // => '1s'
    }, 6200);

also use on browser

<script type="text/javascript" src="time-calc.js"></script>
<script type="text/javascript">

	var watcher = timecalc();
    setTimeout(function(){
      console.log(watcher()); // => '1m'
    }, 61000);

</script>
0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.4

9 years ago

0.7.3

9 years ago

0.7.2

10 years ago

0.7.1

11 years ago

0.7.0

11 years ago

0.6.2

11 years ago

0.6.1

11 years ago

0.6.0

11 years ago

0.5.2

12 years ago

0.5.0

12 years ago