Skip to content

sdgluck/tiny-tim

Repository files navigation

Tiny Tim

Meet Tim, a simple, small timer

Made with ❤ at @outlandish

npm version


🍪 Comes in at 156 bytes minified. Zero dependencies.

✨ Tiny Tim is compiled using babili for ES6+ and CommonJS environments.

👉 Use your preferred bundler and transpiler as required.

📄 Read the annotated source code.

Install

npm install --save tiny-tim
yarn add tiny-tim

Import

// ES2015importtimerfrom'tiny-tim'
// CommonJSvartimer=require('tiny-tim')

Usage

timer([unit[, suffix]]) : Function

Create a timer and start counting!

  • unit{String} Unit of time to return (optional, default="s")
  • suffix{Boolean} Attach suffix, e.g. unit "s" appends "s"(optional, default=false)

Available units: "ms", "s", "m", "h"

Returns a function that stops the timer and returns the duration:

  • as a string if with suffix
  • or as a number without

Examples

// Time in seconds with suffixconstseconds=timer('s',true)setTimeout(()=>{console.log(seconds())//=> '10s'},10000)// reuse a timer...setTimeout(()=>{console.log(seconds())//=> '15s'},15000)
// Time milliseconds without suffixconstmilliseconds=timer()setTimeout(()=>{console.log(milliseconds())//=> 1000},1000)

Contributing

All pull requests and issues welcome!

If you're not sure how, check out the great video tutorials on egghead.io!

About

⏳ a tiny timer < 160 bytes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published