npm.io
1.0.2 • Published 8 years ago

localstorage-mock

Licence
ISC
Version
1.0.2
Deps
0
Vulns
0
Weekly
0

localstorage-mock

A mock implementation of Window.localStorage.

Usage

  1. Install package:
  • npm i localstorage-mock --save-dev
  1. Import / require module:
  • import 'localstorage-mock' or require('localstorage-mock')

Mock should now be accessible globally as localStorage.

API

  • getItem(key) - get item by key
  • setItem(key, value) - insert new item
  • clear() - clear storage
  • length - number of items in storage

Note: I realise there are already packages out there which implement local storage. I wrote this simply as a fun exercise in publishing my first npm module.