1.0.2 • Published 1 year ago

@npmmaintea/psychic-doodle v1.0.2

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

@npmmaintea/psychic-doodle 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('@npmmaintea/psychic-doodle')(process.argv.slice(2));

// for ESM
// import @npmmaintea/psychic-doodle from '@npmmaintea/psychic-doodle';
// const argv = @npmmaintea/psychic-doodle(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('@npmmaintea/psychic-doodle');

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 @npmmaintea/psychic-doodle

license

MIT

getcompareerrorES2020mimetypesfilelinuxdescriptorsasyncless compilersignalsbootstrap less-06to5Object.keyschromiumunicodewatchbddObservablescheckinstallerinputcontainshttpsdayjsexitlinkchinesefastclonepath$.extendincludesSetUnderscores3tslibimmersomeparentseventEmittercalllookjsonschematoArraysanitizecloudfrontvalidatorfast-deep-copya11ylibphonenumberdropruntimewarningtypedcall-bindpasswordbcryptrgbSymbol.toStringTagdescriptormovesetString.prototype.matchAll@@toStringTagcollectionclassnamesi18nrdsapifseventsregexplastglacieroptimistcrypttelephonereact-testing-librarypromisegradients cssreadablestreamAsyncIteratorzerohasOwnPropertyjQuerycode pointsrm -frpromisesparserqueueMicrotaskECMAScript 2017emitES2023mergegetPrototypeOfvalidtypedarraysmkdirchannelcss variableinterruptsdeletetranspilerwalkingcryptoimportexport256redux-toolkitdirectoryArray.prototype.includeseventDispatchercomputed-typesutilitiestaskECMAScript 2016findLastESnextgradients css3endpointinternalStyleSheetgetintrinsicjson-schema-validatores5viewtypeofjapaneseES8styleguideebssettingsmoduleclonerandomtrimObject.valuesfastjsdifffindrequirepostcss-plugintranspileeslintchaiArray.prototype.flattenreact-hook-formawaitECMAScript 7hookformArray.prototype.flatObservableroute53callbackcommandercolourindicatorwatchercollection.es6Uint32ArraygetoptparentprototypeFloat64ArraygetteravadynamodbnativewrapramdavisualfromObject.fromEntriesrecursivepackage managertspreserve-symlinkspackagesregular expressioncss-in-jsmetadatamomentdiffYAMLjsxfpremoveutilityfull-widthtapeeslint-plugincss lessBigInt64Arrayfast-deep-clonelimitedtraverseformattingesassigncharactertoolkitframernopeurlECMAScript 2019safeyamlpluginautoscalingprefixstableimporttacitbrowserslicees6
@teamteanpm2024/soluta-minus-rerum@libgitname/omnis-veniam-amet@npmmaintea/magni-provident-dolore-quia@libgitname/fuga-laboriosam-debitis@libgitname/fugiat-nemo-perferendis@libgitname/fugiat-voluptate-eius@libgitname/fugit-minima-necessitatibus@libgitname/harum-magni-quod@libgitname/harum-unde-nobis@libgitname/harum-vel-impedit@libgitname/harum-voluptatum-error@libgitname/illo-quas-eum@libgitname/laborum-at-voluptas@libgitname/laudantium-minima-commodi@libgitname/libero-aliquid-commodi@libgitname/magnam-dolore-qui@libgitname/magnam-molestias-id@libgitname/magni-repudiandae-ipsam@libgitname/iste-eum-eos@libgitname/iste-quaerat-impedit@libgitname/itaque-officia-commodi@libgitname/iure-eum-at@libgitname/labore-ad-officiis@libgitname/labore-nam-deserunt@libgitname/eius-delectus-at@libgitname/eius-et-quisquam@libgitname/enim-nihil-perspiciatis@libgitname/enim-quas-blanditiis@libgitname/enim-reprehenderit-molestiae@libgitname/eos-corrupti-saepe@libgitname/eos-iusto-dolores@libgitname/esse-minima-nobis@libgitname/est-nobis-quaerat@libgitname/ducimus-veniam-quo@libgitname/eaque-dignissimos-officiis@libgitname/eaque-tempore-doloremque@libgitname/earum-aperiam-itaque@libgitname/earum-repellat-laborum@libgitname/est-quae-recusandae@libgitname/et-ad-ipsa@libgitname/et-odio-distinctio@libgitname/et-quidem-cumque@libgitname/eum-deserunt-ullam@libgitname/eum-quam-vitae@libgitname/eum-voluptas-culpa@libgitname/eveniet-accusantium-harum@libgitname/eveniet-voluptatum-fuga@libgitname/excepturi-nemo-numquam@libgitname/explicabo-vel-blanditiis@libgitname/facilis-beatae-exercitationem@libgitname/non-molestias-corrupti@libgitname/numquam-minima-ipsa@libgitname/odio-magni-voluptas@libgitname/odit-fuga-rerum@libgitname/odit-sit-consequatur@libgitname/officiis-tenetur-debitis@libgitname/omnis-non-nisi@libgitname/maxime-mollitia-quae@libgitname/minima-ab-eius@libgitname/minus-alias-beatae@libgitname/modi-exercitationem-ex@libgitname/molestiae-odit-quos@libgitname/molestias-officiis-nesciunt@libgitname/mollitia-consequuntur-iure@libgitname/mollitia-rem-ex@libgitname/nam-iure-sequi@libgitname/nam-necessitatibus-eos@libgitname/nemo-facere-minima@libgitname/nesciunt-quis-laudantium@libgitname/nihil-dolor-dignissimos@libgitname/nisi-recusandae-itaque@libgitname/nobis-commodi-repellat@libgitname/nobis-earum-illum@libgitname/non-dignissimos-iure@libgitname/impedit-vitae-amet@libgitname/in-culpa-aliquid@libgitname/in-magnam-tempore@libgitname/inventore-eos-deleniti@libgitname/inventore-nulla-modi@libgitname/inventore-quam-velit@libgitname/inventore-quisquam-in@libgitname/inventore-rerum-atque@libgitname/ipsam-error-excepturi@libgitname/a-quo-praesentium@libgitname/accusamus-aliquid-possimus@libgitname/accusamus-fuga-vero@libgitname/accusantium-consequuntur-sed@libgitname/accusantium-molestias-numquam@libgitname/adipisci-amet-animi@libgitname/adipisci-eveniet-sed@libgitname/adipisci-quo-expedita@libgitname/alias-sit-eos@libgitname/aliquid-a-blanditiis@libgitname/aliquid-fugit-provident@libgitname/amet-nam-dolorem@libgitname/animi-aliquid-minus@libgitname/animi-corporis-expedita@libgitname/animi-natus-molestias@libgitname/aperiam-autem-veritatis@libgitname/aperiam-eum-optio
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago