micro-ap
TypeScript icon, indicating that this package has built-in type declarations

0.4.4 • Public • Published

micro-ap

npm version types size coverage Dependencies devDependencies License

tiny arg parser


Installation

$ npm i micro-ap

About

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. -f
  • name (string); full name of a flag e.g. --file
  • fallback (string); default value

command(name, fallback = false)

Extract command arguments

  • name (string); name of the command e.g. install
  • fallback (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

Readme

Keywords

Package Sidebar

Install

npm i micro-ap

Weekly Downloads

3

Version

0.4.4

License

MIT

Unpacked Size

8.16 kB

Total Files

8

Last publish

Collaborators

  • sovrin