micro-ap
v0.4.4
Published
tiny arg parser
Downloads
25
Readme
tiny arg parser
Installation
$ npm i micro-apAbout
micro-a is a small and opinionated argument parser library without any additional dependencies.
Functions
flag(flag, name, fallback = false)
Extract flag arguments
flag(string); one char as flag e.g.-fname(string); full name of a flag e.g.--filefallback(string); default value
command(name, fallback = false)
Extract command arguments
name(string); name of the command e.g.installfallback(string); default value
get()
Returns the parsed arguments as an object
Examples
const parser = require('micro-ap');
// simple
// node index.js install test --verbose
parser(process.argv)
.flag('v', 'verbose')
.command('install')
.get() // returns {"verbose": true, "install": "test"}
;
// complex
// node index.js install foo -o console -f one.js two.js three.js -f four.js
parser(process.argv)
.command('install')
.flag('f', 'file')
.flag('o', 'output')
.flag('v', 'verbose', true)
.get() // returns {"install": "test", "verbose": true, "output": "console", "file": ["one.js", "two.js", "three.js", "four.js"]}
;Licence
MIT License, see LICENSE
