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-expired-time-setting

v0.1.2

Published

setting expired time for localStorage

Downloads

13

Readme

storage-expired-time-setting

目的

解决localStorage中存储的值不能及时释放的问题,默认存储时间为7天(day),以当前时间为准。

用法

npm install storage-expired-time-setting
or
yarn add storage-expired-time-setting
import { localStore, sessionStore} from 'storage-expired-time-setting'
localStore.set('name','hyw','2022-1-10 09:28:00',(_this,value) => {})
localStore.get('name',(a,b) => {
   console.log(a,b)
})
localStore.clear()
localStore.deleteItem(name)

API

该npm库和web storage的api保持相对应,具体的对应规则是(前者是标准API):

  • setItem->set
  • getItem-> get
  • removeItem -> deleteItem
  • clear->clear

具体参数如下:

  • set( key, value, time,cb)设置key的失效时间,key:webstorage中对应的key。value:webstorage中对应的value。time表示失效时间,具体的格式为 2022-01-09 114:57:28,是一个标准的时间串,否则会使用new Date初始化一个当前时间。如果有其他的业务逻辑需要处理,可以在回调中进行,该回调可选
  • get(key, cb), 取值
  • deleteItem(key),删除某个key
  • clear,清除所有的值

localStorage过期时间设置,统一返回的结构,返回的状态如下:

  • SUCCESS(0): 表示操作正常
  • FAILURE(1): 如果set时有异常,会返回 QuotaExceededError;如果get时有异常也返回failure
  • EXPIRED(2): 在get key时,如果设置的值已经失效,则会返回
  • UNKNOWN(3): 如果手动修改storage中的数据结构,导致结果规则不匹配,则会返回。

返回的数据结构如下:

1、正常返回

{
  value: 222,
  status: 0
}

2、set失败或者获得的值数据结果已不准确

{
  value: 222,
  status: 1
}

3、超时返回

{
  value: null,
  status: 2
}

友情提醒

关于存储失效的问题只适用于localstorage, 该包提供的sessionStorage只是为了让两个web storage返回的数据结构保持一致,同时处理了数据异常的问题。

协议

MIT