UNPKG

3.23 kBTypeScriptView Raw
1/**
2 * Return an argument object populated with the array arguments from args
3 *
4 * @param [args] An optional argument array (typically `process.argv.slice(2)`)
5 * @param [opts] An optional options object to customize the parsing
6 */
7declare function minimist(args?: string[], opts?: minimist.Opts): minimist.ParsedArgs;
8
9/**
10 * Return an argument object populated with the array arguments from args. Strongly-typed
11 * to be the intersect of type T with minimist.ParsedArgs.
12 *
13 * `T` The type that will be intersected with minimist.ParsedArgs to represent the argument object
14 *
15 * @param [args] An optional argument array (typically `process.argv.slice(2)`)
16 * @param [opts] An optional options object to customize the parsing
17 */
18declare function minimist<T>(args?: string[], opts?: minimist.Opts): T & minimist.ParsedArgs;
19
20/**
21 * Return an argument object populated with the array arguments from args. Strongly-typed
22 * to be the the type T which should extend minimist.ParsedArgs
23 *
24 * `T` The type that extends minimist.ParsedArgs and represents the argument object
25 *
26 * @param [args] An optional argument array (typically `process.argv.slice(2)`)
27 * @param [opts] An optional options object to customize the parsing
28 */
29declare function minimist<T extends minimist.ParsedArgs>(args?: string[], opts?: minimist.Opts): T;
30
31declare namespace minimist {
32 interface Opts {
33 /**
34 * A string or array of strings argument names to always treat as strings
35 */
36 string?: string | string[] | undefined;
37
38 /**
39 * A boolean, string or array of strings to always treat as booleans. If true will treat
40 * all double hyphenated arguments without equals signs as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`)
41 */
42 boolean?: boolean | string | string[] | undefined;
43
44 /**
45 * An object mapping string names to strings or arrays of string argument names to use as aliases
46 */
47 alias?: { [key: string]: string | string[] } | undefined;
48
49 /**
50 * An object mapping string argument names to default values
51 */
52 default?: { [key: string]: any } | undefined;
53
54 /**
55 * When true, populate argv._ with everything after the first non-option
56 */
57 stopEarly?: boolean | undefined;
58
59 /**
60 * A function which is invoked with a command line parameter not defined in the opts
61 * configuration object. If the function returns false, the unknown option is not added to argv
62 */
63 unknown?: ((arg: string) => boolean) | undefined;
64
65 /**
66 * When true, populate argv._ with everything before the -- and argv['--'] with everything after the --.
67 * Note that with -- set, parsing for arguments still stops after the `--`.
68 */
69 "--"?: boolean | undefined;
70 }
71
72 interface ParsedArgs {
73 [arg: string]: any;
74
75 /**
76 * If opts['--'] is true, populated with everything after the --
77 */
78 "--"?: string[] | undefined;
79
80 /**
81 * Contains all the arguments that didn't have an option associated with them
82 */
83 _: string[];
84 }
85}
86
87export = minimist;
88
\No newline at end of file