# localStorage

> W3C localStorage for Node.JS

Latest version **1.0.4** (published 2018-10-10) · (MIT OR Apache-2.0) license · 0 weekly downloads

## Install

```sh
npm install localStorage
pnpm add localStorage
yarn add localStorage
bun add localStorage
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-10-10 |
| First published | 2011-07-22 |
| Weekly downloads | 0 |
| License | (MIT OR Apache-2.0) |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= v0.2.0 |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | AJ ONeal |
| Maintainers | coolaj86 |

## Links

- npm: https://www.npmjs.com/package/localStorage
- Repository: https://git.coolaj86.com/coolaj86/local-storage.js
- npm.io page: https://npm.io/package/localStorage

## Recent versions

- 1.0.4 (latest) — 2018-10-10
- 1.0.3 — 2014-10-07
- 1.0.2 — 2013-01-26
- 1.0.1 — 2013-01-26
- 1.0.0 — 2011-07-22

## README

# DOMStorage

See https://git.coolaj86.com/coolaj86/dom-storage.js for a slightly better version of the same thing.

# localStorage

An inefficient, but as W3C-compliant as possible using only pure JavaScript, `localStorage` implementation.

## Purpose

This is meant for the purpose of being able to run unit-tests and such for browser-y modules in node.

## Usage

    var localStorage = require('localStorage')
      , myValue = { foo: 'bar', baz: 'quux' }
      ;

    localStorage.setItem('myKey', JSON.stringify(myValue));
    myValue = localStorage.getItem('myKey');

## API

  * getItem(key)
  * setItem(key, value)
  * removeItem(key)
  * clear()
  * key(n)
  * length

## Tests

    null === localStorage.getItem('key');

    0 === localStorage.length;
    null === localStorage.getItem('doesn't exist');
    undefined === localStorage['doesn't exist'];

    localStorage.setItem('myItem');
    "undefined" === localStorage.getItem('myItem');
    1 === localStorage.length;

    localStorage.setItem('myItem', 0);
    "0" === localStorage.getItem('myItem');

    localStorage.removeItem('myItem', 0);
    0 === localStorage.length;

    localStorage.clear();
    0 === localStorage.length;

TODO / Bugs
---

  * Does not persist.
    * could use `fs.readFileSync` at load and an occasional `fs.writeFile` to write-out localStorage.json
  * Doesn't not emit `Storage` events

---
_Source: https://npm.io/package/localStorage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
