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

storage-utils-helper

v1.0.1

Published

A utility library for user cache management with encryption support

Readme

storage-utils-helper

一个用于用户缓存管理的工具库,支持加密存储。

功能特性

  • 🔐 加密存储:使用 AES 加密算法保护用户数据
  • 👤 用户缓存管理:便捷的用户信息缓存和获取
  • 📦 多格式支持:支持 CommonJS、ES Module 和 UMD 格式
  • 🌲 Tree-shaking:支持按需引入,减少打包体积

安装

npm install storage-utils-helper
# 或
yarn add storage-utils-helper

使用方法

ES Module

import { UserCache } from 'storage-utils-helper';
// 或
import UserCache from 'storage-utils-helper';

CommonJS

const { UserCache } = require('storage-utils-helper');
// 或
const UserCache = require('storage-utils-helper');

浏览器 (UMD)

<script src="https://unpkg.com/storage-utils-helper/dist/index.umd.js"></script>
<script>
  const { UserCache } = StorageUtilsHelper;
</script>

API 文档

UserCache

用户缓存管理类,用于管理登录用户信息。

UserCache.setUser(value)

缓存当前登录用户信息。

参数:

  • value (object): 用户信息对象

示例:

UserCache.setUser({
  id: 1,
  name: 'John',
  token: 'abc123',
  orgid: 'org001'
});

UserCache.getUser()

获取登录用户的信息。

返回值:

  • object|null: 用户信息对象,如果不存在则返回 null

示例:

const user = UserCache.getUser();
console.log(user.name); // 'John'

UserCache.clearUser()

清除用户本地信息。

示例:

UserCache.clearUser();

UserCache.getUserToken()

获取当前用户调用后台的 token。

返回值:

  • string|null: 用户 token

示例:

const token = UserCache.getUserToken();

UserCache.getUserOrgId()

获取当前用户调用后台的 orgid。

返回值:

  • string|null: 用户 orgid

示例:

const orgid = UserCache.getUserOrgId();

UserCache.getUserValue(keyName)

获取用户信息中的某部分信息。

参数:

  • keyName (string): 要获取的键名

返回值:

  • *: 对应的值

示例:

const userName = UserCache.getUserValue('name');

完整示例

import { UserCache } from 'storage-utils-helper';

// 存储用户信息
UserCache.setUser({
  id: 1,
  name: 'John Doe',
  email: '[email protected]',
  token: 'abc123xyz',
  orgid: 'org001'
});

// 获取用户信息
const user = UserCache.getUser();
console.log(user.name); // 'John Doe'

// 获取 token
const token = UserCache.getUserToken();
console.log(token); // 'abc123xyz'

// 获取 orgid
const orgid = UserCache.getUserOrgId();
console.log(orgid); // 'org001'

// 获取特定字段
const email = UserCache.getUserValue('email');
console.log(email); // '[email protected]'

// 清除用户信息
UserCache.clearUser();

在 Vue 项目中使用

// main.js 或组件中
import { UserCache } from 'storage-utils-helper';

// 在登录后存储用户信息
export default {
  methods: {
    async login(username, password) {
      const response = await this.$http.post('/api/login', {
        username,
        password
      });
      
      // 存储用户信息(自动加密)
      UserCache.setUser(response.data.user);
      
      return response.data;
    },
    
    logout() {
      // 清除用户信息
      UserCache.clearUser();
    },
    
    getUserInfo() {
      // 获取用户信息(自动解密)
      return UserCache.getUser();
    }
  }
}

在 React 项目中使用

import { UserCache } from 'storage-utils-helper';

function LoginComponent() {
  const handleLogin = async (credentials) => {
    const response = await fetch('/api/login', {
      method: 'POST',
      body: JSON.stringify(credentials)
    });
    
    const data = await response.json();
    
    // 存储用户信息
    UserCache.setUser(data.user);
  };
  
  const handleLogout = () => {
    UserCache.clearUser();
  };
  
  // 获取用户信息
  const user = UserCache.getUser();
  
  return (
    <div>
      {user ? (
        <div>
          <p>欢迎, {user.name}</p>
          <button onClick={handleLogout}>退出</button>
        </div>
      ) : (
        <LoginForm onLogin={handleLogin} />
      )}
    </div>
  );
}

浏览器支持

  • Chrome (最新版本)
  • Firefox (最新版本)
  • Safari (最新版本)
  • Edge (最新版本)
  • IE 11+ (需要 polyfill)

开发

# 安装依赖
npm install

# 开发模式(监听文件变化)
npm run dev

# 构建
npm run build

许可证

MIT

贡献

欢迎提交 Issue 和 Pull Request!

更新日志

1.0.0

  • 初始版本
  • 支持用户缓存管理
  • 支持加密存储