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

clash-switcher

v0.0.4

Published

CLI tool and library for switching Clash Verge proxies and subscriptions

Readme

clash-switcher

Clash Verge 代理切换工具,提供 API 库和命令行工具。

前置要求

使用本工具前,需要在 Clash Verge 软件中开启外部控制:

  1. 打开 Clash Verge 设置
  2. 找到「外部控制」选项并开启
  3. 记录端口号(默认 9097)和密钥(如有设置)

安装

npm install clash-switcher

API 使用

初始化

import { ClashSwitcher } from 'clash-switcher';

const switcher = new ClashSwitcher({
  host: '127.0.0.1',    // 可选,默认 127.0.0.1
  port: 9097,           // 可选,默认 9097
  secret: '',           // 可选,API 密钥
  testUrl: 'http://www.gstatic.com/generate_204',  // 可选
  timeout: 5000,        // 可选,超时时间(ms)
});

配置管理

// 获取当前配置
const config = switcher.getConfig();

// 更新配置
switcher.setConfig({ port: 9090, timeout: 3000 });

模式管理

// 获取当前模式
const mode = await switcher.getMode();  // 'rule' | 'global' | 'direct'

// 设置模式
await switcher.setMode('rule');

代理组

// 获取所有代理组
const groups = await switcher.getGroups();

// 获取单个代理组
const group = await switcher.getGroup();              // 主代理组
const group = await switcher.getGroup(undefined, 0);  // 按索引
const group = await switcher.getGroup(undefined, '选择');  // 模糊匹配

节点操作

// 获取节点列表
const nodes = await switcher.getNodes();        // 主代理组的节点
const nodes = await switcher.getNodes(0);       // 按索引
const nodes = await switcher.getNodes('选择');  // 模糊匹配

// 切换节点
await switcher.setNode('香港');           // 主代理组
await switcher.setNode(0, '香港');        // 按索引指定组
await switcher.setNode('选择', '香港');   // 模糊匹配组名

延迟测试

// 测试单个节点
const result = await switcher.testNode('香港');
// { name: '🇭🇰 香港 01', delay: 120 }

// 测试代理组所有节点
const results = await switcher.testNodes();       // 主代理组
const results = await switcher.testNodes(0);      // 按索引
const results = await switcher.testNodes('选择'); // 模糊匹配

// 测试指定节点列表
const nodes = await switcher.getNodes();
const results = await switcher.testNodes(nodes.filter(n => n !== 'DIRECT'));

// 自动选择最快节点
const best = await switcher.autoNode();       // 主代理组
const best = await switcher.autoNode(0);      // 按索引
const best = await switcher.autoNode('选择'); // 模糊匹配

订阅管理

// 获取所有订阅
const subs = switcher.getSubs();

// 获取当前订阅
const current = switcher.getSub();

// 按索引或名称获取
const sub = switcher.getSub(0);
const sub = switcher.getSub('机场名');

// 切换订阅(默认重启)
await switcher.setSub(0);
await switcher.setSub('机场名');

// 切换但不重启
await switcher.setSub('机场名', false);

工具方法

// 等待 API 就绪
await switcher.waitReady();

// 重启 Clash Verge
await switcher.restartClashVerge();

命令行

全局安装后可使用 clash-switcher 命令。

模式

# 查看当前模式
clash-switcher mode

# 设置模式
clash-switcher mode rule
clash-switcher m global

代理组

# 列出所有代理组
clash-switcher groups
clash-switcher g

节点

# 列出节点(主代理组)
clash-switcher nodes
clash-switcher n

# 按索引或名称
clash-switcher n 0
clash-switcher n 选择

切换节点

# 切换节点(组 + 节点)
clash-switcher set 0 香港
clash-switcher s 选择 日本

测试延迟

# 测试主代理组
clash-switcher test
clash-switcher t

# 按索引或名称
clash-switcher t 0
clash-switcher t 选择

# 自定义测试参数
clash-switcher t -u http://example.com -t 3000

自动选择

# 自动选择最快节点
clash-switcher auto
clash-switcher a

# 指定代理组
clash-switcher a 0
clash-switcher a 选择

订阅

# 列出订阅
clash-switcher subs

# 切换订阅
clash-switcher sub 0
clash-switcher sub 机场名

# 切换但不重启
clash-switcher sub 机场名 --no-restart

配置

# 查看配置
clash-switcher config
clash-switcher c

# 设置配置
clash-switcher c host 192.168.1.100
clash-switcher c port 9090
clash-switcher c timeout 3000