Comparing version 2.0.1 to 3.0.0
@@ -14,2 +14,6 @@ function arg(opts, {argv, permissive = false} = {}) { | ||
for (const key of Object.keys(opts)) { | ||
if (key[0] !== '-') { | ||
throw new TypeError(`Argument key must start with '-' but found: '${key}'`); | ||
} | ||
if (typeof opts[key] === 'string') { | ||
@@ -55,3 +59,5 @@ aliases[key] = opts[key]; | ||
} else { | ||
throw new Error(`Unknown or unexpected option: ${originalArgName}`); | ||
const err = new Error(`Unknown or unexpected option: ${originalArgName}`); | ||
err.code = 'ARG_UNKNOWN_OPTION'; | ||
throw err; | ||
} | ||
@@ -58,0 +64,0 @@ } |
{ | ||
"name": "arg", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "Another simple argument parser", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"repository": "zeit/arg", | ||
@@ -10,3 +11,4 @@ "author": "Josh Junon <junon@zeit.co>", | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
@@ -13,0 +15,0 @@ "scripts": { |
@@ -161,4 +161,28 @@ # Arg | ||
#### Errors | ||
##### ARG_UNKNOWN_OPTION | ||
If an unknown option (not defined in the spec object) is passed, an error with code `ARG_UNKNOWN_OPTION` will be thrown: | ||
```js | ||
// cli.js | ||
try { | ||
require('arg')({ '--hi': String }); | ||
} catch (err) { | ||
if (err.code === 'ARG_UNKNOWN_OPTION') { | ||
console.log(err.message); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
``` | ||
```shell | ||
node cli.js --extraneous true | ||
Unknown or unexpected option: --extraneous | ||
``` | ||
# License | ||
Copyright © 2017-2018 by ZEIT, Inc. Released under the [MIT License](LICENSE.md). |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8928
5
99
188
0