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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@a-drowned-fish/storage

v1.0.4

Published

一个用于处理存储的工具库,支持过期时间。仅支持LocalStorage。

Readme

@a-drowned-fish/storage

一个轻量级的本地存储工具库,支持过期时间自动清理功能。

安装

npm install @a-drowned-fish/storage

快速开始

基本使用

import { storage, singleTonStorage } from "@a-drowned-fish/storage";

// 使用普通实例
storage.setExpireTime(3600); // 设置过期时间为 1 小时
storage.setItem("token", "abc123");
const token = storage.getItem("token");

// 使用单例实例
singleTonStorage.setExpireTime(3600);
singleTonStorage.setItem("user", "test");

链式调用

import { storage } from "@a-drowned-fish/storage";

// setExpireTime 方法支持链式调用
storage.setExpireTime(3600).setItem("key", "value");

API 文档

StorageWithExpire 类

提供带有过期时间的本地存储功能,支持自动清理过期数据。

构造函数

new StorageWithExpire();

方法

setExpireTime(expired?: number): StorageWithExpire

设置过期时间,单位为秒。支持链式调用。

参数:

  • expired - 过期时间(单位:秒),默认 0 表示永不过期

返回值:

  • 返回当前实例,支持链式调用
getItem(key: string): any | null

获取存储的值,如果已过期则返回 null 并自动删除。

参数:

  • key - 存储键名
setItem(key: string, value: string): void

存储值到本地存储。

参数:

  • key - 存储键名
  • value - 存储值
removeItem(key: string): void

删除指定键名的存储。

参数:

  • key - 存储键名

singleTonStorage

StorageWithExpire 的单例实例,全局共享同一个实例。

特点:

  • 无论在多少个文件中导入,始终是同一个实例
  • 使用单例模式保证全局唯一性
import { singleTonStorage } from "@a-drowned-fish/storage";

// 设置过期时间为 1 小时
singleTonStorage.setExpireTime(3600);

// 存储数据
singleTonStorage.setItem("token", "abc123");

// 获取数据
const token = singleTonStorage.getItem("token");

// 删除数据
singleTonStorage.removeItem("token");

storage

StorageWithExpire 的普通实例,由于 ES Module 的模块缓存机制,在不同文件中导入时也是同一个实例。

注意:

  • 虽然是普通实例,但由于模块缓存,多次导入仍然共享同一个实例
  • 如果需要完全独立的实例,请使用 new StorageWithExpire()
import { storage } from "@a-drowned-fish/storage";

// 使用方式与 singleTonStorage 相同
storage.setExpireTime(3600);
storage.setItem("key", "value");
const value = storage.getItem("key");

实例隔离:

如果需要创建完全独立的实例(互不影响),可以直接使用 StorageWithExpire 类:

import { StorageWithExpire } from "@a-drowned-fish/storage";

// 创建独立实例
const myStorage = new StorageWithExpire();
myStorage.setExpireTime(3600);
myStorage.setItem("key", "value");

导出说明

import { StorageWithExpire, singleTonStorage, storage } from "@a-drowned-fish/storage";

// 或使用默认导出
import storageModule from "@a-drowned-fish/storage";
// storageModule.singleTonStorage
// storageModule.storage
// storageModule.StorageWithExpire

特性

  • 🎯 支持过期时间自动清理
  • 🔗 支持链式调用
  • 📦 轻量级,无依赖
  • 🚀 支持 ES Module 和 CommonJS
  • 🔒 类型安全,支持 TypeScript

许可证

MIT License

作者

a-drowned-fish