Giter Club home page Giter Club logo

tiny-tim's Introduction

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

// ES2015
import timer from 'tiny-tim'
// CommonJS
var timer = 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 suffix
const seconds = timer('s', true)

setTimeout(() => {
  console.log(seconds()) //=> '10s'
}, 10000)

// reuse a timer...

setTimeout(() => {
  console.log(seconds()) //=> '15s'
}, 15000)
// Time milliseconds without suffix
const milliseconds = 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!

tiny-tim's People

Contributors

sdgluck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.