🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

storage-factory

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
s

storage-factory

Because using localStorage directly is a bad idea

0.2.1
latest
90

Supply Chain Security

100

Vulnerability

78

Quality

76

Maintenance

100

License

Version published
Weekly downloads
12K
1.71%
Maintainers
1
Weekly downloads
 
Created
Issues
6

storage-factory

CircleCI

This library is a tiny (414B) wrapper for localStorage and sessionStorage because using Storage directly is a bad idea. Here's the blogpost that explains why is that.

Warning: object access (e.g. localStorage.foo) is not yet implemented 💥

Usage

Somewhere in your project

// storage.js
import { storageFactory } from "storage-factory";

export const local = storageFactory(() => localStorage);
export const session = storageFactory(() => sessionStorage);

When you need to use storage

import * as storage from "./storage";

function login(token) {
  storage.local.setItem("token", token);
  // do your other login things
}

Example

Run the example using parcel

npx parcel example/index.html

Contribute

Do you want to contribute? Awesome! Please, create an issue first and tell me about it.

FAQs

Package last updated on 17 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts