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

storage-h

v1.0.12

Published

javascript storage

Downloads

5

Readme

Localstore模块化管理器

一、功能介绍

日常开发中,我们本地中的localstore非常难以管理,维护,很多时候不知道项目中存储了哪些内容。或者是说命名规范、多项目协同命名空间问题,因此,此库主要解决了如下几点:
  • [x] 模块化管理方式,根据业务来进行建立模块,如果为微前端应用则可以根据应用来建模块;
  • [x] 命名空间,每个模块有独立的命名空间,不存在命名冲突问题;
  • [x] 配置中需要配置模块下所使用的键,也就是defineProps,目的是为了更直观的看当前模块使用了哪些字段的缓存;
  • [x] store中key风格统一,不管是你传递了大驼峰、小驼峰、烤串,都会统一转换成下划线,同时拼接命名空间,也就是如:"user_xxxx_xxx";

二、如何使用

1、安装依赖

// npm
npm install storage-h -S;
// yarn
yarn add storeage-h -S

2、在项目中新建一个管理/定义store中文件;

// use-storage.ts
import { createStorage } from "storage-h"; // 引入存储库

// 创建一个系统store
const systemStore = createStorage({
    // store唯一id
    id: "system",

    // localstore存储前缀
    prefix: "system",

    // 所使用的字段,如果不传递则不限制
    defineProps: ["userName", "userId", "nickName", "token"]
});

// 菜单store
const menuStore = createStorage({
    // store唯一id
    id: "menu",

    // localstore存储前缀
    prefix: "menu",

    // 所使用的字段,如果不传递则不限制
    defineProps: ["menuList"]
});

// 建议按需导出,不使用默认更方便管理
export { systemStore, menuStore };

3、业务中使用

import { systemStore, menuStore } from "./lib/use-storage.ts";

/**
 * 每个模块的常用方法
 * 取值
 * get(key) 获取单个值
 * get(key1, key2, ...key) 获取多个值,返回一个object
 * getOnce(key) 获取值,获取了后会自动删除
 * 
 * 设置值
 * set(key, value) 设置单个值
 * set({key: value}) 设置多个值
 * set(key, value, time) 设置超时时间
 * 
 * 删除值
 * delete(key) 单个删除
 * delete(key1, key2, ...key) 多个删除
 * 
 * 设置过期时间
 * setExpire(key, expire) 设置过期时间
 * getKeys() 获取当前存储中的所有键, 并非定义数量
 * getSize() 获取当前模块中存储的数量,并非定义数量
 */

// 设置用户名
systemStore.set("userName", "John");

// 设置其他未定义的
systemStore.set("userSex", "John"); // 直接会错误警告

// 批量设置
systemStore.set({
    userName: "zhangsan",
    nickName: "就是张三",
    userId: "123456"
});

// 批量删除
systemStore.delete("userName", "nickName", "userId");

三、API 说明

| 方法 | 参数 | 参数说明 | | --------- | ------------------------------------------------------------ | -------- | | get | get(...keys: string[]): Object | any 单个返回值,多个则返回对象 | | | set | set( key: string | object, value?: any, expireTime?: number,): { [key: string]: IContent } | | | delete | delete(...keys: string[]): Storage | | | setExpire | setExpire(key: string, expireTime?: number): object | number | null | | | getKeys | getKeys(): string[] | | | getSize | getSize(): number | |