kawkah-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

The argument parser for Kawkah. If you're looking for a full blow CLI parser you probably want Kawkah. You can think of kawkah-parser as sort of a normalizer before you would validate the parsed result against a schema then trigger perhaps an action. If you simply want to parse whatcha got and then handle constraints/coercion yourself kawkah-parser works great.

Install

$ npm install kawkah-parser

Usage

import { parse } from 'kawkah-parser';
const args = 'install /some/path names... tim sally joe --user.name bob --force --tags red --tags blue -abc -vvvvv --no-rename';
const result = parse();

Your result would be:

result = {
  _: ['install', '/some/path'],
  force: true,
  tags: ['red', 'blue'],
  names: ['jim', 'sally', 'joe'],
  user: { name: 'bob' },
  a: true,
  b: true,
  c: true,
  v: 5,
  rename: false,
  __: []
};

Options

For addtional option detail and API info see Docs below.

charVariadic

Character denoting variadic arguments.

const args = 'create blog java... c python javascript'
const result = parse(args);

Result would be:

result = {
  _: ['create', 'blog', ['java', 'c', 'python', 'javascript']],
};
Type string
Default ...

charAbort

Character used to abort parsing of args.

const args = 'create blog -- ignore1 ignore2'
const result = parse(args);

Result would be:

result = {
  _: ['create', 'blog'],
  __: ['ignore1', 'ignore2']
};
Type string
Default --

charNegate

Character used to negate boolean flags.

const args = '--no-force'
const result = parse(args);

Result would be:

result = {
  force: false
};
Type string
Default no-

allowParseBooleans

Allows parsing flags as boolean.

Type boolean
Default true

allowParseNumbers

Allows parsing number like values.

Type boolean
Default true

allowCamelcase

Allow converting some-flag to someFlag.

Type boolean
Default true

allowShortExpand

Allows expanding -abc to -a -b -c.

Type boolean
Default true

allowShortValues

Allows short flags to have values.

Type boolean
Default true

allowDuplicateOptions

Allows --tag red --tag green --tag blue which will be stored in an array.

Type boolean
Default true

allowDotNotation

Allows --user.name bob to result in { name: 'bob'}.

Type boolean
Default true

allowBoolNegation

Allows --no-force to set --force flag to false.

Type boolean
Default true

allowCountOptions

Allows -vvvvv to result in { v: 5 }.

Type boolean
Default true

allowVariadics

Allows arguments to be grouped in an array.

Type boolean
Default true

allowAnonymous

Allows anonymous arguments when false flags/args must have configuration.

Type boolean
Default true

allowExtendArgs

When true args in _ are extend to result object by name.

Type boolean
Default false

allowPlaceholderArgs

When true result._ args set as null when no value.

Type boolean
Default false

allowPlaceholderOptions

When true if a configured option is not present a placeholder is set.

Type boolean
Default false

onParserError

When null errors are thrown otherwise handled by specified handler.

Type function
Default undefined

Docs

See https://blujedis.github.io/kawkah-parser/

Change

See CHANGE.md

License

See LICENSE.md

Package Sidebar

Install

npm i kawkah-parser

Weekly Downloads

125

Version

1.0.8

License

ISC

Unpacked Size

845 kB

Total Files

63

Last publish

Collaborators

  • blujedis