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

miniprogram-cookie-shim

v1.0.1

Published

A document.cookie-like cookie shim for mini programs. Plugin for miniprogram-xmlhttprequest-shim.

Readme

miniprogram-cookie-shim

miniprogram-xmlhttprequest-shim 的 Cookie 插件,像 document.cookie 一样读写,可单独使用。

English

安装

npm install miniprogram-cookie-shim

快速开始

import { Cookie, setBaseURL, wrap } from "miniprogram-cookie-shim";

setBaseURL("https://api.example.com"); // 设置基准 URL,用于 Cookie 的域匹配

// 读写 Cookie —— 与 document.cookie 的 getter/setter 语义一致
Cookie.set("token=abc123; Max-Age=3600; Path=/");
console.log(Cookie.get()); // "token=abc123"

// request 仅作示例,实际请用对应平台的方法
// 例如微信小程序用 wx.request,支付宝小程序用 my.request 等
// wrap() 会在请求时自动携带 Cookie,响应时自动解析 Set-Cookie 并存储
request(wrap({
    url: "https://api.example.com/user",
    withCredentials: true, // 跨域请求需要开启
    success(res) {
        console.log(res.data);
    },
}));

API

Cookie

Cookie.get()Cookie.set() 在小程序与浏览器中都能正常工作:

  • 在小程序中:通过内置 Cookie 存储模拟浏览器行为。
  • 在浏览器中:直接读写 document.cookie,与原生行为一致。

| 方法 | 说明 | | -------------------------- | ------------------------------------------------------------------- | | Cookie.get() | 返回当前域名可用的所有 Cookie(格式:name=value; ...) | | Cookie.set(cookieString) | 写入一个 Cookie,支持 Max-AgeExpiresPathDomain 等属性 |

setBaseURL(url)

设置全局基准 URL,用于 Cookie 的域匹配和路径匹配,可多次调用。

| 参数 | 类型 | 说明 | | ----- | -------- | ----------------- | | url | string | 有效的 URL 字符串 |

createAccessor(baseURL?)

创建 Cookie 访问器。适用于需要在 wx.requestmy.request 等网络请求中手动管理 Cookie 的场景。

| 参数 | 类型 | 说明 | | --------- | --------- | ---------------------------------------- | | baseURL | string? | 可选,同时调用 setBaseURL 设置基准 URL |

返回对象:

| 方法 | 签名 | 说明 | | ----- | -------------------------------------------------------------------------------- | --------------------------------- | | get | (url: string, withCredentials?: boolean) => string | 根据 URL 返回匹配的 Cookie 字符串 | | set | (url: string, withCredentials?: boolean, cookies?: string \| string[]) => void | 根据 URL 将响应的 Cookie 写入存储 |

withCredentialstrue 时,允许跨域请求携带 Cookie;同源请求不受此参数影响。

开源协议

MIT License

Copyright (c) 2026

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.