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

process-argv-parser

v0.0.1

Published

process.argv parser

Readme

背景

常需要从运行命令中,获取参数,现有的工具,不能很好的区分npm scripts与命令行间的参数,所以才有了这个项目。

参考如下场景:

// package.json
{
  "scripts": {
    "server": "node index.js --server=3005 --open=index.html"
  }
}

假设在 package.json 中,配置了 npm run server 命令,能快速启动服务器,并且打开页面 index.html

在控制台,我们这样调用:

npm run server --staticDirname=xxx

其中 --dirname=xxx 是决定服务器运行时,静态资源路径来源的。

这时候,我们 process.argv 中,获取到的,只有:

console.log(process.argv); // => [node.exe, index.js, '--server=3005', '--open=index.html']

其中的 --dirname=xxx 去哪呢?此项目,解决的,就是这个问题。

API

本项目,把 package.jsonscripts 自带的参数,称为 inner参数,命令行中,自己输入的参数,称为 outer参数

例子:

const Parser = require('process-argv-parser');
const parser = new Parser();

// 定义参数值的转换方法,否则,默认都是字符串 或 Boolean 值
// -d xxx => { dirname: 'xxx' }
// --server=1000 => { server: 1000 }
// -o index.html => { open: 'index.html' }
parser
  .option('-d', 'dirname', Parser.String)
  .option('--server', parserInt)
  .option('-o', 'open');

const data = parser.parse(/* void 0  或 数组: ['--server=3005', '--open', 'index.html']*/);

// 如果是 npm run xxx --param1=xx 则会在 outer 中体现
// 否则,都在 inner 中,获取参数
console.log(data); // argv => { inner: {}, outer: {} }