session-helper
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "session-helper", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "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.", | ||
@@ -5,0 +5,0 @@ "main": "dist/SessionHelper.js", |
# 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. | ||
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. | ||
@@ -27,5 +27,5 @@ ## Usage | ||
// es5 | ||
var SessionHelper = require('session-helper') | ||
const SessionHelper = require('session-helper') | ||
var sessionHelper = new SessionHelper( | ||
const sessionHelper = new SessionHelper( | ||
"123-my-unique-id-here", // uuid | ||
@@ -43,8 +43,8 @@ "localStorage", // cache location: choose between 'localStorage' or 'sessionStorage' | ||
To get expiry from storage: | ||
`var expiryFromStorage = SessionHelper.expiry` | ||
Function to get expiry from storage: | ||
`let expiryFromStorage = SessionHelper.expiry` | ||
#### setExpiry | ||
To set expiry from storage: | ||
Function to set expiry from storage: | ||
`SessionHelper.setExpiry()` | ||
@@ -54,3 +54,3 @@ | ||
To remove expiry from storage: | ||
Function to remove expiry from storage: | ||
`SessionHelper.removeExpiry()` | ||
@@ -60,19 +60,19 @@ | ||
To check if expiry in storage is set and is expired: | ||
`var isTokenExpired = SessionHelper.isTokenExpired` | ||
Boolean to check if expiry in storage is set and is expired: | ||
`let isTokenExpired = SessionHelper.isTokenExpired` | ||
#### isTokenExpiredOrNull | ||
To check if expiry in storage is set and is expired, or if it is not set: | ||
`var isTokenExpiredOrNull = SessionHelper.isTokenExpiredOrNull` | ||
> It can be null when, for example, there are multiple tabs open and one of the tabs has called 'removeExpiry' before the other. Then the expiry is null in the other, while you still want it to be interpreted as 'expired'. | ||
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 | ||
To get the amount of time left in seconds until the expiry is reached (if the timer has started and the callback is set): | ||
`var timeLeftUntilExpiryIsReached = SessionHelper.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 | ||
To set a callback function which will trigger when the timeout function ends: | ||
Variable to set a callback function which will trigger when the timeout function ends: | ||
@@ -87,3 +87,3 @@ ``` javascript | ||
To get the callback function which will be triggered at the end of the timeout function: | ||
`var callback = SessionHelper.expiryTimeoutCallback` | ||
`let callback = SessionHelper.expiryTimeoutCallback` | ||
> You can trigger this callback manually by adding extra parentheses like so: `SessionHelper.expiryTimeoutCallback()` | ||
@@ -93,3 +93,3 @@ | ||
To start the timeout function, using the timeoutInMinutes configuration parameter: | ||
Function to start the timeout function, using the timeoutInMinutes configuration parameter: | ||
`SessionHelper.startExpiryTimeout()` | ||
@@ -99,3 +99,3 @@ | ||
To stop the timeout function: | ||
Function to stop the timeout function: | ||
`SessionHelper.stopExpiryTimeout()` | ||
@@ -105,3 +105,3 @@ | ||
To restart the timeout function, using the timeoutInMinutes configuration parameter. Underlying it's simply calling _.stopExpiryTimeout_ and _.startExpiryTimeout_: | ||
Function to restart the timeout function, using the timeoutInMinutes configuration parameter. Underlying it's simply calling _.stopExpiryTimeout_ and _.startExpiryTimeout_: | ||
`SessionHelper.resetExpiryTimeout()` | ||
@@ -112,6 +112,7 @@ | ||
* add tests | ||
* catch situations where the timeout is being started but there is no callback set | ||
* 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 trigger a callback based on the polled results instead of the timeout function | ||
* 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) | ||
@@ -118,0 +119,0 @@ ## Contributing |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
15951
0
117