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

@kne/token-storage

v1.0.0

Published

用于存储和获取浏览器客户端token

Downloads

77

Readme

token-storage

描述

用于存储和获取浏览器客户端token

安装

npm i --save @kne/token-storage

概述

该模块提供了简单的Token存储管理功能,支持两种存储方式:

  1. 同域存储(使用localStorage)
  2. 跨域存储(使用Cookies)

主要功能包括设置Token、获取Token和移除Token操作,适用于前端身份认证场景。

示例

示例样式

.ant-card {
  border-color: black;
  text-align: center;
  width: 200px;
}

示例代码

  • 这里填写示例标题
  • 这里填写示例说明
  • _TokenStorage(@kne/current-lib_token-storage)[import * as _TokenStorage from "@kne/token-storage"],antd(antd)
const { default: tokenStorage } = _TokenStorage;
const { Flex, Button, App } = antd;

const BaseExample = () => {
  const { message } = App.useApp();
  return (
    <Flex gap={12}>
      <Button
        onClick={() => {
          tokenStorage.setToken('X-User-Token', '1234567890');
        }}>
        设置token
      </Button>
      <Button
        onClick={() => {
          message.info('token: ' + tokenStorage.getToken());
        }}>
        获取token
      </Button>
      <Button
        onClick={() => {
          tokenStorage.removeToken();
        }}>
        移除token
      </Button>
    </Flex>
  );
};

render(<BaseExample />);

API

| 方法名 | 参数 | 返回值 | 描述 | |--------|------|--------|------| | setToken | (tokenValue: string, tokenKey?: string, options?: object) | void | 设置Token到存储系统 | | getToken | (tokenKey?: string, options?: object) | string \| null | 从存储系统获取Token | | removeToken | (tokenKey?: string, options?: object) | void | 从存储系统移除Token |

参数说明

公共参数

  • tokenKey: 可选,默认值 'X-User-Token',指定存储的键名
  • options: 可选配置对象,包含:
    • sameDomain: 布尔值,默认true,是否使用同域存储

注意事项

  1. sameDomaintrue时使用localStorage API,为false时使用Cookies
  2. 默认存储键名为'X-User-Token',可通过参数自定义
  3. 所有方法都支持可选参数,提供灵活的调用方式