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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ncommand

v0.0.7

Published

Ncommand是一个控制台交互式命令解析控制器。可以快速便捷的开发一个新的脚手架。

Downloads

9

Readme

Ncommand npm github

Ncommand是一个控制台交互式命令解析控制器。可以快速便捷的开发一个新的脚手架。

安装

npm i ncommand

教程

1、引入Ncommand
var command = require("Ncommand");
2、初始化cmmmand方法
new command(Options)
说明:
Optionsc(Object),选填
Optionsc.input {Object|Array},默认为["Commands","Options"],例如:
new command({input:[]}) 
Optionsc.input[args,...] {String|Object},例如:
new command({input:["name1","name2"]})
new command({input:[{
    fnName:"name1",
    title:"我是附带说明" //选填
},"name2"]})
//如果更改了默认的Optionsc参数选项的话,那么后面就该调用对应方法,例如:
new command({input:["name1","name2"]}).name1().name2();
3、Ncommand方法
new command()
    .Commands(param)
    //....
    .Options(param)
    //....
说明:
param {Object},选填,不填就不执行任何事物
param.log {Array},必填,例如:
new command()
    .Commands({
        log:[args,...]
    })
param.output {Boolean},选填,例如:
new command()
    .Commands({
        //默认为true,如果为true则是打印输出命令,如果为false则不输出命令,
        //可以理解成功如果设置为false的话,当前的命令,用户看不到,但它
        //又确实存在,所以利用这个字段可实现隐藏命令
        output:false
    })
param.callback {Function},选填,例如:
new command()
    .Commands({
        log:["参数A",args,...],
        callback:function(agvs,newAgvs){
            //这里是当前参数的回调函数
            console.log(this);//this是new command()对象,承接上下文
            console.log(agvs);//agvs是当前执行参数,即 “ 参数A ”
            console.log(newAgvs);//newAgvs是当前执行参数以后的参数,例如: “node test.js 参数A 参数B... ”,即"包含参数B以后的参数"
            this
            .Commands({
                 log:["参数B",args,...],
                 callback:function(agvs,newAgvs,cmdParam){
                     //这里是当前参数的回调函数
                     console.log(this);//this是new command()对象,承接上下文
                     console.log(agvs);//agvs是当前执行参数,即 “ 参数B ”
                     console.log(newAgvs);//newAgvs是当前执行参数以后的参数,例如: “node test.js 参数A 参数B... ”,即"包含参数B以后的参数"
                     console.log(cmdParam);//cmdParam是当前命令的有关参数。
                     //.....可以无限嵌套下去或者执行其他事物
                 }
             })
             .init();
             //.....可以无限嵌套下去或者执行其他事物
        }
    })
4、执行初始化 .init(callback,showCallback)
new command()
    .Commands({
        log:["参数a"]
    })
    .init(callback,showCallback);
说明:
callback {Function},选填,例如:
new command()
    .Commands({
        log:[args,...]
    })
    .init(function(){
        //这是init的回调方法
        console.log(this);//this是new command()对象,承接上下文
    });
showCallback {Array},选填,例如:
new command()
    .Commands({
        log:[args,...]
    })
    .init(new Function,function(){
        //帮助的回调方法
        console.log(this);//this是new command()对象,承接上下文
    });
//备注:如果showCallback传,则不会打印帮助提示信息,等同于你在自定义帮助提示。
//      如果showCallback不传,则会打印帮助提示信息。
//      如果showCallback传null,则会打印帮助提示信息。
//      如果showCallback的返回值为true的话,不结束当前程序,默认为false,即结束当前程序
5、.end(Opt)
new command()
    .Commands({
        log:[args,...]
    })
    .end(Opt)
    .init(callback,showCallback);
说明:
Opt {String|Function},选填,不填插入一行空信息,例如:
new command()
    .Commands({
        log:[args,...]
    })
    .end("我是插入信息")
    .end(function(){
        //这是end的回调方法
        console.log(this);//this是new command()对象,承接上下文
        //彩色信息输入(如需彩色输入,请参考:https://github.com/zys8119/ncol)
        this.console
                    .red("红色")
                    .yellow("黄色")
                    .color(function () {
                        this
                            .red(" 哈哈~")
                            .yellow("哈哈~")
                            .success("哈哈~")
                            .info("哈哈~")
                    })
                    .success("成功");
    })
    .init(function(){
        //这是init的回调方法
        console.log(this);//this是new command()对象,承接上下文
    });

例子如下

var command = require("./index");
new command()
    .Commands({
        log:["a","这是...red('一')个命令",{},[]],
        callback:function () {
            this
                .Commands({
                    log:["c","这是a命令下的c命令",{},[]],
                    callback:function () {
                        console.log(this)
                    }
                })
                .Commands({
                    log:["-h","这是帮助命令",{},[]],
                    callback:function () {
                        console.log(this)
                    }
                })
                .init();
        }
    })
    .end("我是插入的信息")
    .end(function() {
        this.console
            .red("红色")
            .yellow("黄色")
            .color(function () {
                this
                    .red(" 哈哈~")
                    .yellow("哈哈~")
                    .success("哈哈~")
                    .info("哈哈~")
            })
            .success("成功");
            //...
    })
    .Commands({
        log:["b"],
    })
    .Options({
        log:["c"],
        callback:function (w,e,cmds) {
            this.console.warn("我是当前的argv参数:"+w);
            this.console.warn("我是c命令之后的argv参数:"+e);
            this.console.warn("我是当前命令的相关参数:"+JSON.stringify(cmds));
        }
    })
    .Options({
        log:["d"],
        output:false,
        callback:function (w,e) {
            this.console.warn("我是隐藏命令,我不输出,但我确实存在,哈哈。");
        }
    })
    .init();
具体方法及配置请查看源代码
如需颜色输出请查看ncolAPI文档