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

fast-storage-js

v1.0.0

Published

一个简单易用的js的localstorage响应式操作库

Readme

fastStorage-js 使用说明

概述

Storage 是一个基于 localStorage 的增强型存储类,提供了更友好的 API 和类型安全的数据存储功能。它使用命名空间隔离不同实例的数据,并自动处理数据类型转换。

版权声明

MIT License 2025 © 王小玗

安装与初始化

// 在浏览器环境中自动注册
// 已经通过 window.Storage = Storage 注册到全局

// 创建实例
const myStorage = new Storage('myApp');

基本用法

存储数据

myStorage.key1 = 'value'; // 字符串
myStorage.numberValue = 42; // 数字
myStorage.boolValue = true; // 布尔值
myStorage.objValue = {a: 1}; // 对象
myStorage.nullValue = null; // null

读取数据

console.log(myStorage.key1); // 'value'
console.log(myStorage.numberValue); // 42 (数字类型)
console.log(myStorage.objValue); // {a: 1} (对象)

检查键是否存在

if ('key1' in myStorage) {
  console.log('key1 exists');
}

删除数据

delete myStorage.key1; // 删除key1
myStorage.remove('key1'); // 等效方法

清空所有数据

myStorage.clear(); // 只清除当前命名空间下的数据

高级功能

获取所有键名

const keys = myStorage.keys();
console.log(keys); // ['numberValue', 'boolValue', 'objValue', ...]

获取存储项数量

console.log(myStorage.length); // 当前命名空间下的项数

迭代存储项

// 使用for...of迭代
for (const [key, value] of myStorage) {
  console.log(key, value);
}

// 或使用Object.keys等
Object.keys(myStorage).forEach(key => {
  console.log(key, myStorage[key]);
});

注意事项

  1. 所有数据都存储在localStorage中,有大小限制(通常5MB)
  2. 数据会持久化,直到手动删除或用户清除浏览器数据
  3. 不同实例使用不同命名空间,互不干扰
  4. 存储对象时会进行JSON序列化,函数和特殊对象属性会丢失
  5. 在隐私模式下,localStorage可能不可用或会在会话结束后清除

方法参考

  • get(key): 获取指定键的值
  • set(key, value): 设置键值对
  • _has(key): 检查键是否存在(内部方法)
  • remove(key): 删除指定键
  • clear(): 清空当前命名空间所有数据
  • keys(): 返回所有键名数组
  • _getLength(): 获取项数(内部方法)
  • _invalidateCache(): 清除缓存(内部方法)

许可证

MIT License - 自由使用、修改和分发,但需保留版权声明。