# saber-storage

> 移动端的本地存储，兼容node平台

Latest version **2.0.0** (published 2015-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install saber-storage
pnpm add saber-storage
yarn add saber-storage
bun add saber-storage
```

## 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 | 2.0.0 |
| Published | 2015-06-19 |
| First published | 2015-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | ecomfe |
| Keywords | localstorage, storage |

## Links

- npm: https://www.npmjs.com/package/saber-storage
- Repository: https://github.com/ecomfe/saber-storage
- Homepage: https://github.com/ecomfe/saber-storage#readme
- Issues: https://github.com/ecomfe/saber-storage/issues
- npm.io page: https://npm.io/package/saber-storage

## Dependencies (2)

- [saber-lang](https://npm.io/package/saber-lang.md) ^2.0.0
- [express-session](https://npm.io/package/express-session.md) ^1.10.3

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2015-06-19
- 2.0.0-beta.1 — 2015-04-20
- 2.0.0-alpha.1 — 2015-03-04

## README

saber-storage
===

![Bower version](https://img.shields.io/bower/v/saber-storage.svg?style=flat-square) [![NPM version](https://img.shields.io/npm/v/saber-storage.svg?style=flat-square)](https://npmjs.org/package/saber-storage) [![Build Status](https://img.shields.io/travis/ecomfe/saber-storage.svg?style=flat-square)](https://travis-ci.org/ecomfe/saber-storage) [![License](https://img.shields.io/npm/l/saber-storage.svg?style=flat-square)](./LICENSE) [![EFE Mobile Team](https://img.shields.io/badge/EFE-Mobile_Team-blue.svg?style=flat-square)](http://efe.baidu.com)

移动端本地存储模块，提供 `memory`、`session` 与 `local` 三种存储模式，并且兼容 node 环境

## Installation

通过 [edp](https://github.com/ecomfe/edp) 引入模块：

```sh
$ edp import saber-storage
```

或者在 node 环境下使用 `npm` 引入模块：

```sh
$ npm install saber-storage --save
```

## Usage

```js
var Storage = require('saber-storage');

// 使用localStorage进行本地存储
var storage = new Storage('local');

// 存入
storage.setItem('string', 'this is a string');
storage.setItem('object', {a: 1});

// {a: 1}
storage.getItem('object');
```

## API

### Constructor

#### Storage(type)

* **type** `{string=}` 存储类型，支持以下取值：
    * **memory** 内存存储
    * **session** `sessionStorage` 存储
    * **local** `localStorage` 存储

node 环境下目前支持 `memory` 内存存储，可以做为 [rebas](https://github.com/ecomfe/rebas) 的插件提供基于内存的 `session` 数据存储

### Methods

#### setItem(key, val)

存入数据

* **key** `{String}` 存储键名
* **val** `{*}` 对应键名下的数据

#### getItem(key)

根据键名返回数据

* **key** `{String}` 存储键名
* _return_ `{*}` 对应键名下的数据

#### removeItem(key)

移除某键名下的数据

* **key** `{String}` 存储键名
* _return_ `{void}`

#### clear()

清空已持久化的数据

* _return_ `{void}`
 
#### key()

获得持久化数据的key

* _return_ `{Array}` 键名数组

#### getAllItems()

获取所有存储的数据

* _return_ `{Object}` 存储的数据

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