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

@qubit-ltd/storage

v1.4.4

Published

A JavaScript library providing wrapper objects for Web storages.

Readme

@qubit-ltd/storage

npm package License English Document CircleCI Coverage Status

@qubit-ltd/storage 是一个 JavaScript 库,为 Web 存储 API 提供包装对象,包括 cookies、localStorage 和 sessionStorage。该库通过自动使用 JSON 进行序列化和反序列化,使存储和检索任何 JavaScript 对象变得简单。

增强的 JSON 处理能力

与标准 JSON 序列化不同,本库使用了来自 @qubit-ltd/json 的自定义 JSON 序列化器/反序列化器,可以正确处理:

  • JavaScript BigInt 大整数
  • MapSet 对象
  • 来自 Java 后端系统的 64 位长整数
  • 其他标准 JSON 无法表示的复杂数据类型

这使得该库特别适合与 Java 后端服务交互的 Web 应用程序。

安装

NPM

npm install @qubit-ltd/storage

Yarn

yarn add @qubit-ltd/storage

使用示例

import { Cookie, LocalStorage, SessionStorage } from '@qubit-ltd/storage';

// 使用 Cookie
Cookie.set('user', { name: '张三', age: 30 });
const user = Cookie.get('user');  // { name: '张三', age: 30 }
Cookie.has('user');               // true
Cookie.remove('user');

// 使用 LocalStorage
LocalStorage.set('settings', { theme: 'dark', fontSize: 16 });
const settings = LocalStorage.get('settings');  // { theme: 'dark', fontSize: 16 }
LocalStorage.has('settings');                   // true
LocalStorage.remove('settings');

// 使用 SessionStorage
SessionStorage.set('cart', [{ id: 1, name: '商品1' }]);
const cart = SessionStorage.get('cart');  // [{ id: 1, name: '商品1' }]
SessionStorage.has('cart');               // true
SessionStorage.remove('cart');

API 文档

Cookie

  • Cookie.set(name, value, attributes): 设置指定名称和值的 cookie

    • name: cookie 的名称
    • value: 要存储的值(任何可以序列化为 JSON 的 JavaScript 值)
    • attributes: 可选的 cookie 属性,如 expires(过期时间)、path(路径)、domain(域名)、secure(安全)和 sameSite
  • Cookie.get(name): 获取指定名称的 cookie 值

    • 返回反序列化后的值,如果 cookie 不存在则返回 undefined
  • Cookie.remove(name, attributes): 删除指定名称的 cookie

    • attributes: 可选的 cookie 属性,必须与设置 cookie 时使用的属性匹配
  • Cookie.has(name): 检查指定名称的 cookie 是否存在

    • 如果 cookie 存在则返回 true,否则返回 false

LocalStorage

  • LocalStorage.set(name, value): 在 localStorage 中设置指定名称的值

    • name: 键名
    • value: 要存储的值(任何可以序列化为 JSON 的 JavaScript 值)
  • LocalStorage.get(name): 从 localStorage 中获取指定名称的值

    • 返回反序列化后的值,如果键不存在则返回 undefined
  • LocalStorage.remove(name): 从 localStorage 中删除指定名称的值

  • LocalStorage.has(name): 检查 localStorage 中是否存在指定的键

    • 如果键存在则返回 true,否则返回 false

SessionStorage

  • SessionStorage.set(name, value): 在 sessionStorage 中设置指定名称的值

    • name: 键名
    • value: 要存储的值(任何可以序列化为 JSON 的 JavaScript 值)
  • SessionStorage.get(name): 从 sessionStorage 中获取指定名称的值

    • 返回反序列化后的值,如果键不存在则返回 undefined
  • SessionStorage.remove(name): 从 sessionStorage 中删除指定名称的值

  • SessionStorage.has(name): 检查 sessionStorage 中是否存在指定的键

    • 如果键存在则返回 true,否则返回 false

贡献

如果您发现任何问题或有改进建议,请随时在 GitHub 仓库 中提出 issue 或提交 pull request。

许可证

@qubit-ltd/storage 在 Apache 2.0 许可下分发。 有关更多详细信息,请参阅 LICENSE 文件。