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

inactivity-countdown-timer

v2.0.0-beta-2

Published

A plain JS (Typescript) module that will countdown and timeout when users are inactive/idle.

Downloads

2,364

Readme

inactivity-countdown-timer

A plain JS (Typescript) module that will countdown and timeout when users are inactive/idle.

Can be used to transition away from sensitive on screen information and redirect to another page. Useful when a user forgets to close their browser or tab before walking away from their computer.

Install

npm install inactivity-countdown-timer --save

Usage

// Optional config vars
const settings = {
    idleTimeoutTime?: number;
    startCountDownTimerAt?: number;
    resetEvents?: string[]; // document events
    throttleDuration?: number;
    localStorageKey?: string;
    windowResetEvents?: string[];
    timeoutCallback?(): void;
    countDownCallback?(secondsLeft: number): void;
    countDownCancelledCallback?(): void;
}

// Instantiate new logout object
const IL = new InactivityLogout(settings);

// make sure you cleanup the object when you are finished using it.
// will not be garbage collected unless you clean it up because of the timers
IL.cleanup()

See the demo code for a detailed example

run npm start to view the demo locally

Features

  • A count down callback - alert users you are going to transition them.
  • Activity is synced across tabs using local storage (users won't be transitioned if they are active in any other tab).
  • Dynamically adjusting timer. Which will set itself to initially timeout when the count down starts, then change to timeout every second for the countdown.
  • Will fall back to a 30 minute timeout if you pass an invalid number as the inactivityTimeoutTime (pass a valid number)
  • Configure what events reset your timer and count as an 'Activity' by passing in you're own reset event list.
  • Throttle the event listeners (so listeners like mouse move are not constantly firing) - will affect precise timing
  • Written in typescript and bundled as a UMD module.
  • Tests with a saucelabs setup for cross browser testing.

Events

By default the inactivity timeout is reset by these document events:

  • clicks
  • mousemovement
  • keypresses

and this window event

  • load

Throttle

When you enable the throttle option by passing a throttle config value greater than zero, event listeners are disabled for the period specified after any event listener is fired from any configured event.

If you have a 5 minute idle timeout time, and a 15 second throttle, you have an effective idle timeout range of 4 minutes and 45 seconds as you may miss the first 15 seconds of activity whenever the timer is reset.

To prevent poor config you cannot set a throttle time > 1/5 the internal timeout time. Internal timeout time is calculated as idleTimeoutTime - startCountdownTimer.

So a 5 minute timeout with a 30 second countdown timer you have a 4 minute and 30 second internal timeout time, meaning the greatest throttle you can have is 1/5 of 4 min 30 seconds 54 seconds ... 10 to 30 seconds is probably a good number anyway :)

Supports

  • IE9 with core-js (import 'core-js/features/object/assign' ;)
  • IE10+
  • Chrome
  • Firefox
  • Safari

Development

The project is setup with both main.ts used for exporting the library and a demo.ts used to demo components and setup testing.

Installing

npm install installs node modules and runs tests

NPM Tasks

  • npm start runs a development server
  • npm test runs the tests via karma (from the main ts file)
  • npm test-via-saucelabs runs the tests via karma against Saucelabs config(from the main ts file)
  • npm build builds a version for distribution via npm

Publishing workflow

  1. Run tests npm test
  2. Run build and check that your module was built (needs to be exported via main.ts)
  3. Install it into your project to test before publishing by running npm install '/path-to-this/'
  4. Bump version in package.json following Semantic Versioning SemVer
  5. Tag the release commit in git: git tag -a v0.1.5 -m "Published v0.1.5"
  6. Push the tags up to github: git push origin --tags
  7. Publish npm publish

Big Thanks

Cross-browser Testing Platform and Open Source <3 Provided by Sauce Labs

Benefex

This module was originally published with support from Benefex. Benefex