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

rx-countdown

v1.1.0

Published

countdown timer library using RxJS Observables

Downloads

1

Readme

npm version

rx-countdown

countdown timer using RxJS Observables

Usage

using RxCountDown as a state container - if you need to query the internal state of the countdown object at a set interval

var RxCountDown = require("rx-countdown");
var intervalId;
var countDown = new RxCountDown(5000); // 5 second timer

countDown.onComplete(function() {
   clearInterval(intervalId);
   console.log("DONE!");
});

// query the current state/value of countdown every second
intervalId = setTimeout(function() {
    console.log(countDown.getRemainingTime());
}, 1000);

/*
    "00:05"
    "00:04"
    "00:03"
    "00:02"
    "00:01"
    "00:00"
    "DONE!"
*/

sample angular implementation using the state container approach

@Component({
    ...
    template: "<span>{{ getRemainingTime() }}</span>"
})
export class AppComponent {
    private countDown: RxCountDown;
    
    constructor() {
        this.countDown = new RxCountDown(5000);
    }

    getRemainingTime(): string {
        return this.countDown.getRemainingTime();
    }
}

Observable approach - whenever the internal state changes, you get notified of the new remaining time value

var RxCountDown = require("rx-countdown");
var countDown = new RxCountDown(5000); // 5 second timer

countDown.onComplete(function() {
   console.log("DONE!");
});

// subscribe whenever the internal state of the countdown changes
countDown.subscribe(function(remainingTime) {
    console.log(remainingTime);
});

/*
    "00:05"
    "00:04"
    "00:03"
    "00:02"
    "00:01"
    "00:00"
    "DONE!"
*/

Configuration Options

var CountDown = new RxCountDown(durationMs[, endDate[, intervalMs[, format]]]);

durationMs: number - total duration in milliseconds of countdown timer. additive with the endDate parameter. defaults to 0

endDate: string - target end date when you want the countdown timer to end. can be combined with durationMs to extend the countdown.

intervalMs: number - duration in milliseconds on how frequently the countdown timer should update

format: string - momentjs format to change how the output remaining time value is displayed. defaults to "mm:ss"

Available Methods

onComplete(onCompleteFn: () => void): void; - onComplete allows the user to pass a function that will be executed when the countdown timer is done

getRemainingTime(): string; - returns the current remaining time formatted with the current format option

isExpired(): boolean; - returns false if the countdown is still active, returns true otherwise

subscribe(next?: (value: string) => void, error?: (error: any) => void, complete?: () => void): Subscription - allows subscription to internal changes of the countdown timer. whenever the internal state of the countdown timer changes, it would invoke the next() function with the updated remaining time. returns an RxJS Subscription

TODO

  • create plunk for sample usage
  • add unit tests