# cross-platform-storage

> cross-platform-storage是跨平台开源统一storage交互库

Latest version **1.0.1** (published 2019-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install cross-platform-storage
pnpm add cross-platform-storage
yarn add cross-platform-storage
bun add cross-platform-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 | 1.0.1 |
| Published | 2019-05-21 |
| First published | 2019-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | landfei |
| Maintainers | landfei |

## Links

- npm: https://www.npmjs.com/package/cross-platform-storage
- Repository: https://github.com/tactic-live/cross-platform-storage
- Homepage: https://github.com/tactic-live/cross-platform-storage#readme
- Issues: https://github.com/tactic-live/cross-platform-storage/issues
- npm.io page: https://npm.io/package/cross-platform-storage

## Recent versions

- 1.0.1 (latest) — 2019-05-21
- 1.0.0 — 2019-05-21

## README

# cross-platform-storage

cross-platform-storage是跨平台开源统一storage交互库

## Feature
* support h5 and 微信小程序

## install

## Getting started
### npm
```bash
npm install cross-platform-storage --save
```
### yarn
```bash
yarn add cross-platform-storage
```

## Usage

## ES5
```js
var storage = require('cross-platform-storage').getStorage();
```
## ES6
```js
import CrossStorage from 'cross-platform-storage';
const storage = CrossStorage.getStorage();
```

## API 
### getStorage(type)

type | 说明
---|---
session | 返回sessionStorage
local | 返回localStorage
miniprogram | 返回小程序wrapped微信对象
空 | 根据环境自动判断 小程序环境返回wrapped微信对象, web环境返回sessionStorage对象

### setItem 同步写入
```js
storage.setItem('foo', 'foo');
```
### getItem 同步获取
```js
const result = storage.getItem('foo');
console.log(result);
// console result 'foo'
```
### setItemAsync 异步写入
```js
storage.setItem('foo', 'foo').then(function(){
    console.log('success');
});
// console 'success'
```
### getItemAsync 异步获取
```js
storage.getItem('foo').then(function(result){
    console.log(result);
});
// console 'foo'
```

## Change Log

### 1.0.1
change license to MIT

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