@tomekf/storage-ttl

Custom storage with JSON, TTL and protection against DOM exception when local storage is blocked

Stats

StarsIssuesVersionUpdatedCreatedSize
@tomekf/storage-ttl
100.0.47 months ago3 years agoMinified + gzip package size for @tomekf/storage-ttl in KB

Readme

@tomekf/storage-ttl

Custom storage with JSON, TTL and protection against DOM exception when local storage is blocked

Installation

npm i @tomekf/storage-ttl # or yarn add @tomekf/storage-ttl

Usage

import { sessionStorage }, localStorage from '@tomekf/storage-ttl';

const ttlInMiliseconds = 1000;

localStorage.setJsonWithTtl('pikok', { longTail: true }, ttlInMiliseconds);

const { longTail } = sessionStorage.getJsonWithTtl('sparrow');

Methods/props

length
support
originalStorage
setJson
getJson
setJsonWithTtl
getJsonWithTtl
setItem
getItem
removeItem
key
clear

Test

git clone git@github.com:tomek-f/storage-ttl.git
cd ./storage-ttl
npm i # or yarn
npm test # or yarn test
npm run eslint-src # or yarn (run) eslint-src

Versions

  • ES5 CommonJs @tomekf/storage-ttl/dist/…
  • ES6+ with ESM @tomekf/storage-ttl/src/…

Changelog

View on github.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.