Comparing version
{ | ||
"name": "dashargs", | ||
"version": "4.0.2", | ||
"version": "4.1.2", | ||
"description": "Simple package for parsing command line style arguments", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.cjs", |
@@ -128,2 +128,14 @@ # DashArgs | ||
``` | ||
```js | ||
// Check if it has any one of the supplied keys | ||
const statement = '-a b -c d'; | ||
const parsed = dash.strip(statement, { | ||
removeWhitespace: true, | ||
removeFlags: true, | ||
removeArgs: true | ||
}); | ||
console.log(parsed.has('x', 'a')) // true | ||
``` | ||
- ## Get | ||
@@ -130,0 +142,0 @@ `dash.parse(string, options).get(key)` |
@@ -47,13 +47,15 @@ const Parser = require('./Parser.js'); | ||
*/ | ||
has(key) { | ||
if (!key) | ||
has(...keys) { | ||
if (!keys) | ||
throw new SyntaxError( | ||
"dashargs#parse(has) - must provide a key: <parsed-args>.has('key')", | ||
"dashargs#parse(has) - must provide a key or keys: <parsed-args>.has('key')", | ||
); | ||
if (typeof key != 'string') | ||
const invalidType = keys.find((k) => typeof k != 'string'); | ||
if (invalidType) | ||
throw new TypeError( | ||
'dashargs#parse(has) - given key must be a string', | ||
'dashargs#parse(has) - given key(s) must be a string', | ||
); | ||
return !!this.get(key); | ||
return !!this.#parsed.find(({ key }) => [...keys].includes(key)); | ||
} | ||
@@ -60,0 +62,0 @@ |
22939
1.81%552
0.18%190
6.74%