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

sg-argv

v1.0.93

Published

Parse CLI Arguments for Easy Use in Javascript.

Downloads

16

Readme

sg-argv

Command-line argument parsing.

Parse CLI Arguments for Easy Use in Javascript

Usage

npm install sg-argv

Then

const sg      = require('sg-argv');

// ...

const ARGV    = sg.ARGV();

if (ARGV.fooBar) {
  // ...
}

sg-argv will analyze process.argv, and build JSON, and be reasonably intelligent about it.

Run the see.js script in the root of the sg-argv repo, and see what converts to what.

$ node see.js cmd \
    --multi-seg-opt=55 \
    --flag \
    --opt=val \
    --arr= one two three \
    --json={"a":42} \
    --json2={'foo':'bar'} \
    --bad- \
    --no-op2 \
    --re=/^[a-z]+/ \
    --date=2019-11-25T04:07:23.314Z \
    [email protected] \
    --license=@LICENSE

=>

              arr       Array     ["one","two","three"]
              bad     boolean                     false
              op2     boolean                     false
                _       Array                   ["cmd"]
    multi-seg-opt      number                        55
             flag     boolean                      true
              opt      string                     "val"
             json      object                  {"a":42}
            json2      object             {"foo":"bar"}
               re      RegExp                 /^[a-z]+/
            debug     boolean                      true
    multi_seg_opt      number                        55
      multiSegOpt      number                        55
         _command      string                     "cmd"

             date        Date     Sun Nov 24 2019 20:07:23 GMT-0800 (Pacific Standard Time)

          package      object {"name":"sg-argv","version":"1.0.73","description":"Parameter parsing.","main":"...
          license      string "MIT License\nCopyright (c) 2016 Brian C Sparks\nPermission is hereby granted, f...
  • Provides snake-case and camel-case versions of the keys, because this-is-not a dottable key on an object.
  • Parses the values in a smart, but not too smart, way.
  • Provides a few extension functions if you need to do more.
  • Provides versions that produce only POD results.

It will convert the following:

  • Items that are all digits are converted to Numbers.
  • Items that have all digits, except one dot, are also converted to Numbers.
  • true, false, and null, are converted to true, false, and null.
  • Dates in the format: 2018-12-31T10:08:56.016Z are converted to Dates.
  • Items that start and end with / are converted to RegExps.
  • JSON is read and parsed as JSON.
  • JSON that has single-quotes in place of double quotes is read, has the single-quotes turned into double-quotes and is parsed as JSON.
    • The conversion is a straight one-to-one conversion, nothing intelligent is done.

And:

  • --items-like-this= a b c will be read as Arrays.
    • {itemsLikeThis: ['a', 'b', 'c'], _: []}
  • --items-like-this=a b c is a string and parameters.
    • {itemsLikeThis: 'a', _: ['b', 'c']}
  • --file=@path/to/file is read in from a file (becomes a string).
  • --file=@path/to/file.json is read in from a file (parsed as JSON).
  • --negative-opt- is one way to say false: {negativeOpt: false}
  • --no-cheese is another way to say false: {cheese: false}