Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michalzalecki/storage-factory
Because using localStorage directly is a bad idea
https://github.com/michalzalecki/storage-factory
Last synced: 22 days ago
JSON representation
Because using localStorage directly is a bad idea
- Host: GitHub
- URL: https://github.com/michalzalecki/storage-factory
- Owner: MichalZalecki
- Created: 2018-09-26T16:00:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-07T13:42:13.000Z (almost 2 years ago)
- Last Synced: 2024-12-09T18:11:19.948Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/storage-factory
- Size: 388 KB
- Stars: 63
- Watchers: 4
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# storage-factory
[![CircleCI](https://circleci.com/gh/MichalZalecki/storage-factory.svg?style=svg)](https://circleci.com/gh/MichalZalecki/storage-factory)
This library is a [tiny](https://bundlephobia.com/result?p=storage-factory) (414B) wrapper for `localStorage` and `sessionStorage` because using Storage directly is a bad idea. Here's the blogpost that explains [why is that](https://michalzalecki.com/why-using-localStorage-directly-is-a-bad-idea/).
**Warning**: object access (e.g. `localStorage.foo`) is not yet implemented 💥
## Usage
Somewhere in your project
```js
// storage.js
import { storageFactory } from "storage-factory";export const local = storageFactory(() => localStorage);
export const session = storageFactory(() => sessionStorage);
```When you need to use storage
```js
import * as storage from "./storage";function login(token) {
storage.local.setItem("token", token);
// do your other login things
}
```## Example
Run the example using [parcel](https://parceljs.org/)
```bash
npx parcel example/index.html
```## Contribute
Do you want to contribute? Awesome! Please, create an issue first and tell me about it.