# localstorage-ponyfill

> Universal LocalStorage for browser and Node.js.

Latest version **1.0.2** (published 2018-12-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install localstorage-ponyfill
pnpm add localstorage-ponyfill
yarn add localstorage-ponyfill
bun add localstorage-ponyfill
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-12-23 |
| First published | 2017-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 55 |
| Author | azu |
| Maintainers | azu |
| Keywords | browser, isomophic, localstorage, node, universal |

## Links

- npm: https://www.npmjs.com/package/localstorage-ponyfill
- Repository: https://github.com/azu/localstorage-ponyfill
- Issues: https://github.com/azu/localstorage-ponyfill/issues
- npm.io page: https://npm.io/package/localstorage-ponyfill

## Dependencies (4)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [app-root-path](https://npm.io/package/app-root-path.md) ^2.1.0
- [node-localstorage](https://npm.io/package/node-localstorage.md) ^1.3.1
- [localstorage-memory](https://npm.io/package/localstorage-memory.md) ^1.0.3

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-12-23
- 1.0.1 — 2017-08-18

## README

# localstorage-ponyfill [![Build Status](https://travis-ci.org/azu/localstorage-ponyfill.svg?branch=master)](https://travis-ci.org/azu/localstorage-ponyfill)


Universal LocalStorage ponyfill library for browser and Node.js.

## Install

Install with [npm](https://www.npmjs.com/):

    npm install localstorage-ponyfill

## Usage

### Auto(Browser or Node.js)

Automatically select mode.

```js
import { createLocalStorage } from "localstorage-ponyfill";
const localStorage = createLocalStorage();
localStorage.setItem("key", "value");
const value = localStorage.getItem("key");
assert.strictEqual(value, "value");        
```

### Browser

Native localStorage.

```js
import { createLocalStorage } from "localstorage-ponyfill";
const localStorage = createLocalStorage({ mode : "browser" });
```

### Node.js

Use [node-localstorage](https://github.com/lmaccherone/node-localstorage "node-localstorage")

Store data to `<app-root>/.cache/localstorage-ponyfill/*` by default.
You can setting the path by `storeFilePath` option.

```js
import { createLocalStorage } from "localstorage-ponyfill";
const localStorage = createLocalStorage({ mode : "node" });
```

### In memory

Use [localstorage-memory](https://github.com/gr2m/localstorage-memory "localstorage-memory")

```js
import { createLocalStorage } from "localstorage-ponyfill";
const localStorage = createLocalStorage({ mode : "memory" });
```

## API

Same with [Window.localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)

```ts
export interface LocalStoragePonyfill {
    readonly length: number;

    clear(): void;

    getItem(key: string): string | null;

    key(index: number): string | null;

    removeItem(key: string): void;

    setItem(key: string, data: string): void;

    [key: string]: any;

    [index: number]: string;
}

```

## Changelog

See [Releases page](https://github.com/azu/localstorage-ponyfill/releases).

## Running tests

Install devDependencies and Run `npm test`:

    npm i -d && npm test

## Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, [please create an issue](https://github.com/azu/localstorage-ponyfill/issues).

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## Author

- [github/azu](https://github.com/azu)
- [twitter/azu_re](https://twitter.com/azu_re)

## License

MIT © azu

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