# ynos-storage

> 本地存储库

Latest version **1.0.4** (published 2022-09-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install ynos-storage
pnpm add ynos-storage
yarn add ynos-storage
bun add ynos-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.0.4 |
| Published | 2022-09-08 |
| First published | 2022-07-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | yn36 |
| Maintainers | ynos |
| Keywords | 本地存储库, local, storage, session, sessionStorage, localStorage, vue3, vue2, ts |

## Links

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

## 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

- 1.0.4 (latest) — 2022-09-08
- 1.0.3 — 2022-09-08
- 1.0.2 — 2022-07-06
- 1.0.1 — 2022-07-01

## README

# ynos-storage

用于从js上下文处理localStorage、sessionStorage、memoryStorage

## 安装

#### NPM

```bash
npm install ynos-storage --save
```

#### Yarn

``` bash
yarn add ynos-storage
```

#### Bower

``` bash
bower install ynos-storage --save
```

## Development Setup

``` bash
# install dependencies
npm install

# build dist files
npm run build
```

## 使用

Vue2.x

``` js
import { Storage } from 'ynos-storage';

const options = {
  namespace: 'ynosjs__', // key prefix
  name: 'ls', // name variable Vue.[ls] or this.[$ls],
  storage: 'local', // storage name session, local, memory
};

Vue.use(Storage, options);

//or
//Vue.use(Storage);

new Vue({
    el: '#app',
    mounted: function() {
        Vue.ls.set('foo', 'boo');
        //Set expire for item
        Vue.ls.set('foo', 'boo', 60 * 60 * 1000); //expiry 1 hour
        Vue.ls.get('foo');
        Vue.ls.get('boo', 10); //if not set boo returned default 10
        
        Vue.ls.remove('foo');
    }
});
```

Vue3.x
``` js
import { Storage } from 'ynos-storage';
import { getCurrentInstance, ComponentInternalInstance } from 'vue'

const options = {
  namespace: 'ynosjs__', // key prefix
  name: 'ls', // name variable
  storage: 'local', // storage name session, local, memory
};

app.use(Storage, options)

const { proxy } = getCurrentInstance() as ComponentInternalInstance

proxy?.ls.set('foo', 'boo');
//Set expire for item
proxy?.ls.set('foo', 'boo', 60 * 60 * 1000); //expiry 1 hour
proxy?.ls.get('foo');
proxy?.ls.get('boo', 10); //if not set boo returned default 10
proxy?.ls.remove('foo');
```

Use in js file
``` js
// localStore.js
import { Storage }  from 'ynos-storage';
const options = {
  namespace: 'vuejs__', // key prefix
  name: 'ls', // name variable Vue.[ls] or this.[$ls],
  storage: 'local', // storage name session, local, memory
};

const { ls } = Storage.useStorage(options)

export default ls

// somefile.js
import ls from 'localStore.js';

ls.set('foo', 'boo');
ls.get('foo');
```

#### Global

- `Vue.ls`
 
#### Context
- `this.$ls` | `proxy?.ls`

## API

#### `Vue.ls.get(name, def)`

返回存储中`name`下的值。在返回之前从JSON内部解析值。

- `def`: default null, 如果未设置`name` 则返回默认值

#### `Vue.ls.set(name, value, expire)`

在存储器中的`name`下持久化`value`。在内部将`value`转换为JSON。

- `expire`: default null, 为存储添加过期时间

#### `Vue.ls.remove(name)`

从存储器中删除`name`。如果成功删除属性，则返回`true`，否则返回`false`。

#### `Vue.ls.clear()`

清除存储。


## 使用加密后的 SessionStorage


## 使用

Vue2.x

``` js
import { sessionStorage } from 'ynos-storage';


Vue.use(sessionStorage);

new Vue({
    el: '#app',
    mounted: function() {
        Vue.ss.set('foo', 'boo');
        Vue.ss.get('foo');
        Vue.ss.get('boo', 10); //if not set boo returned default 10
        
        Vue.ss.remove('foo');
    }
});
```

Vue3.x
``` js
import { sessionStorage } from 'ynos-storage';
import { getCurrentInstance, ComponentInternalInstance } from 'vue'

app.use(sessionStorage)

const { proxy } = getCurrentInstance() as ComponentInternalInstance

proxy?.ss.set('foo', 'boo');
proxy?.ss.get('foo');
proxy?.ss.get('boo', 10); //if not set boo returned default 10
proxy?.ss.remove('foo');
```
Use in js file
``` js
// sesionStore.js
import { sessionStorage }  from 'ynos-storage';

const ss = sessionStorage.useStorage()

export default ss

// somefile.js
import ss from 'sesionStore.js';

ss.set('foo', 'boo');
ss.get('foo');
```

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