@jedmao/storage

A Storage class that implements the Storage interface of the Web Storage API.

Usage no npm install needed!

<script type="module">
  import jedmaoStorage from 'https://cdn.skypack.dev/@jedmao/storage';
</script>

README

@jedmao/storage

GitHub Actions NPM version npm license codecov BundlePhobia Minified BundlePhobia Minified + gzip code style: prettier Unicorn Approved

npm

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