npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

storage-web

v4.0.0-alpha.5

Published

浏览器端的 storage 操作

Downloads

54

Readme

storage-web

Build Status JS gzip size npm package

对 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'
})

在vue中使用

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')

get

获取

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') // 获取即销毁

set

设置

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
})

remove

移除

import Storages from 'storage-web'

Storages.remove('store')

Storages.remove(['store', 'token'])

clear

清空

import Storages from 'storage-web'

Storages.clear({ // 清空 localStorage 和 sessionStorage 下所有以 'pre_' 开头的
  pre: 'pre_'
})

Storages.clear() // 清空所有 localStorage 和 sessionStorage