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

read-and-excute

v1.0.3

Published

a tool can read command line args and excute

Readme

项目简介

该工具用于解析命令行指令及参数,具有轻量的特点,无任何第三方依赖。其具体格式为:command -instruct_1 param_1 param_2 -instruct_2 param_1 param_2。假设运行:

node index.js -open chrome -config config.js // chrome为-open参数,config.js为-config参数
node index.js -o chrome -c config.js // chrome 为 -o参数,config.js为-config参数
node index.js -o -c config.js // -o使用默认配置
node index.js -o chrome firefox // -c使用默认配置,-o参数为chrome和firefox

即,一个指令可以对应于多个参数。

用法介绍

var Args = require('read-and-excute');

配置

var customArgs = new Args({
    binName: '', // 可选,默认为'userBin'
    version: '', // 可选,默认为'1.0.0'
    commands: [], // 字符串数组,可选。可通过addCommand添加。
    commandsAndOptionsTips: '', // 可选,用于描述指令和选项
    descriptions: [], // 字符串数组,可选,用于描述指令的作用。可通过addCommand添加。
    options: [[]], // 字符串数组的数组,可选。可通过addOptions添加选项。
    realFunction: [], // commands对应的执行函数,可选。可通过addCommand添加。
    globalConfig: {}, // 全局配置,可选。
});
其中,commands、options、realFunction中的顺序一一对应。
globalConfig = {
    replaceCommandWhenAdd: false, // 默认为false, 表示不覆盖已有的command配置。若使用默认设置,当对已有command配置进行addCommand时会报错
}

添加指令

/**
 * 添加一条指令
 * @param  {string} instruct 添加指令的字符串
 * @param  {string} description 添加指令的描述
 * @param  {function} callback 命中指令时的回调
 * @return {customArgs}     返回调用该方法的对象
 */
customArgs.addCommand(instruct, description, callback);

对已有或者尚未添加的指令添加选项

/**
 * 添加选项
 * @param  {string} instruct 已存在或者未存在的指令
 * @param  {string|array} options 需要添加的选项
 * @return {customArgs}     返回调用该方法的对象
 */
customArgs.addOptions(instruct, options);

使用addConfig添加指令和选项

/**
 * 添加指令和选项
 * @param  {object} config 需要添加的指令和选项
 * @return {customArgs}     返回调用该方法的对象
 */
customArgs.addConfig(config);
其中,config = {
    command: string,
    description: string,
    options: string[],
    callback: function
}

显示帮助菜单

node index.js -help
# 将会显示帮助菜单

执行

/**
 * 执行命令
 * @return {customArgs}     返回调用该方法的对象
 */
customArgs.excute();

执行回调时会将参数传入函数。如将['chrome', 'firefox']传入回调。

升级说明

v1.0.1

修改了更为详细的注释。Args.addOptions添加了对字符串options的支持。

v1.0.2

添加使用-help指令显示帮助文档。

v1.0.3

修复相对解析地址错误。