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

cloudflare-tools-shared

v0.2.2

Published

cloudflare-tools-shared

Readme

📦 安装

# npm
npm install cloudflare-tools-shared

# yarn
yarn add cloudflare-tools-shared

# pnpm
pnpm add cloudflare-tools-shared

🚀 功能特性

🔍 编码转换

Base64 编码/解码

import { base64Decode, base64Encode, tryBase64Decode, tryBase64Encode } from 'cloudflare-tools-shared';

// 基本使用
const encoded = base64Encode('Hello World');
const decoded = base64Decode(encoded);

// 安全使用(带错误处理)
const safeEncoded = tryBase64Encode('Hello World');
const safeDecoded = tryBase64Decode(encoded, s => `解码失败: ${s}`);

十六进制编码/解码

import { hexDecode, hexEncode, tryHexDecode, tryHexEncode } from 'cloudflare-tools-shared';

// 基本使用
const encoded = hexEncode('Hello');
const decoded = hexDecode(encoded);

// 安全使用
const safeEncoded = tryHexEncode('Hello');
const safeDecoded = tryHexDecode(encoded);

URL 编码/解码

import { tryUrlDecode, tryUrlEncode } from 'cloudflare-tools-shared';

// 安全的 URL 编码/解码
const encoded = tryUrlEncode('Hello World');
const decoded = tryUrlDecode(encoded);

🔍 IP 验证

import { IpValidator, validateIp } from 'cloudflare-tools-shared';

// 函数式用法
validateIp('192.168.1.1', ['192.168.*.*']); // true
validateIp(request, ['10.0.0.*']); // 支持 Request 对象

// 类式用法(适合频繁验证)
const validator = new IpValidator(['192.168.*.*']);
validator.validate('192.168.1.1'); // true

📨 Telegram 通知

import { notifyTelegram } from 'cloudflare-tools-shared';

// 发送单条消息
await notifyTelegram({
    token: 'YOUR_BOT_TOKEN',
    chatId: 'CHAT_ID',
    message: 'Hello from Worker!'
});

// 发送多条消息
await notifyTelegram({
    token: 'YOUR_BOT_TOKEN',
    chatId: 'CHAT_ID',
    message: ['Line 1', 'Line 2', 'Line 3']
});

📚 API 文档

编码转换

Base64

function base64Encode(s: string): string;
function base64Decode(s: string): string;
function tryBase64Encode<C>(s: string, onCatch?: (s: string) => string | C): string | C;
function tryBase64Decode<C>(s: string, onCatch?: (s: string) => string | C): string | C;

Hex (十六进制)

function hexEncode(s: string): string;
function hexDecode(s: string): string;
function tryHexEncode(s: string): string;
function tryHexDecode(s: string): string;

URL

function tryUrlEncode<C>(s: string, onCatch?: (s: string) => string | C): string | C;
function tryUrlDecode<C>(s: string, onCatch?: (s: string) => string | C): string | C;

IP 验证

function validateIp(input: string | Request, match: string[] | null = ['*']): boolean;

class IpValidator {
    constructor(rules: string[] = ['*']);
    validate(input: string | Request): boolean;
    updateRules(rules: string[]): void;
}

Telegram 通知

interface SendMessageString {
    token?: string;
    chatId?: string;
    message?: string;
}

interface SendMessageArray {
    token?: string;
    chatId?: string;
    message?: string[];
}

function notifyTelegram(options: SendMessageString | SendMessageArray): Promise<Response>;

🌐 浏览器兼容性

  • 支持所有现代浏览器
  • 支持 Cloudflare Workers 环境
  • 需要 ES2015+ 支持

📄 许可证

MIT

🤝 贡献

欢迎提交 issue 和 PR!