local-storage-mock

localStorage mock for NodeJS.

Usage no npm install needed!

<script type="module">
  import localStorageMock from 'https://cdn.skypack.dev/local-storage-mock';
</script>

README

Local Storage

[Author: Hussain Mir Ali]

Local Storage mock for testing browser code in NodeJS.

To use the project:

run: npm install -g local-storage-mock

Sample usage:

var lstorage = require('local-storage-mock');

lstorage.setItem('Hello', 'World');
lstorage.setItem('Node', 'JS');
lstorage.setItem('Weight', 100);
lstorage.setItem('Car', {'Engine': 'V8', 'Make': 'BMW', 'Year': 2013});
lstorage.setItem('Words', ['Pen', 'Pineapple', 'Apple','Pen']);

console.log(lstorage.getItem('Hello')==='World');//true
console.log(lstorage.getItem('Weight')===100);//true

console.log(lstorage.getlength() === 5);//true

lstorage.removeItem('Hello');

console.log(lstorage.getlength() === 4);//true

console.log(lstorage.key(0) === 'Node');//true