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

tg-auth

v1.0.1

Published

Telegram Auth

Readme

tg-auth

Telegram 登录授权 Vue 组件(H5 + uni-app App)。

安装

npm install tg-auth

将静态授权页拷贝到宿主项目(须部署在 tgAuthDomain 对应站点,路径与 authBasePath 一致):

npx tg-auth-copy-static --target src/static/html

Telegram Bot 后台需登记授权页的 origin。

组件用法

点击区域由组件内部处理;默认 slot 仅用于展示(图标、文字等)。

<script setup>
import { TgAuth } from 'tg-auth';

const tgAuthDomain = 'https://h5.example.com';
const botId = '123456789';

function onAuth(user) {
  // H5:Telegram 用户对象(含 id、first_name、hash 等)
  console.log(user);
}
</script>

<template>
  <TgAuth
    :tg-auth-domain="tgAuthDomain"
    :bot-id="botId"
    @authorized="onAuth"
  >
    <span>TG 登录</span>
  </TgAuth>
</template>

Props

| 属性 | 说明 | 默认 | |------|------|------| | tg-auth-domain | 静态授权页所在站点域名 | '' | | bot-id | Telegram Bot ID | '' | | auth-base-path | 静态页部署路径 | /static/html | | iframe-breakpoint | 视口宽度 ≥ 该值时使用 iframe(px) | 580 | | app-auth-options | App 模式传给 tgauth-app.html 的参数 | {} |

事件

| 事件 | 说明 | |------|------| | authorized | 仅 H5:授权成功,参数为 Telegram 用户对象 |

uni-app App

App 端(window === undefined)点击后会通过 plus.runtime.openURL 打开系统浏览器中的 tgauth-app.html,授权成功后以深链返回 App,不会触发 authorized,需在 App 入口自行解析 URL 参数 arg

app-auth-options 示例(urlScheme 必填):

<TgAuth
  :tg-auth-domain="tgAuthDomain"
  :bot-id="botId"
  :app-auth-options="{
    page: 'login',
    lang: 'zh',
    urlScheme: 'myapp://',
  }"
>
  <span>TG 登录</span>
</TgAuth>

深链格式:{urlScheme}{page}?arg={encodeURIComponent(JSON.stringify(user))}

本地示例

仓库内附带可运行的 H5 演示(example/):

npm run dev:example

(首次或更新 static/ 后也可手动执行 npm run copy-static:example。)

浏览器用终端输出的 Network 地址(如 http://192.168.1.100:5173)打开,在 BotFather /setdomain 登记同一 host 后测试登录。详见 example/README.md

工具函数

import {
  TgAuth,
  TG_AUTH_RESULT_REGEX,
  parseTgAuthResult,
} from 'tg-auth';

// parseTgAuthResult('eyJpZCI6MTIz...') => { id: 123, ... }

发布

发布前会自动执行 npm run buildprepublishOnly)。