# @wedjs/storage

> ----

Latest version **1.0.0-Alpha.7** (published 2020-09-19) · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-Alpha.7 |
| Published | 2020-09-19 |
| First published | 2020-09-18 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | w_494917128 |
| Maintainers | w_494917128 |

## Links

- npm: https://www.npmjs.com/package/@wedjs/storage
- npm.io page: https://npm.io/package/@wedjs/storage

## Dependencies (2)

- [clean-webpack-plugin](https://npm.io/package/clean-webpack-plugin.md) ^3.0.0
- [terser-webpack-plugin](https://npm.io/package/terser-webpack-plugin.md) ^4.2.0

## Recent versions

- 1.0.0-Alpha.7 (latest) — 2020-09-19
- 1.0.0-Alpha.5 — 2020-09-19
- 1.0.0-Alpha.4 — 2020-09-18

## README

# @wedjs/storage

----

## 介绍

**数据存储** 封装

----

## 安装

通过 `NPM` 安装：
``` base
npm i @wedjs/storage
```
或者 直接引用 `CDN`：
``` html
<script src="https://cdn.wangerdi.cn/wedjs/storage.js"></script>
```

----

## 使用

> #### _.setStorage(key, value, expires)
> #### _.setSession(key, value, expires)

存储数据( **localStorage** / **sessionStorage** )，未传有效时间则永久有效。  
数据将会被 **JSON.stringify()** 转换为字符串存入。  

##### 注意

仅可储存 **基本数据类型** `String` `Number` `Boolean` `Undefined` `Null` 以及内容无这几类以外的 `Object` `Array` 类数据，因为 `JSON.stringify` 不可转换其他类数据。

##### 参数

| 参数名 | 类型 | 默认值 | 是否必填 | 描述 |
| --- | --- | --- | --- | --- |
| key | String |  | 必填 | 存储的键值 |
| value | String or Array or Object |  | 必填 | 存储内容 |
| expires | Number |  | 可选 | 有效时间（单位：秒） |

#### 示例

``` js
  _.setStorage('a', { a: 1 })
  _.setStorage('b', { b: 2 }, 1)
  setTimeout(() => {
      console.log(_.getStorage('a')) // { a: 1 }
      console.log(_.getStorage('b')) // null
  },1000)
```

> #### _.getStorage(key)
> #### _.getSession(key)

获取存储的数据。

##### 参数

| 参数名 | 类型 | 默认值 | 是否必填 | 描述 |
| --- | --- | --- | --- | --- |
| key | String |  | 必填 | 存储的键值 |

> #### _.removeStorage(key)
> #### _.removeSession(key)

删除存储的数据。

##### 参数

| 参数名 | 类型 | 默认值 | 是否必填 | 描述 |
| --- | --- | --- | --- | --- |
| key | String |  | 必填 | 存储的键值 |

> #### _.clearStorage()
> #### _.clearSession()

清空缓存数据。

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