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

@umworks/taro-use-storage

v0.1.0

Published

Taro 小程序存储管理插件

Readme

@umworks/taro-use-storage

一个用于 Taro 小程序的存储管理工具,提供便捷的缓存操作、过期控制和加密等功能。

特性

  • 支持数据前缀,方便区分不同模块
  • 支持数据过期时间设置
  • 提供简单的数据加密功能
  • TypeScript 支持,提供完整类型定义

安装

npm install @umworks/taro-use-storage --save
# 或使用 yarn
yarn add @umworks/taro-use-storage

使用方法

基础使用

import { useStorage } from '@umworks/taro-use-storage';

// 创建存储实例
const storage = useStorage();

// 设置数据
storage.set('user', { id: 1, name: '张三' });

// 获取数据
const user = storage.get('user');
console.log(user); // { id: 1, name: '张三' }

// 设置带过期时间的数据(1小时后过期)
storage.set('token', 'abc123', 60 * 60 * 1000);

// 删除数据
storage.remove('user');

// 清空所有数据
storage.clear();

配置选项

import { useStorage } from '@umworks/taro-use-storage';

// 使用自定义配置
const storage = useStorage({
  // 存储前缀
  prefix: 'my_app_',
  // 是否启用加密
  encrypt: true,
  // 加密密钥
  secretKey: 'my_secret_key'
});

// 使用自定义前缀存储数据
storage.set('settings', { theme: 'dark' });
// 实际存储的键为 "my_app_settings"

获取所有数据

import { useStorage } from '@umworks/taro-use-storage';

const storage = useStorage();

// 设置多个数据
storage.set('user', { name: '张三' });
storage.set('token', 'abc123');

// 获取所有数据
const allData = storage.getAll();
console.log(allData);
// 输出: { user: { name: '张三' }, token: 'abc123' }

API 文档

useStorage(options?)

创建一个存储实例。

参数:

  • options (可选): 配置选项对象
    • prefix: 存储键前缀,默认为 "taro_storage_"
    • encrypt: 是否启用加密,默认为 false
    • secretKey: 加密密钥,默认为 "taro_default_key"

返回: TaroStorage 实例

实例方法

set(key, value, expire?)

设置存储数据。

参数:

  • key: 存储键名
  • value: 存储的值,可以是任意类型
  • expire (可选): 过期时间,毫秒数,不设置则永久有效

get(key, defaultValue?)

获取存储数据。

参数:

  • key: 存储键名
  • defaultValue (可选): 默认值,当获取失败或已过期时返回

返回: 存储的值或默认值

remove(key)

移除存储数据。

参数:

  • key: 存储键名

clear()

清除所有带前缀的存储数据。

getAll()

获取所有存储的数据。

返回: 包含所有数据的对象

许可证

MIT