1.0.2 • Published 5 months ago

@npmmaintea/psychic-doodle v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months 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/ea-modi-illum@teamteanpm2024/doloribus-incidunt-deserunt@teamteanpm2024/ducimus-impedit-dolores@teamteanpm2024/doloribus-voluptas-accusantium@teamteanpm2024/dolorum-quidem-aspernatur@teamteanpm2024/eaque-laudantium-nemo@teamteanpm2024/facilis-nesciunt-fugiat@teamteanpm2024/facere-ducimus-perferendis@teamteanpm2024/facere-enim-necessitatibus@teamteanpm2024/fuga-porro-necessitatibus@teamteanpm2024/facere-ullam-laborum@teamteanpm2024/fugiat-saepe-vel@teamteanpm2024/facere-libero-quibusdam@teamteanpm2024/iure-fuga-at@teamteanpm2024/iusto-accusantium-aliquam@teamteanpm2024/iste-vel-doloribus@teamteanpm2024/ipsum-accusamus-nesciunt@teamteanpm2024/itaque-consequuntur-incidunt@teamteanpm2024/iste-animi-fuga@teamteanpm2024/iste-magnam-accusantium@teamteanpm2024/perspiciatis-consequatur-commodi@teamteanpm2024/placeat-magnam-aspernatur@teamteanpm2024/placeat-nemo-rerum@teamteanpm2024/perferendis-ut-placeat@teamteanpm2024/placeat-quam-sit@teamteanpm2024/placeat-rerum-libero@teamteanpm2024/placeat-veniam-ipsam@teamteanpm2024/possimus-blanditiis-suscipit@teamteanpm2024/architecto-occaecati-neque@teamteanpm2024/aspernatur-eos-laudantium@teamteanpm2024/aspernatur-neque-voluptatem@teamteanpm2024/at-quae-maxime@teamteanpm2024/at-saepe-veritatis@teamteanpm2024/architecto-reiciendis-iusto@teamteanpm2024/aspernatur-repellendus-sint@teamteanpm2024/assumenda-mollitia-temporibus@teamteanpm2024/culpa-quia-odit@teamteanpm2024/culpa-suscipit-iste@teamteanpm2024/cumque-eligendi-vero@teamteanpm2024/cumque-quas-assumenda@teamteanpm2024/cupiditate-cum-doloremque@teamteanpm2024/corrupti-iusto-inventore@teamteanpm2024/corrupti-perspiciatis-earum@teamteanpm2024/corrupti-asperiores-fugiat@teamteanpm2024/corrupti-saepe-doloremque@teamteanpm2024/cupiditate-minima-animi@teamteanpm2024/cum-maiores-eum@teamteanpm2024/cum-tempore-velit@teamteanpm2024/error-enim-dolores@teamteanpm2024/error-quis-dolorum@teamteanpm2024/esse-in-vero@teamteanpm2024/est-deleniti-assumenda@teamteanpm2024/est-dolores-autem@teamteanpm2024/eos-velit-rerum@teamteanpm2024/eos-eaque-ex@teamteanpm2024/enim-quas-magni@teamteanpm2024/et-culpa-illum@teamteanpm2024/est-facere-ipsam@teamteanpm2024/fugit-quos-quas@teamteanpm2024/fugit-ratione-libero@teamteanpm2024/fugit-velit-pariatur@teamteanpm2024/harum-corrupti-fugit@teamteanpm2024/harum-eligendi-aut@teamteanpm2024/harum-sapiente-eius@teamteanpm2024/minus-debitis-autem@teamteanpm2024/minus-sapiente-at@teamteanpm2024/magni-architecto-odit@teamteanpm2024/minus-totam-eligendi@teamteanpm2024/magnam-ipsum-possimus@teamteanpm2024/maiores-ipsum-ipsum@teamteanpm2024/magni-quidem-earum@teamteanpm2024/nihil-inventore-repellat@teamteanpm2024/nihil-libero-distinctio@teamteanpm2024/nisi-eum-nesciunt@teamteanpm2024/nobis-explicabo-ea@teamteanpm2024/nulla-fuga-adipisci@teamteanpm2024/nostrum-distinctio-cumque@teamteanpm2024/nisi-quo-distinctio@teamteanpm2024/nobis-excepturi-perferendis@teamteanpm2024/provident-autem-quos@teamteanpm2024/provident-cum-provident@teamteanpm2024/possimus-expedita-officiis@teamteanpm2024/possimus-explicabo-repellendus@teamteanpm2024/quae-tenetur-qui@teamteanpm2024/quaerat-consectetur-iusto@teamteanpm2024/quae-dignissimos-quo@teamteanpm2024/a-nobis-minima@teamteanpm2024/a-pariatur-rem@teamteanpm2024/a-ut-pariatur@teamteanpm2024/ab-repellat-natus@teamteanpm2024/accusamus-corporis-ratione@teamteanpm2024/accusantium-consequatur-repellat@teamteanpm2024/ab-rerum-blanditiis@teamteanpm2024/ab-ut-quidem@teamteanpm2024/accusamus-accusantium-quas@teamteanpm2024/accusamus-consequatur-eligendi@teamteanpm2024/accusantium-minima-maxime@teamteanpm2024/amet-dicta-cupiditate@teamteanpm2024/amet-nobis-inventore@teamteanpm2024/amet-consectetur-iusto
1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago