Skip to content
/ storage Public

A very minimal js local storage api that friendly for TypeScript

Notifications You must be signed in to change notification settings

necolo/storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

storage

A very simple JavaScript localStorage api for TS.

npm i @necolo/storage

Usage

import Storage from '@necolo/storage';

// create Storage instance with initialized values
// the default target is localStorage
const storage = new Storage({
  b: false,
  n: 1,
  s: 'sample',
});

// get storage value
const value = storage.get('n'); // 1
// typeof value === 'number'

// set storage value
storage.set('n', 99);
const value2 = storage.get('n'); // 99

// can delete the key
storage.del('n');
storage.get('n'); // will return the default value, which is 1

// clear all
storage.clear();

You can also use it for sessionStorage

const session = new Storage(
  {
    // put initialize value here
    foo: 'bar,
  },
  sessionStorage, // put sessionStorage as the target
);

const value = session.get('foo');
session.set('foo', 'otherValue');

About

A very minimal js local storage api that friendly for TypeScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published