# @zcorky/storage

> A minimal API wrapper for localStorage

Latest version **1.4.7** (published 2023-04-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zcorky/storage
pnpm add @zcorky/storage
yarn add @zcorky/storage
bun add @zcorky/storage
```

## 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.4.7 |
| Published | 2023-04-06 |
| First published | 2019-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 55.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Zero |
| Maintainers | uniquecolesmith |
| Keywords | zcorky, storage, store, lockr, typescript |

## Links

- npm: https://www.npmjs.com/package/@zcorky/storage
- Repository: https://github.com/zcorky/storage
- Issues: https://github.com/zcorky/storage/issues
- npm.io page: https://npm.io/package/@zcorky/storage

## Dependencies (1)

- [@zcorky/fz](https://npm.io/package/@zcorky/fz.md) ^1.2.15

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.4.7 (latest) — 2023-04-06
- 1.4.6 — 2023-04-06
- 1.4.5 — 2023-04-06
- 1.4.4 — 2023-02-06
- 1.4.2 — 2022-08-25
- 1.4.0 — 2022-04-26
- 1.3.6 — 2022-04-25
- 1.3.5 — 2022-04-25
- 1.3.3 — 2022-04-25
- 1.3.2 — 2022-04-24
- 1.3.1 — 2022-04-24
- 1.3.0 — 2022-04-24
- 1.2.3 — 2021-01-17
- 1.2.2 — 2020-12-21
- 1.2.1 — 2020-12-17
- … 4 more at https://npm.io/package/@zcorky/storage/versions

## README

# storage

[![NPM version](https://img.shields.io/npm/v/@zcorky/storage.svg?style=flat)](https://www.npmjs.com/package/@zcorky/storage)
[![NPM quality](http://npm.packagequality.com/shield/%40zcorky%2Fstorage.svg)](http://packagequality.com/#?package=@zcorky/storage)
[![Coverage Status](https://codecov.io/gh/zcorky/storage/branch/master/graph/badge.svg)](https://codecov.io/gh/zcorky/storage)
[![Dependencies](https://img.shields.io/david/zcorky/storage.svg?style=flat-square)](https://david-dm.org/zcorky/storage)
[![Build Status](https://travis-ci.com/zcorky/storage.svg?branch=master)](https://travis-ci.com/zcorky/storage)
[![Known Vulnerabilities](https://snyk.io/test/npm/@zcorky/storage/badge.svg?style=flat-square)](https://snyk.io/test/npm/@zcorky/storage)
[![NPM download](https://img.shields.io/npm/dm/@zcorky/storage.svg?style=flat-square)](https://www.npmjs.com/package/@zcorky/storage)
![license](https://img.shields.io/github/license/zcorky/storage.svg)
[![issues](https://img.shields.io/github/issues/zcorky/storage.svg)](https://github.com/zcorky/storage/issues)

> A minimal API wrapper for localStorages, inspired by [tsironis/lockr](https://github.com/tsironis/lockr) and [marcuswestin/store.js](https://github.com/marcuswestin/store.js). It is written fully with Typescript.

* 🕒 Familiar `store` API & patterns
* 🔥 TypeScript

## Install

```
$ npm install @zcorky/storage
```

## Usage


```js
import storage from '@zcorky/storage';

// set sets the value of the given key
// suport maxAge, unit: ms
storage.set('user', { name:'Marcus' }, 30 * 1000)

// get returns the value of the given key
storage.get('user')

// remove removes the value of the given key
storage.remove('user')

// clear clears the storage
storage.clear()

// keys returns the keys of the storage
storage.keys()

// getAll returns the all items of the storage
storage.getAll()

// has checks whether the given key exists
storage.has('user')
```

### Enhancement

```js
// built-in drivers
//  local       - use localStorage
//  session     - use sessionStorage
//  indexeddb   - use IndexedDB
//  service     - use service with http request
storage.setDriver('session')

// custom prefix
storage.setPrefix('my-prefix-')
```

## Advanced Usage

### 1. Create a new Storage
Default storage is a global storage with singleton pattern.
If you want to create a new storage, you can use `storage.create()` method.

```js
const storage = storage.create(options);
```

### 2. Create Custom Driver

```typescript
import { StorageDriver } from '@zcorky/storage';

// 1. Create a class implements StorageDriver
export class CustomStorage extends StorageDriver {
  ...
}

// 2. Register the driver
storage.setDriver('custom', CustomStorage)
```

### API
* See the detailed [API Reference](./docs).

### Relatived
* [lockr](https://github.com/tsironis/lockr) -  A minimal API wrapper for localStorages.
* [store](https://github.com/marcuswestin/store.js)

## License

MIT © [Moeover](https://moeover.com)

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