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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@frshaw1/angular-visibility-api

v1.0.6

Published

An Angular and RxJS enabled event publisher for the browser's visibility API

Readme

Angular Visibility API

This is an Angular service for interacting with Browser's Visibility API. This API is useful when you want to know whether your application is currently being viewed by the user or if the tab/window is in the background.

Usage

To use this service, the VisibilityModule must be imported into your app or dependent module.

@NgModule({
  ...
  imports: [
    ...,
    VisibilityModule,
    ...
  ]
})
export class MyModule {}

VisibilityService

The visibility service works in all major browsers. If the browser does not have support for the visibility API, the service will fallback to a legacy method for determining browser visibility.

The service has a single public method onVisibilityChange which returns an Observable<Boolean>. When the caller subscribes to the visibility changes of the Observable, the subscribe handler will be called immediately with the current value of the browser's visibility. All future changes to the visibility will be published to all subscribing methods.

For more information see the example below.

@Component({
  ...
})
export class MyComponent {
  constructor(private visibility: VisibilityService) {}
  
  ...
  
  this.visibility.onVisibliltyChange().subscribe((isVisible) => {
    if (isVisible) {
      //perform actions that need to be done when browser if visible
    } else {
      //perform actions when browser has been hidden
    }
  })
}

Decorators

There is also the option to use provided method decorators to decorate methods that should only be run based on a certain browser visibility or when the visibility of the browser changes

@OnVisibilityChange()

Any method decorated with this annotation will be called each time the browser visibility changes. This is very similar to subscribing to events from the VisibilityService, just providing another convenience method for interacting with the service. Methods decorated with this annotation should accept one parameter isVisible that will be provided to the decorated method when the visibility change fires.

export class MyComponent {
  ...
  
  @OnVisibilityChange()
  visibilityChanged(isVisible: Boolean) {
    if (isVisible) {
      //perform actions that need to be done when browser if visible
    } else {
      //perform actions when browser has been hidden
    }
  }
}

@WhenVisibilityIs(isVisible: Boolean)

Another method for interacting with the VisibilityService is to decorate a method with this decorator. The @WhenVisibilityIs decorator takes a boolean value that indicates, based on the provided browser visibility status, whether the decorated method should be invoked or not.

export class MyComponent {
  ...
  @WhenVisibilityIs(true)
  executeOnlyWhenVisible(someArg: string, anotherArg: number) {
    //this method only gets invoked (when called) if the application window is determined to be visible to the user.
  }
  
  @WhenVisibilityIs(false)
  executeOnlyWhenHidden() {
    //this method only gets invoked (when called) if the application window is determined to be hidden to the user.
  }
}