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

switchit

v1.0.8

Published

Command-line Switcher and Dispatcher

Downloads

2,944

Readme

switchit logo

Build Status Coverage Status Dependencies Status npm version MIT Licence

switchit

A no-nonsense framework for command-line switch parsing and command dispatching.

switchit enables you to write modern command-line applications using a straightforward API and features including:

There are so many features and functionality to describe that they got its own document just to outline them all!

Getting Started

Quick Start

Install switchit into your project:

$ npm install switchit --save

Create a .js file and add the following:

const Command = require('switchit').Command;

class SayHi extends Command {
    execute (params) {
        console.log(`Hi, ${params.name}!`);
    }
}

SayHi.define({
    switches: 'name'
});

new SayHi().run();

Run your project file, don't forget to pass --name:

$ node examples/sayhi.js --name John
Hi, John!

Support for positional arguments

You can also accept positional arguments as parameters in your command:

...

SayHi.define({
    parameters: 'name'  // changed this from "switches" to "parameters"
});

...

Look ma, no switches!

$ node examples/parameter.js Paul
Hi, Paul!

Do you want to read a parameter form either positional arguments or switches? switchit supports it too!

Promises? switchit has those too!

The .run() method returns a promise!

...

new SayHi().run().then(() => { 
    console.log("Success!"); 
},(e) => { 
    console.error(`Oh no! ${e.message}`) 
});

Check it out:

$ node examples/promise.js
Oh no! Missing value for parameter: "name"
$ node examples/promise.js George 
Hi, George!
Success!

Interactive prompt for missing values

Wanna see somethiing awesome? Just add interactive: true to your command definition:

....

SayHi.define({
    parameters: 'name',
    interactive: true,
    // Optionally add some help texts to improve the UI
    //  more info at docs/Features.md#built-in-help
    help: {
        '': 'This is a command that says hi!',
        'name': 'Your name'
    }
});

...

Run it with no arguments to see it in action:

$ node interactive.js
This is a command that says hi!
Press ^C at any time to quit.

Your name
? name: 

Check docs/Features.md for more information on how to take advantage of this feature.

More examples and API

Once you get the hang of the examples above, make sure to check our examples directory or our complete docs for more information and API docs.

Contributing

Please read CONTRIBUTING.md for details on the code of conduct, and the process for submitting pull requests.

Versioning

switchit uses SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details