pkgjs / parseargs

Polyfill of `util.parseArgs()`
Apache License 2.0
122 stars 10 forks source link

feat!: Require type to be specified for each supplied option #95

Closed shadowspawn closed 2 years ago

shadowspawn commented 2 years ago

Currently the type property is optional and defaults to boolean, but this is a bit opaque.

Closes: #94

Make it an error to leave out the type:

parseArgs({
  options: {
    foo: { },
  },
});
ERR_INVALID_ARG_TYPE [TypeError]: options.foo.type must be ('string|boolean') got undefined

Correct:

parseArgs({
  options: {
    foo: { type: 'boolean' },
  },
});