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

angularjs-2-localstorage-timer

v1.0.2

Published

Countdown timer which uses the LocalStorage to store the information. You can create several ones, change their interval, and reset it. once it's reaches 0 - the last update time is saved in the LocalStorage information as well.

Downloads

4

Readme

AngulsrJS 2.x LocalStorage CountDown Timer

A countdown timer that write the data into the localStorage of the browser. It's being used incase of: -You want to refresh the page and continue from where you left off. -You want to get notified when the time is up ( Event ) and trigger something.

$ npm install --save angularjs-2-localstorage-timer 

Usage example

A full-featured working example can be found when running in the root folder Inisde node_modules/angularjs-2-localstorage-timer

npm install
npm start

Init our timer

In AngularJS 2.x we need to inject the timer into our component

constructor(private broadcaster: Broadcaster, private AppTimer : CountDownTimer) {
    // this.AppTimer is our timer
}
// Init with properties ( inside our app.component.ts )
this.AppTimer.init({
    counter:  5,
    interval: 1000,
    id:       "CountDownTest"
});

Events

constructor(private broadcaster: Broadcaster, private AppTimer : CountDownTimer) {

    // Events              
    this.broadcaster.on<string>('CountDownTimerChangeEvent').subscribe(message => {       
        console.log("[event] CountDownTimerChangeEvent");
    });

    this.broadcaster.on<string>('CountDownTimerEndEvent').subscribe(message => {
        console.log("[event] CountDownTimerEndEvent");
    });
}

Timer Functions

.start()

Start/Resume the timer

<button ng-click="AppTimer.start()"> Start </button>

.stop()

Stop our timer

<button ng-click="AppTimer.stop()"> Stop </button>

.restart()

Restart the timer with the values given when creating the timer. Timer won't start running, need to use start()

<button ng-click="AppTimer.restart()"> Restart </button>

.update()

Update one of the following parameters:

  • id ( string )
  • counter ( integer )
  • interval ( integer )

The update action will:

  • save the values into LocalStorage as well
  • It won't restart the timer or take any other action, meaning: -- If we've updated the value while the timer is running - it will continue running from the new value
<button ng-click="AppTimer.update('counter', 120)"> Update </button>

.destory()

Remove the timer entirly from LocalStorage. Remember that in order to continue from where we left off - the timer is always there ...

<button ng-click="AppTimer.destroy()"> Remove </button>

Timer Information

.getCounter()

Will return the exiting counter value

this.counter = this.AppTimer.getCounter()

Or, live information via HTML

<pre>{{ AppTimer.getCounter() }}</pre>

.getLastUpdate()

Will return the "last updated" value that the timer has stored. The value is a Date() object.

this.lastUpdate = this.AppTimer.getLastUpdate();

Or, live information via HTML

<pre>{{ AppTimer.getLastUpdate() }}</pre>

.getInfo()

Return as JSON all the possible information stored in LocalStorage. You can review all data when adding to the template:

this.timer_information = this.AppTimer.getInfo()

Or, live information via HTML

<pre>{{ AppTimer.getInfo() | json }}</pre>

Further Custom Actions

.reload()

So the reload() isn't really there ... we need to write it on our own in our controller as: If $scope.properties.id - is already found in LocalStorage - the timer will be reloaded with the last counter. But if the id isn't found, it will create a new timer.

    reload() {
        this.AppTimer.init(this.properties);                
    }

.recreate()

Re-create a new timer, overriding the existing timer with the new timer

    recreate() {
        console.log(this.CLASS, "recreate with", this.properties);
        this.AppTimer.init(this.properties);        
    }