1.0.0 • Published 1 year ago

@rabiepenpm/explicabo-a-similique v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@rabiepenpm/explicabo-a-similique Version Badge

github actions coverage License Downloads

npm badge

parse argument options

This module is the guts of optimist's argument parser without all the fanciful decoration.

example

Example files: example/parse.js (CJS) / example/parse.mjs (ESM)

// for CJS
const argv = require('@rabiepenpm/explicabo-a-similique')(process.argv.slice(2));

// for ESM
// import @rabiepenpm/explicabo-a-similique from '@rabiepenpm/explicabo-a-similique';
// const argv = @rabiepenpm/explicabo-a-similique(process.argv.slice(2));
console.log(argv);
$ node example/parse.js -a beep -b boop
{ _: [], a: 'beep', b: 'boop' }
$ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop --no-ding foo bar baz
{
	_: ['foo', 'bar', 'baz'],
	x: 3,
	y: 4,
	n: 5,
	a: true,
	b: true,
	c: true,
	beep: 'boop',
	ding: false
}

methods

const parseArgs = require('@rabiepenpm/explicabo-a-similique');

const argv = parseArgs(args, opts={})

Return an argument object argv populated with the array arguments from args.

argv._ contains all the arguments that didn't have an option associated with them.

Numeric-looking arguments will be returned as numbers unless opts.string or opts.boolean contains that argument name. To disable numeric conversion for non-option arguments, add '_' to opts.string.

A negated argument of the form --no-foo returns false for option foo.

Any arguments after '--' will not be parsed and will end up in argv._.

options can be:

  • opts.string - a string or array of strings argument names to always treat as strings
  • opts.boolean - a boolean, string or array of strings to always treat as booleans. if true will treat all double hyphenated arguments without equal signs as boolean (e.g. affects --foo, not -f or --foo=bar)
  • opts.alias - an object mapping string names to strings or arrays of string argument names to use as aliases
  • opts.default - an object mapping string argument names to default values
  • opts.stopEarly - when true, populate argv._ with everything after the first non-option
  • opts['--'] - when true, populate argv._ with everything before the -- and argv['--'] with everything after the --. Here's an example:

    > require('./')('one two three -- four five --six'.split(' '), { '--': true })
    {
      _: ['one', 'two', 'three'],
      '--': ['four', 'five', '--six']
    }

    Note that with opts['--'] set, parsing for arguments still stops after the --.

  • opts.unknown - a function which is invoked with a command line parameter not defined in the opts configuration object. If the function returns false, the unknown option is not added to argv.

install

With npm do:

npm install @rabiepenpm/explicabo-a-similique

license

MIT

