@jedmao/storage
v3.0.0
Published
A Storage class that implements the Storage interface of the Web Storage API.
Downloads
608
Maintainers
Readme
@jedmao/storage
A Storage
class that implements the Storage interface of the Web Storage API.
This class comes out-of-the-box with TypeScript type annotations and TSDoc comments.
Installation
$ npm install [--save[-dev]] @jedmao/storage
Usage
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