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

senzu

v1.0.1

Published

Senzu, convenient CLI options parser

Downloads

2

Readme

Senzu, convenient CLI options parser

Introduction

Senzu is lightweight tool without dependency for CLI options parsing. Options are not typed and the parser don't throw error. Senzu is a parser, not a checker, for greater flexibility it is your responsibility to check the input of the user.

Examples

cmd
cmd -h
cmd -hhhh
cmd --optimize-level 2
cmd -O2 path/to/src
cmd --includes ../inc0 ../inc1 -- path/to/src
cmd -I../inc0 -I ../inc2 path/to/src -o a.exe

Configuration for this example:

const senzu = require("senzu")

const options = senzu({
    "includes" : { text: "set includes paths", ch: "I", array: true },
    "output" : { text: "set output path", ch: "o" },
    "optimize-level" : { text: "set optimization level", ch: "O", parse: parseInt },
    "help" : { text: "show help", ch: "h", atomic: true }
}, process.argv.slice(1))

options["paths"]; // access an option, undefined if the user dont specify it
options.wanderers; // access other args (like "path/to/src" in examples above)

Let's check the respectives outputs:

{ }
{ 'help': true }
{ 'help': true }
{ 'optimize-level': 2 }
{ wanderers: [ 'path/to/src' ], 'optimize-level': 2 }
{ wanderers: [ 'path/to/src' ], 'includes': [ '../inc0', '../inc1' ] }
{ wanderers: [ 'path/to/src' ], 'includes': [ '../inc0', '../inc2' ], 'output': 'a.exe' }

Features

Prototype of the senzu function:

function senzu (templates, args = require("process").argv.slice(2))

List of parameters available for an option template:

  • text: The text that appears in the "help" command.
  • ch (optional): A character alias which will be used with a single -. Character can be directly followed by its corresponding value like -I../inc and can only grab one argument forward.
  • atomic (optional): The option character can be grouped with other atomics characters and will not grab following arguments. It handle option of the form -hVfz for example.
  • array (optional): The option will be an array (it will grab all following arguments if the option is specified like --includes but not like -I). It isn't compatible with atomic.
  • parse (optional): A parse function to transform arguments. It is good practice to not use it as a checker and to not throw errors. It has no effect with atomic.

Help message generation: use senzu.helpmessage to generate a basic help message like:

Usage: cmd [options] <files>
Options:
        --includes, -I          set includes paths
        --output, -o            set output path
        --optimize-level, -O    set optimization level
        --help, -h              show help

Full example:

const options = senzu(templates);

const config = {
    usage: "cmd [options] <files>", // set to false to desactivate
    indent_level: 0, 
    format_line = line => line
}

if (options.help === true)
    senzu.helpmessage(templates, config); // config can be ommited

Notes

If an option isn't specified it will be undefined.

If options specified by the user are not recognized they will be pushed in wanderers, for example cmd -a -b path/to/src will give ["-a", "-b", "path/to/src"]. If you want to throw an error in this case, loop and check in the array.

wanderers is reserved option name

Options are recognized using object as hashmap.