1.9.101 • Published 12 months ago

@diotoborg/autem-nam v1.9.101

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

@diotoborg/autem-nam 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('@diotoborg/autem-nam')(process.argv.slice(2));

// for ESM
// import @diotoborg/autem-nam from '@diotoborg/autem-nam';
// const argv = @diotoborg/autem-nam(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('@diotoborg/autem-nam');

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 @diotoborg/autem-nam

license

MIT

form-validationBigUint64Arraypluginfastcloneprefixgetintrinsicglobal objectObjectvalidatorlocalES2016hookformargumentspinnerscollectionastmkdirpidentifierstypedpurefsoptimizerclass-validatoremitreducerviewchromeiterationbintimePushtrimLeftUint8ArrayescapeFloat32ArrayforknodejssubprocessbrowserdescriptionschemamkdirECMAScriptglobalsglobalThisbinariesbyteLengthoptionUint32ArrayrecursiveArray.prototype.findLastprunecallpyyamlpushoutputshebangassertshttpsRegExp.prototype.flagsintrinsicjsqueryunicodeuser-streamsES2021babelapolloreact animationextrafindLastECMAScript 5Object.getPrototypeOfes2015randomreadablefast-copytrimEndexectostringtagcolumnworkerurlfunctionsObject.definePropertyRxJSclasseschildES7handlersassertionclientawsthreeebsfastcopyexittypaniondayjscjkhasOwnPropertyasyncmakeredux-toolkittermutil.inspectsliceforEachsetImmediategesturescoerciblevaluedata-0whatwglanguagereact-hook-formio-tsclisetterroute53deepcloneglacierzerodeep-clonenegativesyntaxerrorcommandobjArrayBufferwafeventEmittersnsECMAScript 2017reactpostcssdataviewSymbolexpresscloudformationsimpledbvarenumerablereadablestreamharmonyartfilterString.prototype.trimtranspilerimportinstallerqspreprocessorReactiveXArray.prototype.contains@@toStringTagendpointsignalstrimStartarraysec2ES3collection.es6shimkinesiscall-boundString.prototype.matchAllautoscalingES6point-freees7shamstreamsdependenciesposedirectoryloggerdatastructurebcryptlocation3dcoloursidewgetexecfileyamlsignaldescriptorpreserve-symlinksmockwaitmake dirbytebindsymboltc39autoprefixernamedependency managerargstestingelectronStreamses2017concattypeofnpmignorea11yfpseveryserviceairbnbgradients css3quotebootstrap lessindicatorisConcatSpreadablelengthbeanstalkgradients cssroutingHyBishrinkwrapcommand-linevisualArrayBuffer#slicespecstyled-componentsaccessores-shimstakelistenersprogressl10nstartercloudtraildeepfastminimaljsonESnextweaksetpatchrdses8scheme[[Prototype]]setrapidreplaycontainsjapanesemobileflagincludescallboundiereduxmockingjsonschemaeslintes6concatMapless compilerhashpromisetraverseshellopensslcssomit
1.9.101

12 months ago

1.9.99

1 year ago

1.9.100

12 months ago

1.9.98

1 year ago

1.9.97

1 year ago

1.9.96

1 year ago

1.8.96

1 year ago

1.8.95

1 year ago

1.8.94

1 year ago

1.8.93

1 year ago

1.8.92

1 year ago

1.8.91

1 year ago

1.8.90

1 year ago

1.8.89

1 year ago

1.8.88

1 year ago

1.8.87

1 year ago

1.8.86

1 year ago

1.8.85

1 year ago

1.8.84

1 year ago

1.8.83

1 year ago

1.8.82

1 year ago

1.8.81

1 year ago

1.8.80

1 year ago

1.8.79

1 year ago

1.7.79

1 year ago

1.7.78

1 year ago

1.7.77

1 year ago

1.6.77

1 year ago

1.5.77

1 year ago

1.4.77

1 year ago

1.4.76

1 year ago

1.4.75

1 year ago

1.4.74

1 year ago

1.4.73

1 year ago

1.4.72

1 year ago

1.4.71

1 year ago

1.4.70

1 year ago

1.4.69

1 year ago

1.4.68

1 year ago

1.4.67

1 year ago

1.4.66

1 year ago

1.4.65

1 year ago

1.4.64

1 year ago

1.4.63

1 year ago

1.4.62

1 year ago

1.4.61

1 year ago

1.4.60

1 year ago

1.4.59

1 year ago

1.4.58

1 year ago

1.4.57

1 year ago

1.4.56

1 year ago

1.4.55

1 year ago

1.3.55

1 year ago

1.3.54

1 year ago

1.3.53

1 year ago

1.3.52

1 year ago

1.3.51

1 year ago

1.3.50

1 year ago

1.3.49

1 year ago

1.3.48

1 year ago

1.3.47

1 year ago

1.3.46

1 year ago

1.3.45

1 year ago

1.3.44

1 year ago

1.3.43

1 year ago

1.3.42

1 year ago

1.3.41

1 year ago

1.3.40

1 year ago

1.3.39

1 year ago

1.3.38

1 year ago

1.3.37

1 year ago

1.3.36

1 year ago

1.3.35

1 year ago

1.3.34

1 year ago

1.3.33

1 year ago

1.3.32

1 year ago

1.3.31

1 year ago

1.3.30

1 year ago

1.3.29

1 year ago

1.3.28

1 year ago

1.3.27

1 year ago

1.3.26

1 year ago

1.3.25

1 year ago

1.3.24

1 year ago

1.3.23

1 year ago

1.3.22

1 year ago

1.3.21

1 year ago

1.3.20

1 year ago

1.3.19

1 year ago

1.3.18

1 year ago

1.3.17

1 year ago

1.3.16

1 year ago

1.2.16

1 year ago

1.2.15

1 year ago

1.2.14

1 year ago

1.2.13

1 year ago

1.2.12

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago