localstorage-mock

1.0.2 • Public • Published

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.

Package Sidebar

Install

npm i localstorage-mock

Weekly Downloads

0

Version

1.0.2

License

ISC

Last publish

Collaborators

  • sajadtorkamani