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

brutus

v2.0.0

Published

A tool for creating a cli which uses cli options and package.json options and merge them into default options

Downloads

16

Readme

brutus v2.0.0 Build Status codecov.io

A tool for creating a cli which uses cli options and package.json options and merge them into default options

Install

npm install --save brutus

Usage

var brutus = require('brutus')({

    name: 'mycommand',
    options: {
        foo: "abc",
        bar: {},
        baz: [100, 200]
    },
    delegate: {

        mergeCliOptionsToPackageOptions: function (cliOptions, pkgOptions) {
            // merge options
        },

        mergePackageOptionsToCommandOptions: function (pkgOptions, cmdOptions) {
            // merge options
        },

        execute: function (cliOptions, cmdOptions) {
            // main process
        }

    }

})

// execute as a cli command (using cli options)
brutus.execAsCli()

Options

name: String

The name of the command. This is used as the key of the user's package options.

{
    "name": "users-package",

    "snowball": {
        "foo": "bar"
    }
}

If your command name is snowball, then the user's package options are {"foo": "bar"} in the above example.

options: Object

The default options for the command.

delegate: CommandDelegate Interface

Brutus delegates the merging methods and command execution through delegate object.

mergeCliOptionsToPkgOptions(cliOptions, pkgOptions)

param | type -----------|----- cliOptions | Object pkgOptions | Object

Merges the user's cli options to the user's package options.

cliOptions is the parsed argv using minimist (i.e. require('minimist')(process.argv.slice(2)) )

mergePkgOptionsToCommandOptions(pkgOptions, cmdOptions)

param | type -----------|----- pkgOptions | Object cmdOptions | Object

Merges the user's package options to the command default options.

pkgOptions are the part of the user's package.json of the key of your command name.

For example, your cmdName is snowball and the user's package.json is like the below:

{
    "name": "my-package",
    "snowball": {
        "foo": "bar"
    }
}

Then the pkgOptions are {foo: "bar"}. This is useful when you make your command's behaviour configurable by the user's package.json.

execute(cliOptions, cmdOptions)

param | type -----------|----- cliOptions | Object cmdOptions | Object

Executes the command with cli and command options. The return value of execute becomes the exit code of the cli.

cmdOptions include information merged from the user's cli options and the user's package options using the above 2 methods.