
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
storage-web
Advanced tools
对 web 端的 storage 操作,自动解析数据类型,支持 storage 过期时间设置,支持 Vue.js
| 设置参数类型 | localStorage.getItem 获取到的类型 | storage-web 获取到的类型 |
|---|---|---|
| 无 | 😃 Null | 😃 Null |
| Number | 😰 String | 😃 Number |
| String | 😃 String | 😃 String |
| Object | 😰 String | 😃 Object |
| Array | 😰 String | 😃 Array |
| Boolean | 😰 String | 😃 Boolean |
| Undefined | 😰 String | 🤩 Null |
| Null | 😰 String | 😃 Null |
yarn add storage-web
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| use | 使用的 storage 类型 | String | l/local/localStorage/s/session/sessionStorage | local |
| pre | 前缀 | String | - | - |
| expire | 过期时间,从当前开始 | Number | - | - |
import Storages from 'storage-web'
Storages.set('store', {}, {
use: 'session',
pre: 'pre_',
expire: 24 * 60 * 60 * 1000
})
// 或
Storages.set('store', {}, {
use: 'session'
})
import Storages from 'storage-web'
// 挂载到原型链上
Vue.prototype.$storage = Storages
// Vue 中设置默认参数
this.$storage.defaults['use'] = 'local'
this.$storage.defaults['pre'] = 'pre_'
this.$storage.defaults['expire'] = 24 * 60 * 60 * 1000
// 用 this.$storage 代替 Storages 即可,如:
this.$storage.get('store')
获取
import Storages from 'storage-web'
Storages.get('store') // localStorage
Storages.get('store', { // sessionStorage
use: 's'
})
Storages.get('store', { // sessionStorage
use: 'session'
})
Storages.get('store', { // sessionStorage
use: 'sessionStorage'
})
Storages.get('store', { // sessionStorage name: pre_store
use: 's',
pre: 'pre_'
})
Storages.getOnce('store') // 获取即销毁
设置
import Storages from 'storage-web'
// 支持类型 String,Number,Boolean,Array,Object,Null,Undefined...
let storeValue = {
store_id: 1,
store_name: 'Tmall'
}
Storages.set('store', storeValue, {
use: 's',
pre: 'pre_',
expire: 24 * 60 * 60 * 1000
})
Storages.set([
{
key: 'store',
value: storeValue
}
], {
use: 's',
pre: 'pre_',
expire: 24 * 60 * 60 * 1000
})
移除
import Storages from 'storage-web'
Storages.remove('store')
Storages.remove(['store', 'token'])
清空
import Storages from 'storage-web'
Storages.clear({ // 清空 localStorage 和 sessionStorage 下所有以 'pre_' 开头的
pre: 'pre_'
})
Storages.clear() // 清空所有 localStorage 和 sessionStorage
FAQs
浏览器端的 storage 操作
The npm package storage-web receives a total of 25 weekly downloads. As such, storage-web popularity was classified as not popular.
We found that storage-web demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.