Skip to content

uniquexiaobai/tiny-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinyStorage

A tiny localStorage API

Install

npm install @lokibai/tiny-storage

Usage

import tinyStorage from '@lokibai/tiny-storage';
// const tinyStorage = require('tiny-storage');

tinyStorage.get('a', 1);
tinyStorage.set('b', { x: 2 });
tinyStorage.set('c', 3, { maxAge: 60 }); // expires after 1 minute

tinyStorage.get('b'); // output: { x: 2}

tinyStorage.remove('a'); // remove a item

tinyStorage.size(); // output: 2

tinyStorage.clear(); // remove all items

tinyStorage.size(); // output: 0

// create a new instance, different instance don't affect each other
const instance = tinyStorage.create({
  name: 'mystorage', // prefix for the key
  driver: sessionStorage, // default: localStorage
  maxAge: 60, // set the default maxAge
});