arg-to-object

1.2.3 • Public • Published

Build Status Coverage Status dependencies Status

ARG-TO-OBJECT

ATO is a quick-and-dirty argument parser meant for situations when a complicated CLI isn't necessary.

Use process.argv by default.

const ato = require('arg-to-object')
var params = ato.parse()

An object can be used for defaults.

// node sample.js -files a b c -r false
var defaults = { files: [], recursive: true }
var params = ato.parse(defaults)
 
/*
 * {
 *   files: ["a", "b", "c"],
 *   recursive: false
 * }
 */

Argument shorthands are expanded by a simple prefix-search

// node sample.js -f a b c -r 
params = ato.parse(defaults)
 
/* '-f' extends to 'files'
 * { files: ["a", "b", "c"], ... }
 */ 

Pass in arguments manually.

ato.parse(process.argv, defaults)

Without a default object, the parsed object will constructed with _-tak_s as keys. The arguments -f a b c -r will yield

{
  f: ["a", "b", "c"],
  r: true
}

Type interpolation examples.
args=-r result={r: true}
args=-r 1 2 3 result={r: [1, 2, 3]}
args=-r false result={r: false}
args=-r -f hello result={r: true, f: 'hello'}

Package Sidebar

Install

npm i arg-to-object

Weekly Downloads

1

Version

1.2.3

License

ISC

Last publish

Collaborators

  • matutter