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

erii

v2.0.6

Published

![](./logo.png)

Downloads

265

Readme

Erii

npm version

Installation

npm install erii --save

Usage

const Erii = require('erii').default;

Erii.setMetaInfo({
    version: '0.0.1',
    name: 'example'
});

// Bind commands
Erii.bind({
    name: ['help', 'h'], // `h` will be set as an alias
    description: 'Show Help', // command description
    argument: {
        name: 'command',
        description: 'query help of a specified command'
    }
}, (ctx, options) => {
    ctx.showHelp(); // show help text
});

// add options for `help` command
Erii.addOption({
    name: ['verbose', 'debug'], 
    command: 'help', // bind to command
    description: 'debug output', // option description
    argument: { // definition of option argument
        name: 'level',
        description: 'level of debug output'
    }
});

Erii.addOption({
    name: ['test'],
    // without binding to a specified command,
    // this option will be set as a common option.
    description: 'show test information',
    argument: {
        name: 'test-argument',
        description: 'test argument'
    }
});

Erii.start(); // don't forget to start Erii.

Example

Call with

node index.js --help xxx --debug 1

// ...
// PART OF CODE
Erii.bind({
    name: ['help', 'h'], 
    description: 'Show Help',
    argument: {
        name: 'command',
        description: 'query help of a specified command'
    }
}, (ctx, options) => {
    const { debug } = options;
    console.log(debug);  // '1'
    console.log(ctx.getArgument()); // 'xxx'
});

Erii.addOption({
    name: ['verbose', 'debug'],
    description: 'show verbose output',
    argument: {
        name: 'level',
        description: 'level of verbose output'
    }
});

Erii.start();

Help Text

example / 0.0.1

Help:
     Commands                      Description                   Alias

     --help <command>              Show Help                     --h
         <command>                 query help of a specified comm

Options:

     Options                       Description
     --verbose, debug <level>      show verbose output
         <level>                   level of verbose output

Argument Validation

Argument validation are based on validator.js.

Erii.validator points to a validator exported by validator.js.

Erii can validate arguments automatically.

Define the validate methods in argument parameter.

Erii.addOption({
    name: ['verbose', 'debug'],
    description: 'show verbose output',
    argument: {
        name: 'level',
        description: 'level of verbose output',
        validate: 'isInt'
    }
});

validate can also be a function, for example:

Erii.addOption({
    name: ['verbose', 'debug'],
    description: 'show verbose output',
    argument: {
        name: 'level',
        description: 'level of verbose output',
        validate: (value) => Erii.validator.isInt(value)
    }
});

argument.validate works in both command and option definitions.

Example Output for Argument Validation

PS D:\Git\erii.test> node index.js --help --verbose f
Argument validation failed for option 'verbose'.
<level> should be a/an Int.