npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sss-timer

v3.0.0

Published

Timer

Downloads

26

Readme

About

Timer is a library for creating and updating content based on time.

Like watch, counters, ads e.t.c.

Installation

  1. Download Timer

  2. Connect Timer before your scripts.

<script src="/assets/js/lib/Timer.js"></script>
  1. See how to use the Timer.
Package managers 😎

If you are using package managers such as npm or yarn, import this lib as usual.

# Yarn
yarn add sss-timer

# NPM
npm i sss-timer --save

Do import Timer from 'sss-timer';

Usage

Create callback

    // Timer will call your function with the following params
    // date - time object
    // timer - timer instance
    
    function callback (date, timer) {
      console.dir(date);
      console.dir(timer);
    }

Init your timer

    const timer = new Timer(callback);

    // start your timer 
    timer.start();

Or init and pass params

    const timer = new Timer(callback, {
        time: 5000
    });
    
    // start your timer 
    timer.start();

Options

| Option | Type | Description | | :------------ |:---------------|:--------------| | time | number| Initial Timer time state | | tick | number | How much Timer should increment in each tick and call callback | | onStop | function | Calls after timer stops | | breakOn | OneOf: {Timer.duration.DAY / Timer.duration.HOUR ...} | Prevents the transition to the next time division. 1hour 10min -> 70min |

Methods

Timer.convert

Converts milliseconds in the object

Note: This is STATIC method.
const timer = Timer.convert(2000500000, Timer.duration.MIN);
// timer -> DAY: 0, HOUR: 0, MIN: 33341, SEC: 40, MS: 0,

Timer.stringify

Method will convert numbers to string, and will add zero, if the number less than 10.

Useful for making clocks-like counters e.t.c

Note: This is STATIC method.
const timer = Timer.convert(2000500000);
const date = Timer.stringify(timer);
// timer -> {DAY: "23", HOUR: "03", MIN: "41", SEC: "40", MS: "00" }

Timer.format

Format template-string with passed data object

Note: KEY in Object should be the same as {{KEY}} in string. You can use any data with this function.

Note: This is STATIC method.
    const string = '{{DAY}}:{{HOUR}}:{{MIN}}:{{SEC}}:{{MS}}';
    const data = { DAY: '01', HOUR: '01', MIN: '07', SEC: '54', MS: '00'};
    Timer.format(string, data);
    // 01:01:07:54:00

timer.start()

Starts the timer

    const timer = new Timer(callback);
    timer.start()

timer.stop()

Stops the timer

    const timer = new Timer(callback);
    timer.stop()

timer.reset()

Stops the timer

    const timer = new Timer(callback);
    timer.reset()

Example

    const callback = function (date, timer) {
            console.dir(date);
            console.dir(timer);
            const stringifyDate = Timer.stringify(date);
            document.body.innerHTML = 'Time is: '
                + stringifyDate.DAY
                + ' : '
                + stringifyDate.HOUR
                + ' : '
                + stringifyDate.MIN
                + ' : '
                + stringifyDate.SEC;
    
            // timer.time is a working timer variable
            // consider it as read-only
            if(timer.time < 10000) {
                timer.reset();
            }
    
            setTimeout(() => {
                // to stop timer
                timer.stop();
    
                // to reset timer
                timer.reset();
            }, 20000)
        };
    
        const timer = new Timer(callback, {
            // initial time value
            time: 90485000,
            // to count down just pass negative tick int
            tick: -1000,
        });
    
        // to start timer
        timer.start();

Note: If you count down, timer will stop automatically when it reach 0.

License

This project is available under the MIT license.