@supercoder123/localstorage-with-expiry
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

@supercoder123/localstorage-with-expiry

Micro library written in typescript which adds expiry time (in seconds) to localstorage

Installation

NPM

npm i @supercoder123/localstorage-with-expiry

CDN (882 bytes)

<script src="https://cdn.jsdelivr.net/npm/@supercoder123/localstorage-with-expiry@1.0.0/dist/lib-umd/LS.min.js"></script>

Usage

const ls = new LS();  // default storage class is localstorage

// pass sessionStorage in the constructor to use sessionStorage
const ls = new LS(window.sessionStorage); 

// no expiry
ls.setItem('key', 'value');  

// expiry time in seconds
ls.setItem('key', 'value', 5)  

// no need to stringify, uses JSON.stringity internally
ls.setItem('key', {test: 'yay'});

// get Item
ls.getItem('key');

// remove Item
ls.removeItem('key');

// clear all
ls.clear();

// list all
ls.list();   // prints key value in the console

Readme

Keywords

none

Package Sidebar

Install

npm i @supercoder123/localstorage-with-expiry

Weekly Downloads

2

Version

1.1.1

License

ISC

Unpacked Size

12.1 kB

Total Files

10

Last publish

Collaborators

  • supercoder123