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

better-command

v1.0.1

Published

一个轻量化的类型友好的命令行解析工具,适用于Bun运行时

Downloads

2

Readme

better-command

一个轻量化的类型友好的命令行解析工具,适用于Bun运行时。提供完整的 TypeScript 类型支持和灵活的命令行参数处理能力。

license

特性

  • 🎯 完整的 TypeScript 类型支持
  • 🚀 轻量级设计,零依赖
  • 💪 支持命令嵌套
  • 🎨 灵活的参数解析
  • 📦 支持位置参数和命名参数
  • 🔧 内置帮助命令生成

安装

传统Nodejs

bun add better-command
# 或
npm install better-command
# 或
yarn add better-command
# 或
pnpm add better-command

快速开始

// index.ts
import { defineCommandParser, arg, ArgType } from 'better-command';
import { helpCommand } from 'better-command/plugin';

const { parse } = defineCommandParser(
  {
    name: 'mycli',
    commands: [helpCommand],
  },
  arg('name', { type: ArgType.String, required: true }),
  arg(['port', 'p'], { type: ArgType.Number }),
  arg(['debug', 'd'], { type: ArgType.Boolean })
);

parse.parse(process.argv.splice(2), (args) => {
  console.log('Name:', args.name); // args.name is string
  console.log('Port:', args.port); // args.port is number|undefined
  console.log('Debug:', args.debug); // args.debug is boolean|undefined
});
bun run index.ts test 3000
# Name: test
# Port: 3000
# Debug: undefined

bun run index.ts --name test --port 3000 --debug true
# Name: test
# Port: 3000
# Debug: true

bun run index.ts help
# help info...

自定义命令

import { defineCommandParser, arg, ArgType, command } from 'better-command';

const test2Parser = defineCommandParser(
  {
    name: 'test2',
  },
  arg('name', { type: ArgType.String, required: true }),
  arg(['port', 'p'], { type: ArgType.Number }),
  arg(['debug', 'd'], { type: ArgType.Boolean })
);

const { parse } = defineCommandParser(
  {
    name: 'mycli',
    commands: [
      command({
        name: 'test',
        action: (e) => {
          console.log('test command');
        },
      }),
      command(test2Parser, (args) => {
        console.log('test2 command', args);
      }),
    ],
  }
);

parse.parse(process.argv.splice(2));
bun run index.ts test
# test command

bun run index.ts test2 test 3000
# test2 command { name: 'test', port: 3000, debug: undefined }

扩充类型

有些时候可能需要对命令传入的对象进行扩充,但是传入新属性在命令中类型会丢失,此时则可以使用ts的接口扩充。

import { defineCommandParser, arg, ArgType, command } from 'better-command';

declare module 'better-command' {
  interface Argument { // 对应的是arg方法
    description?: string;
  }

  interface Command { // 对应的是command方法
    description?: string;
  }

  interface CommandParserOpts { // 对应的是defineCommandParser方法,注意:CommandParserOpts本身继承了Command
    examples?: string[];
    version?: string;
  }
}

const { parse } = defineCommandParser({
  name: 'mycli',
  description: 'mycli description',
  examples: ['mycli test', 'mycli test2'],
  version: '1.0.0',
  commands: [
    command({
      name: 'version',
      alias: ['-v', '--version'],
      description: '查看程序版本',
      action: (e) => {
        console.log(e.opts.version); // e.opts is string|undefined
        // log: 1.0.0
      },
    }),
  ],
})
// ...

其它

  1. 这个包我最初是给bun使用的,nodejs用户版本可能需要稍微高一些(我也不确定)
  2. 不咋会写文档,有问题欢迎PR
  3. 如果可以的话,请给仓库点个Star,感谢!!!

License

MIT License