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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sweet-storage

v1.0.5

Published

给localStorage整合过期时间,更便捷的用于前端存储

Downloads

24

Readme

sweet-storage

localStorage 整合了过期时间的功能

localStorage 是浏览器提供给我们的原生api, 目前 localStorage 只能实现永久存储。 本工具给localStorage整合了设置过期时间的功能, 并让用户可以在存储信息过期的时候去“订阅”到此信息。 此外,本工具也整合了 sessionStorage 的存储操作

如何使用

npm 下载

$ npm install sweet-storage
import storage from 'sweet-storage'
storage.save('name', 'storage', 3000)
storage.on('name', key => {
  console.warn(`${key} deleted`)
})

直接引入

<script src='./storage/release/storage.js'></script>
storage.save('name', 'storage', 3000)
storage.on('name', (key)=>{
  console.warn(`${key} deleted`)
})

API

localStorage

get

根据key获取localStorage中的信息

storage.get(key)
  • key: 保存的时候设置的key

save

存储到localStorage中

storage.save(key, value, time)
  • key: 存储的键
  • value: 存储的值
  • time: 过期时间(ms), 不传代表永久存储, time不允许设为0

remove

删除localStorage中指定键

storage.remove(key)
  • key: 需要被删除的键

clear

清空localStorage

storage.clear()

on

订阅某一个键的到期信息

storage.on(key, fn)
  • key: 被订阅的键
  • fn: 回调函数(key => {})

off

取消订阅某一个键的到期信息

storage.off(key, fn)
storage.off(key, true)  // 传入true取消所有订阅此键的函数
  • key: 被订阅的键
  • fn: 取消的函数

sessionStorage

get

根据key获取sessionStorage中的信息

storage.session.get(key)
  • key: 保存的时候设置的key

save

存储

storage.session.save(key, value)
  • key: 存储的键
  • value: 存储的值

remove

移除

storage.session.remove(key)
  • key: 需要被删除的键

clear

清空sessionStorage

storage.session.clear()