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

@tsdanci/wx-share

v1.0.5

Published

WeChat Share SDK utility for web applications

Readme

@tsdanci/wx-share

一个用于微信分享的 TypeScript 工具包,提供了简单易用的 API 来配置微信分享功能。

安装

npm install @tsdanci/wx-share
# 或者
yarn add @tsdanci/wx-share
# 或者
pnpm add @tsdanci/wx-share

使用方法

基础用法

import { createWxShare } from "@tsdanci/wx-share";

// 创建分享实例
const wxShare = createWxShare();

// 设置分享配置
wxShare.setShareOptions({
  title: "分享标题",
  desc: "分享描述",
  link: "https://example.com",
  imgUrl: "https://example.com/image.jpg",
});

// 从API获取签名配置并初始化分享
await wxShare.fetchSignConfigAndShare({
  url: "/api/wx-share", // 可选,默认为 /api/v2/wx-share
});

高级用法

import { createWxShare } from "@tsdanci/wx-share";

const wxShare = createWxShare()
  .setDebug(true) // 开启调试模式
  .setShareOptions({
    title: "分享标题",
    desc: "分享描述",
    link: "https://example.com",
    imgUrl: "https://example.com/image.jpg",
    success: () => console.log("分享成功"),
    fail: (err) => console.error("分享失败:", err),
    cancel: () => console.log("取消分享"),
  });

// 使用自定义的签名配置获取方法
await wxShare
  .setCustomFetch(async (url) => {
    const response = await fetch(url, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ url: window.location.href }),
    });
    return response.json();
  })
  .fetchSignConfigAndShare();

API 文档

createWxShare()

创建微信分享实例。

setDebug(debug: boolean)

设置调试模式。

setShareOptions(options: ShareConfig)

设置分享配置。

fetchSignConfigAndShare(options?: SignConfigOptions)

从 API 获取签名配置并初始化分享。

setCustomFetch(customFetch: (url: string) => Promise)

设置自定义的签名配置获取方法。

类型定义

interface ShareConfig {
  title?: string;
  desc?: string;
  link?: string;
  imgUrl?: string;
  success?: () => void;
  fail?: (err: any) => void;
  cancel?: () => void;
}

interface SignConfig {
  appId: string;
  timestamp: string;
  nonceStr: string;
  signature: string;
}

interface SignConfigResponse {
  data: SignConfig;
}

interface SignConfigOptions {
  url?: string;
  customFetch?: (url: string) => Promise<SignConfigResponse>;
}

注意事项

  1. 使用前需要确保已经引入了微信 JS-SDK
  2. 需要在微信浏览器环境中使用
  3. 需要后端提供签名配置接口
  4. 建议在生产环境中关闭调试模式

License

MIT