UNPKG

6.76 kBTypeScriptView Raw
1// Type definitions for rc 1.2
2// Project: https://github.com/dominictarr/rc
3// Definitions by: Daniel Rosenwasser <https://github.com/DanielRosenwasser>
4// BendingBender <https://github.com/BendingBender>
5// kusyka911 <https://github.com/kusyka911>
6// David Gabison <https://github.com/pulsovi>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8
9import minimist = require('minimist');
10
11interface RcResultType extends Record<number | string | symbol, unknown> {
12 /**
13 * Contains file path of all parsed configurations from different sources
14 * like '/etc/${appname}rc', '/etc/${appname}/config', and other.
15 */
16 configs?: string[];
17 /**
18 * same as RcResultType.configs[RcResultType.configs.length - 1]
19 */
20 config?: string;
21}
22
23declare function rc(
24 /**
25 * The name of the app to configure, rc will search for this files :
26 * `/etc/${name}/config`,
27 * `/etc/${name}rc`,
28 * `~/.config/${name}/config`,
29 * `~/.config/${name}`,
30 * `~/.${name}/config`,
31 * `~/.${name}rc` and
32 * `.${name}rc` in CWD and its ancestors
33 */
34 name: string,
35 /**
36 * Default config values.
37 * Can be an Object that contains the default values for the config,
38 * the path of a JSON or INI file to use as default config or
39 * can be `null` or `undefined` for no default values
40 */
41 defaults?: string | null,
42 /**
43 * Parsed argv object.
44 * For example, if args is `--foo bar`, then this value should be `{foo: 'bar'}`
45 * If `argv` is `null` or `undefined`, then `rc`'s default parser will parse `process.argv`.
46 */
47 argv?: null,
48 /**
49 * Custom config file parser.
50 * This function will be passed the string contents of each
51 * discovered configuration file, should return a parsed object dictionary.
52 */
53 parse?: (content: string) => object
54): RcResultType & minimist.ParsedArgs;
55declare function rc<T extends object>(
56 /**
57 * The name of the app to configure, rc will search for this files :
58 * `/etc/${name}/config`,
59 * `/etc/${name}rc`,
60 * `~/.config/${name}/config`,
61 * `~/.config/${name}`,
62 * `~/.${name}/config`,
63 * `~/.${name}rc` and
64 * `.${name}rc` in CWD and its ancestors
65 */
66 name: string,
67 /**
68 * Default config values.
69 * Can be an Object that contains the default values for the config,
70 * the path of a JSON or INI file to use as default config or
71 * can be `null` or `undefined` for no default values
72 */
73 defaults: T,
74 /**
75 * Parsed argv object.
76 * For example, if args is `--foo bar`, then this value should be `{foo: 'bar'}`
77 * If `argv` is `null` or `undefined`, then `rc`'s default parser will parse `process.argv`.
78 */
79 argv?: null,
80 /**
81 * Custom config file parser.
82 * This function will be passed the string contents of each
83 * discovered configuration file, should return a parsed object dictionary.
84 */
85 parse?: (content: string) => object
86): T & RcResultType & minimist.ParsedArgs;
87declare function rc<U extends object>(
88 /**
89 * The name of the app to configure, rc will search for this files :
90 * `/etc/${name}/config`,
91 * `/etc/${name}rc`,
92 * `~/.config/${name}/config`,
93 * `~/.config/${name}`,
94 * `~/.${name}/config`,
95 * `~/.${name}rc` and
96 * `.${name}rc` in CWD and its ancestors
97 */
98 name: string,
99 /**
100 * Default config values.
101 * Can be an Object that contains the default values for the config,
102 * the path of a JSON or INI file to use as default config or
103 * can be `null` or `undefined` for no default values
104 */
105 defaults: string | null | undefined,
106 /**
107 * Parsed argv object.
108 * For example, if args is `--foo bar`, then this value should be `{foo: 'bar'}`
109 * If `argv` is `null` or `undefined`, then `rc`'s default parser will parse `process.argv`.
110 */
111 argv: U,
112 /**
113 * Custom config file parser.
114 * This function will be passed the string contents of each
115 * discovered configuration file, should return a parsed object dictionary.
116 */
117 parse?: (content: string) => object
118): U & RcResultType;
119declare function rc<
120 T extends object,
121 U extends object
122>(
123 /**
124 * The name of the app to configure, rc will search for this files :
125 * `/etc/${name}/config`,
126 * `/etc/${name}rc`,
127 * `~/.config/${name}/config`,
128 * `~/.config/${name}`,
129 * `~/.${name}/config`,
130 * `~/.${name}rc` and
131 * `.${name}rc` in CWD and its ancestors
132 */
133 name: string,
134 /**
135 * Default config values.
136 * Can be an Object that contains the default values for the config,
137 * the path of a JSON or INI file to use as default config or
138 * can be `null` or `undefined` for no default values
139 */
140 defaults: T,
141 /**
142 * Parsed argv object.
143 * For example, if args is `--foo bar`, then this value should be `{foo: 'bar'}`
144 * If `argv` is `null` or `undefined`, then `rc`'s default parser will parse `process.argv`.
145 */
146 argv: U,
147 /**
148 * Custom config file parser.
149 * This function will be passed the string contents of each
150 * discovered configuration file, should return a parsed object dictionary.
151 */
152 parse?: (content: string) => object
153): T & U & RcResultType;
154declare function rc<
155 T extends object | string | null | undefined,
156 U extends object | null | undefined
157>(
158 /**
159 * The name of the app to configure, rc will search for this files :
160 * `/etc/${name}/config`,
161 * `/etc/${name}rc`,
162 * `~/.config/${name}/config`,
163 * `~/.config/${name}`,
164 * `~/.${name}/config`,
165 * `~/.${name}rc` and
166 * `.${name}rc` in CWD and its ancestors
167 */
168 name: string,
169 /**
170 * Default config values.
171 * Can be an Object that contains the default values for the config,
172 * the path of a JSON or INI file to use as default config or
173 * can be `null` or `undefined` for no default values
174 */
175 defaults: T,
176 /**
177 * Parsed argv object.
178 * For example, if args is `--foo bar`, then this value should be `{foo: 'bar'}`
179 * If `argv` is `null` or `undefined`, then `rc`'s default parser will parse `process.argv`.
180 */
181 argv: U,
182 /**
183 * Custom config file parser.
184 * This function will be passed the string contents of each
185 * discovered configuration file, should return a parsed object dictionary.
186 */
187 parse?: (content: string) => object
188): (T extends string | null | undefined ?
189 (U extends null | undefined ? minimist.ParsedArgs : U) & RcResultType :
190 T & (U extends null | undefined ? minimist.ParsedArgs : U) & RcResultType);
191
192export = rc;