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

session-helper

v1.0.5

Published

Session helper is a module that helps you save an expiry time to your local/session storage, be able to performs checks against it, and perform callbacks when this expiry time has been reached.

Downloads

297

Readme

Session-Helper

Session Helper is a module that helps you save a timestamp as an 'expiry time' to your local/session storage to be able to perform checks against it and to trigger callbacks when this expiry time has been reached.

npm version

Usage

0) Install

npm install session-helper --save

1) initialize the session helper with a unique id so that it does not conflict with others also using this package

// es6
import SessionHelper from 'session-helper'

export default new SessionHelper(
  "123-my-unique-id-here",    // uuid
  "localStorage",             // cache location: choose between 'localStorage' or 'sessionStorage'
  30,                         // timeout in minutes
  true,                       // debugMode, 'false' by default, enable it to push log messages to console
)
// es5
const SessionHelper = require('session-helper')

const sessionHelper = new SessionHelper(
  "123-my-unique-id-here",    // uuid
  "localStorage",             // cache location: choose between 'localStorage' or 'sessionStorage'
  30,                         // timeout in minutes
  true,                       // debugMode, 'false' by default, enable it to push log messages to console
)

2) use the following methods to manipulate your session/local storage

expiry

Function to get expiry from storage: let expiryFromStorage = SessionHelper.expiry

setExpiry

Function to set expiry from storage: SessionHelper.setExpiry()

removeExpiry

Function to remove expiry from storage: SessionHelper.removeExpiry()

isTokenExpired

Boolean to check if expiry in storage is set and is expired: let isTokenExpired = SessionHelper.isTokenExpired

isTokenExpiredOrNull

Boolean to check if expiry in storage is set and if it is expired, or if it is not even set: let isTokenExpiredOrNull = SessionHelper.isTokenExpiredOrNull

Important: It can be null when, for example, there are two tabs (or more) open and the first tab has called removeExpiry() before the second. Then the expiry will be null in the second, meaning the Session Helper would interpret it as "it is not set" instead of "it is set and expired" because of the other tab. This might be useful when an expiry had to log out a user in the first tab and thus in the second there can be checked if the user is still logged in or not by checking the isTokenExpiredOrNull boolean.

expiryTimeout

Boolean to get the amount of time left in seconds until the expiry is reached (if the timer has started and the callback is set): let timeLeftUntilExpiryIsReached = SessionHelper.expiryTimeout

expiryTimeoutCallback

Variable to set a callback function which will trigger when the timeout function ends:

SessionHelper.expiryTimeoutCallback = function() {
  console.log('Expiry has been reached')
  // perform actions like a logout
}

To get the callback function which will be triggered at the end of the timeout function: let callback = SessionHelper.expiryTimeoutCallback

You can trigger this callback manually by adding extra parentheses like so: SessionHelper.expiryTimeoutCallback()

startExpiryTimeout

Function to start the timeout function, using the timeoutInMinutes configuration parameter: SessionHelper.startExpiryTimeout()

stopExpiryTimeout

Function to stop the timeout function: SessionHelper.stopExpiryTimeout()

resetExpiryTimeout

Function to restart the timeout function, using the timeoutInMinutes configuration parameter. Internally it's simply calling .stopExpiryTimeout and .startExpiryTimeout: SessionHelper.resetExpiryTimeout()

TODO

  • add tests
  • catch situations where the timeout is being started/reached but there is no callback set
  • add pause functionality
  • add functionality to poll the session/local storage and to trigger a callback based on the polled results instead of the timeout function
  • add link(s) to blogpost(s)
  • proposal: refactor the expiryTimeout to time in seconds instead of in minutes (something for v2)

Contributing

PRs are more than welcome and will be reviewed asap!

License

MIT - For full license see the LICENSE file.