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

ng-timeout

v0.0.4

Published

Creates observables for user idle and timeout with manual interrupts. Detects interrupts across browser tabs with [storage-emitter](https://github.com/alekseykulikov/storage-emitter).

Downloads

8

Readme

ng-timeout

This is the version-agnostic project for https://github.com/jackjamieson/ng2-timeout

I will not be updating ng2-timeout although in my testing it was working up to Angular 7. This project is recreated in Angular's new library generation and will be much easier to update and maintain.

Creates observables for user idle and timeout with manual interrupts. Detects interrupts across browser tabs with storage-emitter.

Installation

To install this library, run:

$ npm install ng-timeout storage-emitter --save

Consuming library

Import library in any Angular application from your Angular AppModule:

// Import library
import { NgTimeoutService } from 'ng-timeout';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
  ],
  providers: [ NgTimeoutService ],
  bootstrap: [AppComponent]
})
export class AppModule { }

To use the module I recommend injecting the service into your top level app component.
From there you can control what causes interrruptions to the timers and how you want to handle idle or timeout.

import { NgTimeoutService } from '../ng-timeout';

private idleState: string; // if you want to show the countdown for example

constructor( private timeoutService: NgTimeoutService ) {

  this.timeoutService.setTimeToIdle(60 * 10); // 10 minutes of no interrupts will set the user to idle
  this.timeoutService.setTimeToTimeout(60); // 1 minute of no timeout interrupts will set the user as timed out

  // subscribe to the idle observable
  this.timeoutService.watchIdle().subscribe((isIdle: boolean) => {
    if (isIdle) {
      //  do something if the user becomes idle
    }
  });

  this.timeoutService.watchTimeout().subscribe((countdown: string) => {
    this.idleState = countdown;
    if(+countdown <= 0){
      // do something about the timeout
    }
  });
}

Here is an example @HostListener for detecting keypress

@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
  this.timeoutService.interruptIdle(); // interrupt the idle countdown and reset the timer if a key was pressed
  this.timeoutService.interruptTimeout(); // for illustration purposes we can also reset the timeout when a key is pressed

}

Development

The parent Angular project is included with this so it should be easy to set up and update. Follow Angular's guide on creating libraries.

  • npm install
  • edit projects/ng-timeout
  • ng build ng-timeout
  • output is in the dist folder

License

MIT © Jack Jamieson