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

xk-storage

v0.0.3

Published

```sh npm i xk-storage ```

Readme

Basic Using

npm i xk-storage 
import { HStorage } from "xk-storage";

/** 创建 storage 存储实例 */
const storage = new HStorage({
    namespace: '',
    encrypt: true,
})

storage.set('token', "TEST_TOKEN")
storage.set('token', "TEST_TOKEN", 1000 * 60 * 60) // -- 可通过传入第三个参数,设置过期时间(单位/毫秒)
storage.get('token', "TEST_TOKEN")

实例配置对象

interface StorageOptions {
    /* 命名空间: 本地存储时会自动给存储的 key 添加上前缀(对存储数据进行操作时不需要给 key 加上这个前缀,内部会自动解析) */
    namespace?: string
    /* 是否加密: 默认 false 不加密(加密使用的时非对称加密,内部有默认的 '私钥' 与 '公钥',也可以配置自定义的公钥与私钥) */
    encrypt?: boolean
    /* 加密公钥 */
    publicKey?: string
    /* 加密私钥 */
    privateKey?: string
}

方法示例

/* 设置 */
storage.set(key, value, ttl) // -- ttl: 有效时间(单位/毫秒)

/* 获取 */
storage.get(key)

/* 移除 */
storage.remove(key)

/* 清空所有存储 */
storage.clear(key)

/* 清空当前命名空间所有存储 */
storage.clearNamespace(key)

与 Pinia 持久化插件 pinia-plugin-persistedstate 一起使用

如果项目中有集成了持久化插件,可以通过配置持久化插件 "自定义存储器" 与 "自定义系列化" 的方式,来统一项目中使用的存储器

import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate'

// -- 持久化插件配置
const persistedStatePlugin = createPersistedState({
    /* 使用自定义 storage 存储器 */
    storage: {
        getItem: storage.get.bind(storage) /* 通过 bind 绑定当前存储器,避免 this 指向丢失 */,
        setItem: storage.set.bind(storage),
    },

    /* 自定义持久化插件序列化操作(取消该插件的自动序列化)→ 因为与所封装的 HStorage 工具的序列化有冲突,所以禁用该默认的序列化功能 */
    serializer: {
        serialize: (value) => value as any,
        deserialize: (value) => value as any,
    },
})

// -- 基本的 pinia 配置(可忽略)
const pinia = createPinia().use(persistedStatePlugin)
export default  pinia