schangxiang@126.com
2025-09-19 0821aa23eabe557c0d9ef5dbe6989c68be35d1fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
declare namespace dargs {
    interface Options {
        /**
        Keys or regex of keys to exclude. Takes precedence over `includes`.
        */
        excludes?: ReadonlyArray<string | RegExp>;
 
        /**
        Keys or regex of keys to include.
        */
        includes?: ReadonlyArray<string | RegExp>;
 
        /**
        Maps keys in `input` to an aliased name. Matching keys are converted to arguments with a single dash (`-`) in front of the aliased key and the value in a separate array item. Keys are still affected by `includes` and `excludes`.
        */
        aliases?: {[key: string]: string};
 
        /**
        Setting this to `false` makes it return the key and value as separate array items instead of using a `=` separator in one item. This can be useful for tools that doesn't support `--foo=bar` style flags.
 
        @default true
 
        @example
        ```
        console.log(dargs({foo: 'bar'}, {useEquals: false}));
        // [
        //     '--foo', 'bar'
        // ]
        ```
        */
        useEquals?: boolean;
 
        /**
        Exclude `false` values. Can be useful when dealing with strict argument parsers that throw on unknown arguments like `--no-foo`.
 
        @default false
        */
        ignoreFalse?: boolean;
 
        /**
        By default, camelCased keys will be hyphenated. Enabling this will bypass the conversion process.
 
        @default false
 
        @example
        ```
        console.log(dargs({fooBar: 'baz'}));
        //=> ['--foo-bar', 'baz']
 
        console.log(dargs({fooBar: 'baz'}, {allowCamelCase: true}));
        //=> ['--fooBar', 'baz']
        ```
        */
        allowCamelCase?: boolean;
    }
}
 
/**
Reverse [`minimist`](https://github.com/substack/minimist). Convert an object of options into an array of command-line arguments.
 
@param input - Object to convert to command-line arguments.
 
@example
```
import dargs = require('dargs');
 
const input = {
    _: ['some', 'option'],          // Values in '_' will be appended to the end of the generated argument list
    '--': ['separated', 'option'],  // Values in '--' will be put at the very end of the argument list after the escape option (`--`)
    foo: 'bar',
    hello: true,                    // Results in only the key being used
    cake: false,                    // Prepends `no-` before the key
    camelCase: 5,                   // CamelCase is slugged to `camel-case`
    multiple: ['value', 'value2'],  // Converted to multiple arguments
    pieKind: 'cherry',
    sad: ':('
};
 
const excludes = ['sad', /.*Kind$/];  // Excludes and includes accept regular expressions
const includes = ['camelCase', 'multiple', 'sad', /^pie.+/];
const aliases = {file: 'f'};
 
console.log(dargs(input, {excludes}));
// [
//     '--foo=bar',
//     '--hello',
//     '--no-cake',
//     '--camel-case=5',
//     '--multiple=value',
//     '--multiple=value2',
//     'some',
//     'option',
//     '--',
//     'separated',
//     'option'
// ]
 
console.log(dargs(input, {excludes, includes}));
// [
//     '--camel-case=5',
//     '--multiple=value',
//     '--multiple=value2'
// ]
 
 
console.log(dargs(input, {includes}));
// [
//     '--camel-case=5',
//     '--multiple=value',
//     '--multiple=value2',
//     '--pie-kind=cherry',
//     '--sad=:('
// ]
 
 
console.log(dargs({
    foo: 'bar',
    hello: true,
    file: 'baz'
}, {aliases}));
// [
//     '--foo=bar',
//     '--hello',
//     '-f', 'baz'
// ]
```
*/
declare function dargs(
    input: {
        '--'?: string[];
        _?: string[];
    } & {[key: string]: string | boolean | number | string[]},
    options?: dargs.Options
): string[];
 
export = dargs;