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

yargs-lite

v1.1.2

Published

lite implementation of yargs

Downloads

10

Readme

yargs-lite

lite-weight yargs, speed up your cli in some cases

setup

  1. go to your project directory and create bin folder

  2. create bin/index.js and put #!/usr/bin/env node on the top of the file

  3. (optional) chmod 777 bin/index.js

  4. package.json : {..."scripts":{ "myscript": "./bin/index.js" }, "bin": {"myscript": "bin/index.js"}}

  5. use npm run myscript or call ./bin/index.js directly

  6. under bin/index.js checkout example

  7. (opitonal) link you command, or put it under path variables so you can use your command directly. i.e. sudo -u root ln -s bin/index.js /usr/bin/myscript

example

#!/usr/bin/env node
const yargslite = require("yargs-lite");
let yargs = new yargslite();

yargs.addHelpDocEntry("--help", "general help page\ndisplay:\tdisplay storage");

yargs.addCommand("display", (storage) => console.log(storage));
yargs.addHelpDocEntry("display", "display the storage from yargs");

yargs.run();

./bin/index.js display

=>

{
  origin: { argv: [...]},
  argv: [ 'display' ],
  entry: 'display',
  _: [],
  args: {},
  kwargs: {}
}

./bin/index.js --help
./bin/index.js display --help

=>

general help page
display:      display storage

display the storage from yargs
./bin/index.js display 10 -a 11 -cd 12 --e --f 13

=>

{
  origin: { argv: [...]},
  argv: [ ... ],
  entry: 'display',
  _: [ '10' ],
  args: { a: [ '11' ], c: [ '12' ], d: [ '12' ] },
  kwargs: { e: [ '13' ], f: [ '13' ] }
}

Adv.

Change help doc display

let fancyLogger = (content) => console.log("---", content, "---");
yargs.help.helpDocDisplay = (entry, doc) => fancyLogger(doc[entry]);

Super fast doc loading

yargs.help.helpDoc = require("pre-defined-doc.json");

Define your own parser

yargs.addParser((storage) => {
  storage.args = { "-v": "10" };
  storage.kwargs = { "--value": "ten" };
  storage.extra = "message";
});

yargs.addCommand("test", (storage) => console.log(storage.args, storage.kwargs, storage.extra));

and run

./bin/index.js test

=>

{ '-v': '10' } { '--value': 'ten' } message

pattern and logic

let's define some parameters as

./s a b -c -d --e --f g

and ignore the entry (full command should be something like ./bin/index.js -c a --e b), and the default result contains {args:{}, kwargs:{}, _:[]}

straight-forward case example

# 1 to 1 pair
./s -c a -d b       # args:{c:[a], d:[b]}
./s --e a --f b     # kwargs:{e:[a], f:[b]}

./s a               # _:[a]

ambiguous case example

# n to 1 pair
./s -cd a           # args:{c:[a], d:[a]}
./s -c -d a         # args:{c:[a], d:[a]}
./s -c -d --f b     # args:{c:[b], d:[b]}, kwargs:{f:[b]}

# other example
./s a -cd b g       # _:[a], args:{c:[b,g], d:[b,g]}
./s a --f b g       # _:[a], kwargs:{f:[b,g]}
./s a b g           # _:[a,b,g]
./s a -c abg        # _:[a], args:{c:[a,b,g]}
./s a --ef b g      # _:[a], kwargs:{ef:[b,g]}

./s a -cd           # _:[a], args:{c:[], d:[]}
./s a -cd g -cd     # _:[a], args:{c:[], d:[]}
./s a ---ef         # _:[a], kwargs:{ef:[]}

version >= 1.1.0

./s -cd=a           # args:{c:[a], d:[a]}