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

qtools-parse-command-line

v1.0.8

Published

zero configuration command line argument parser; just grabs the stuff and makes a JS object out of it

Downloads

50

Readme

qtools Parse Command Line

====================================================== UPDATED: Now parses injected string instead of argv

New parameters: injectedCommandString, injectFirstTwoElements

Added input parameter, injectedCommandString, that substitutes an artificially created command string for process.argv. It is parsed by injectedCommandString.split(/ +/) and as far as I can tell, acts exactly like it should, ie, if injectedCommandString.replace(/ +/g, ' ')==process.argv.join(' ') then it produces the same result.

NOTE: Normal process.argv has node and the program name in the first two positions in the argv array. If you your artificial command string is values only, ie, does not have the first two values, you can add the parameter, injectFirstTwoElements:true. This will inject a pair of dummy values at the front of the fake argv array and all will work correctly.

tqii 5/13/24

processCommandLine() analyzes argv and returns the results for use by the calling program.

For historical reasons, it defaults to evaluating incoming Javascript. This can, of course, be dangerous. It should be called with the 'noFunctions:true' argument unless you need function evaluation.

var commandLineParms = qtools.parseCommandLine({noFunctions:true})

processCommandLine() produces an object with four elements: { calledFromCommandLine: true|false, fileList:[], values: {}, functions: {}, switches: {} }

fileList is anything that is has no switch and resolves to a file or directory

VALUE PARAMETERS

--name=value

UPDATE (6/28/18) added:

--name value

UPDATE (11/4/19) ADDED:

--namelist=sam,henry,joan

(If valuesSplitCharacter is specified in args; otherwise, still a string)

applies to all cases below.

Anything in the command line of that form is processed to become either a value or a function.

  1. Parsed to see if it's javascript and evaluated eg,

     --tmp="(2+5)"

    produces a property

     values:{tmp:7}

    or,

     --tmp="(function(a){return 2*a})"

    produces a property

     functions:{tmp:function(a){return 2*a;}}

    that can be called later as commandLineOutput.functions.tmp(parameter)

    or (of course),

     --tmp="hello world"

    produces a property

     values:{tmp:"hello world"}

    however, there is a special case for strings, eg,

     --tmp=/path/to/function.js

    is checked to see if it resolves to a file. (The path is not relative

    or glob'd. It must be fully specified.)

    If it does not produce a value, the property is then eval'd to

    see if it produces a value.

     values:{tmp:"/path/to/function.js"}

    If it does parse and produce a value, the property is,

     values:{tmp:'some value resulting from the file'}

    unless it results in a function, in which case, the property is,

     functions:{tmp:function(){/ *whatever is in the file* /}}

    Important note: The function definition must be wrapped in parenthesis.

    eg,

     (function(input){ return input*2;})

    Otherwise it will not eval() and will be treated as a string value.

SWITCHES

-switchName

Anything of that form creates a property, values:{switchName:true}