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

process.args

v0.1.1

Published

get parameters from cli

Downloads

54

Readme

process.args

light-weight command line arguments parser for cli application

Install

npm install process.args --save-dev

Usage

var args = require('process.args')([find,alias]);
  1. get all commands in command line
// script.js
var args = require('process.args')();
console.log(args);

Then run in CLI:

node script.js -v add --name=new_component --template=./templates/default.tpl

Then you will get:

{
	node: {},
	'script.js': {
		v: true
	},
	add: {
		name: 'new_component',
		template: './templates/default.tpl'
	}
}
  1. get a command's parameters by command name
var args = require('process.args')('add');
console.log(args);

Run the same command, and you will get:

{
	name: 'new_component',
	template: './templates/default.tpl'
}
  1. set alias

The second parameter is alias which calls full name for shortname. e.g.

var args = require('process.args')({
	v: 'version',
	g: 'global'
});

Then you run:

your -v=1.2.3 -g

args will be:

{
	your: {
		version: 1.2.3,
		global: true
	}
}

The result dosen't have v but has version.

Well, if you give a object for the first param, it will be used as alias not find. find is only used with string.

alias will only work on - params. alias of --bmk will not work.

Why this CLI appearance?

I have seen many kinds of cli parameters appearance, like:

(npm install) bower
-v
--version
-name my_name
--name my_name
-name=my_name
--name=my_name

A command line in my mind always follow the model:

{basic command [-options]} {action [-options] [--params]*}+ {---global_options_or_params}*
# + means repeat once or more
# * means repeat none or more

For example:

node -v
npm run test -h --cwd=~/dev/project
gulp add --name=my_plugin build --name=my_plugin
gulp add build preview ---name=my_plugin2

This is the reason why I use this appearance.

In process.args:

  • - short alias: e.g. -v -h -g
  • -- key=value pairs: e.g. --name="Nick" --host="192.168.0.1"
  • --- super param: e.g. ---v means all before this command will be set -v, ---name="Park" means all before this will be set --name="Park"
gulp build --path="./js" preview -b ---without-feedback go --link="http://www.google.com"

Let's look at ---without-feedback. This means, build and preview task will both be set without-feedback, go will not be set bcause of position behind.

If you set a key twice, the value will be a array.

gulp build --path="./js" --path="./css"

Then path will be a array.

Convention

  • only [a-zA-Z0-9] and _ could be used for parameter key name.
  • the first letter of key name should be character.
  • no blank could be use in value, you can use quota for more than one word, for example: --place="Shenzhen China"
  • without - at the beginning of a word, it will be considered as a task or command, not a parameter.
  • more than three - at the beginning of a word makes this part no use doing nothing, for example: ----link="http://github.com", this will be abandoned.