https://github.com/jednano/storage
A Storage class that implements the Storage interface of the Web Storage API.
https://github.com/jednano/storage
storage web
Last synced: 5 months ago
JSON representation
A Storage class that implements the Storage interface of the Web Storage API.
- Host: GitHub
- URL: https://github.com/jednano/storage
- Owner: jednano
- License: mit
- Created: 2019-02-17T05:41:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:39:31.000Z (over 3 years ago)
- Last Synced: 2025-06-03T21:59:59.426Z (about 1 year ago)
- Topics: storage, web
- Language: TypeScript
- Size: 1.46 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @jedmao/storage
[](https://github.com/jedmao/storage/actions)
[](https://www.npmjs.org/package/@jedmao/storage)
[](https://www.npmjs.org/package/@jedmao/storage)
[](https://codecov.io/gh/jedmao/storage)
[](https://bundlephobia.com/result?p=@jedmao/storage)
[](https://bundlephobia.com/result?p=@jedmao/storage)
[](https://github.com/prettier/prettier)
[](https://twitter.com/sindresorhus/status/457989012528316416?ref_src=twsrc%5Etfw&ref_url=https%3A%2F%2Fwww.quora.com%2FWhat-does-the-unicorn-approved-shield-mean-in-GitHub)
[](https://nodei.co/npm/@jedmao/storage/)
A `Storage` class that implements the [Storage](https://developer.mozilla.org/en-US/docs/Web/API/Storage) interface of the [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API).
This class comes out-of-the-box with [TypeScript][] type annotations and [TSDoc](https://github.com/Microsoft/tsdoc#tsdoc) comments.
## Installation
```
$ npm install [--save[-dev]] @jedmao/storage
```
## Usage
```ts
import { Storage } from '@jedmao/storage'
const data = { bar: 42 }
const storage = new Storage()
storage.setItem('foo', data)
storage.getItem('foo') // "[object Object]"
storage.setItem('foo', JSON.stringify(data))
storage.getItem('foo') // "{"bar":42}"
storage.setItem('baz', 42)
storage.getItem('baz') // '42'
storage.key(1) // 'baz'
storage.length // 2
storage.removeItem('foo')
storage.length // 1
storage.clear()
storage.length // 0
```
[typescript]: http://www.typescriptlang.org/