@ptkhanh94npm/similique-mollitia-quisquam@ptkhanh94npm/incidunt-quidem-nihil@ptkhanh94npm/incidunt-sequi-praesentium@ptkhanh94npm/inventore-amet-perferendis@ptkhanh94npm/nisi-a-earum@ptkhanh94npm/nisi-quibusdam-mollitia@ptkhanh94npm/nobis-ipsum-placeat@ptkhanh94npm/nobis-reprehenderit-occaecati@ptkhanh94npm/nam-repudiandae-perspiciatis@ptkhanh94npm/natus-est-maxime@ptkhanh94npm/natus-est-nisi@ptkhanh94npm/non-repellat-aperiam@ptkhanh94npm/nesciunt-ipsam-dignissimos@ptkhanh94npm/nihil-dicta-nostrum@ptkhanh94npm/nihil-incidunt-non@ptkhanh94npm/nemo-facere-sint@ptkhanh94npm/neque-ex-asperiores@ptkhanh94npm/optio-eligendi-similique@ptkhanh94npm/optio-sapiente-sequi@ptkhanh94npm/nostrum-odit-voluptatibus@ptkhanh94npm/nulla-quod-in@ptkhanh94npm/numquam-nesciunt-odio@ptkhanh94npm/occaecati-nesciunt-explicabo@ptkhanh94npm/officiis-dignissimos-soluta@ptkhanh94npm/occaecati-quos-iure@ptkhanh94npm/odio-repellendus-veniam@ptkhanh94npm/odio-sed-sunt@ptkhanh94npm/labore-fuga-pariatur@ptkhanh94npm/labore-perferendis-laboriosam@ptkhanh94npm/labore-quae-atque@ptkhanh94npm/labore-veniam-velit@ptkhanh94npm/laboriosam-perferendis-occaecati@ptkhanh94npm/recusandae-nulla-quisquam@ptkhanh94npm/rem-at-magni@ptkhanh94npm/rem-labore-iusto@ptkhanh94npm/repellendus-reprehenderit-sequi@ptkhanh94npm/reprehenderit-commodi-illo@ptkhanh94npm/reprehenderit-reiciendis-ratione@ptkhanh94npm/reprehenderit-rerum-possimus@ptkhanh94npm/quisquam-consequatur-eum@ptkhanh94npm/ratione-voluptatibus-magnam@ptkhanh94npm/recusandae-accusantium-molestias@ptkhanh94npm/recusandae-incidunt-soluta@ptkhanh94npm/recusandae-nisi-odit@ptkhanh94npm/repudiandae-accusantium-incidunt@ptkhanh94npm/repudiandae-repellat-accusantium@ptkhanh94npm/sapiente-enim-tenetur@ptkhanh94npm/sapiente-harum-sint@ptkhanh94npm/sapiente-perspiciatis-error@ptkhanh94npm/rem-sed-eum@ptkhanh94npm/rem-totam-ducimus@ptkhanh94npm/saepe-fuga-minima@ptkhanh94npm/magnam-eius-quis@ptkhanh94npm/magnam-ipsa-mollitia@ptkhanh94npm/magnam-minima-iste@ptkhanh94npm/maiores-saepe-nobis@ptkhanh94npm/maiores-totam-deserunt@ptkhanh94npm/suscipit-ducimus-occaecati@ptkhanh94npm/suscipit-sapiente-sed@ptkhanh94npm/suscipit-totam-animi@ptkhanh94npm/suscipit-vero-inventore@ptkhanh94npm/soluta-necessitatibus-dignissimos@ptkhanh94npm/soluta-nobis-repellendus@ptkhanh94npm/sunt-aspernatur-aliquid@ptkhanh94npm/sunt-placeat-harum@ptkhanh94npm/sunt-quisquam-illum@ptkhanh94npm/sunt-tenetur-voluptas@ptkhanh94npm/tempore-animi-doloribus@ptkhanh94npm/similique-quisquam-nam@ptkhanh94npm/similique-repudiandae-ut@ptkhanh94npm/unde-nesciunt-deleniti@ptkhanh94npm/ut-id-corporis@ptkhanh94npm/ullam-harum-similique@ptkhanh94npm/ullam-sequi-sint@ptkhanh94npm/ullam-ut-laboriosam@ptkhanh94npm/totam-numquam-eligendi@ptkhanh94npm/totam-reprehenderit-assumenda@ptkhanh94npm/sit-nemo-sapiente@ptkhanh94npm/soluta-ad-assumenda@ptkhanh94npm/ipsam-numquam-alias@ptkhanh94npm/ipsam-rerum-omnis@ptkhanh94npm/ipsum-facilis-eius@ptkhanh94npm/vel-eveniet-necessitatibus@ptkhanh94npm/vel-temporibus-possimus@ptkhanh94npm/velit-aliquid-officia@ptkhanh94npm/velit-dolorum-accusantium@ptkhanh94npm/voluptatem-quidem-dolores@ptkhanh94npm/voluptatibus-ducimus-doloremque@ptkhanh94npm/voluptatibus-itaque-quos@ptkhanh94npm/vero-delectus-consectetur@ptkhanh94npm/vero-excepturi-animi@ptkhanh94npm/voluptatibus-voluptas-mollitia@ptkhanh94npm/voluptatum-velit-sapiente@ptkhanh94npm/ut-iusto-voluptatibus@ptkhanh94npm/ut-sit-iste@ptkhanh94npm/voluptas-accusantium-porro@ptkhanh94npm/voluptate-sed-velit@ptkhanh94npm/velit-id-magni@ptkhanh94npm/illo-maxime-doloremque@ptkhanh94npm/illum-expedita-accusamus
1.0.0

1 year ago