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

vcate

v0.1.8

Published

This library is designed to simplify the handling of command line arguments.

Downloads

8

Readme

VCate

This library is designed to simplify the handling of command line arguments.

This documentation is valid for version 0.0.9.

Start

Install:

npm install vcate

Import:

const VCate = require("vcate");

Work

After installation and import, you need to initialize the class.

const argv = process.argv;
const VCate = require("vcate");

let cat = new VCate(argv);

.add

To add a command to which the library will respond, use the ".add" command.

const argv = process.argv;
const VCate = require("vcate");

let cat = new VCate(argv);

cat.add("command", function(argv=[""], option=null){}, option={});

command - this is the command to which the library will respond.

function - this is a function that will be called if the command is found. It has two arguments, it is argv=[""] it is an array of arguments that was passed during the initialization of the class, option=null is an object to which the parameters will be transferred, how to set them will be explained later.

option - This is not a mandatory argument (if it is not set, the option in the function is also not needed), it is an object with functions.

.listen

To start listening to commands, there is a ".listen" command, it must be at the end after adding all commands.

const argv = process.argv;
const VCate = require("vcate");

let cat = new VCate(argv);

cat.add("command", function(argv=[""], option=null){}, option={});
cat.listen();

.notFound

There is also an option to set a command in case an unexpected command was entered for this e.t.notFound parameter.

const argv = process.argv;
const VCate = require("vcate");

let cat = new VCate(argv);

cat.notFound = ()=>console.log("Command not found.")

cat.add("command", function(argv=[""], option=null){}, option={});
cat.listen();

Example

Let's create a small program that will display the text in red when the "red" command is used, and green when the "green" command is used.

// We get the term parameters.
const argv = process.argv;
// We import Vcate
const VCate = require("vcate");
// Import the auxiliary class Console.
const Console = require("vcate/Console");
// Let's initialize the class.
let cat = new VCate(argv);
// We install the .notFound command
cat.notFound = ()=>Console.error("Command not found.")
// Add a command for red color.
cat.add("red", (argv=[""], option=null)=>{
    // We check whether there is a field we need in option.
    if(option.what){
        // Output as an error to obtain a red color.
        Console.error(option.what);
    };
}, {
    what: (argv)=>{
        // We process the "what" field in "option" and return the required value, in our case this is the text to be displayed.
        if(argv[3]){
            return argv.slice(3).join(" ");
        } else {
            return false;
        };
    }
});
// We do everything the same as for red, but output through confirm to get green color.
cat.add("green", (argv=[""], option=null)=>{
    if(option.what){
        Console.confirm(option.what);
    };
}, {
    what: (argv)=>{
        if(argv[3]){
            return argv.slice(3).join(" ");
        } else {
            return false;
        };
    }
});

cat.listen();

Now when running "node app red Hello!" will be displayed in red "Hello!" and when "node app green !olleH" is green "!elloH" and if you run "node app yellow WoW" it will be displayed in red "Command not found.".