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

argv-router

v1.3.1

Published

简单的node.js命令行参数路由分发器

Downloads

5

Readme

Install

npm install argv-router

匹配表达式

匹配表达式分为单参数和组合参数两种,不可混合使用

单参数

单参数时直接指定参数名即可,使用简写、全称命名时用英文逗号分隔

const argvRouter = require('argv-router')

argvRouter({
   '-v, --version'(argv) {
      console.log(argv)
   },
   '-w, --watch, <>'(argv) {
      console.log(argv)
   }
})

组合参数

组合参数时,多个参数使用空格分隔

const argvRouter = require('argv-router')

argvRouter({
   '-a -w'(argv) {
      console.log(argv)
   },
})

自动扩展

在使用组合参数时可以搭配单参数实现自动扩展,使用单参数中的任意简写或全称命名。如以下示例中组合参数“-a -w”会尝试匹配“-a -w”、“-a --watch”、“--async -w”、“--async --watch”。

let options = {
   '-w, --watch'(argv) {

   },
   '-a, --async'(argv) {

   },
   '-a -w'(argv) {

   }
}

argvRouter(options)

参数值匹配

通过“<>”占位符号定义是否启用参数值

const argvRouter = require('argv-router')

argvRouter({
   '-a <> -w <>'(argv) {
      console.log(argv)
   },
})

快速赋值

通过“[$name]”定义是否启用无参数名的快捷赋值选项,在argv中返回一个以“$name”命名的匹配项数组

const argvRouter = require('argv-router')

argvRouter({
   '[files] -a <> -w <>'(argv) {
      console.log(argv.files)
   },
})

匹配优先级

首先按匹配参数数量进行升级,匹配参数越多优先级越高。在等量参数数量下,包含快速赋值的匹配项先级高于其它选项。

默认匹配

在参数为空时指定默认行为

let options = {
   '-w, --watch'(argv) {

   },
   '-a, --async'(argv) {

   }
}

let router = argvRouter(options, '-w')

动态执行

在js中动态执行指定的cli命令

let router = argvRouter(options)

router.execute('-v')

router.execute('-w -a')