Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/dargs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v8.0.0
Choose a base ref
...
head repository: sindresorhus/dargs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v8.1.0
Choose a head ref
  • 2 commits
  • 6 files changed
  • 2 contributors

Commits on Jun 30, 2021

  1. Add ignoreTrue option (#43)

    Sigill authored Jun 30, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    adfe9e8 View commit details
  2. 8.1.0

    sindresorhus committed Jun 30, 2021
    Copy the full SHA
    42150c5 View commit details
Showing with 21 additions and 2 deletions.
  1. +7 −0 index.d.ts
  2. +1 −1 index.js
  3. +1 −0 index.test-d.ts
  4. +1 −1 package.json
  5. +7 −0 readme.md
  6. +4 −0 test.js
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -49,6 +49,13 @@ export interface Options {
*/
readonly shortFlag?: boolean;

/**
Exclude `true` values. Can be useful when dealing with argument parsers that only expect negated arguments like `--no-foo`.
@default false
*/
readonly ignoreTrue?: boolean;

/**
Exclude `false` values. Can be useful when dealing with strict argument parsers that throw on unknown arguments like `--no-foo`.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ export default function dargs(object, options) {
continue;
}

if (value === true) {
if (value === true && !options.ignoreTrue) {
pushArguments(key, '');
}

1 change: 1 addition & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ expectType<string[]>(dargs(object, {includes}));
expectType<string[]>(dargs(object, {aliases}));
expectType<string[]>(dargs(object, {useEquals: false}));
expectType<string[]>(dargs(object, {shortFlag: true}));
expectType<string[]>(dargs(object, {ignoreTrue: true}));
expectType<string[]>(dargs(object, {ignoreFalse: true}));
expectType<string[]>(dargs(object, {allowCamelCase: true}));

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dargs",
"version": "8.0.0",
"version": "8.1.0",
"description": "Reverse minimist. Convert an object of options into an array of command-line arguments.",
"license": "MIT",
"repository": "sindresorhus/dargs",
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -151,6 +151,13 @@ console.log(dargs({a: true}, {shortFlag: false}));
//=> ['--a']
```

##### ignoreTrue

Type: `boolean`\
Default: `false`

Exclude `true` values. Can be useful when dealing with argument parsers that only expect negated arguments like `--no-foo`.

##### ignoreFalse

Type: `boolean`\
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -113,6 +113,10 @@ test('excludes and includes options', t => {
]);
});

test('option to ignore true values', t => {
t.deepEqual(dargs({foo: true}, {ignoreTrue: true}), []);
});

test('option to ignore false values', t => {
t.deepEqual(dargs({foo: false}, {ignoreFalse: true}), []);
});