@types/node 18.6.5 → 18.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- node/README.md +1 -1
- node/index.d.ts +1 -1
- node/package.json +2 -2
- node/util.d.ts +187 -0
node/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This package contains type definitions for Node.js (https://nodejs.org/).
|
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated:
|
|
11
|
+
* Last updated: Wed, 10 Aug 2022 19:32:15 GMT
|
|
12
12
|
* Dependencies: none
|
|
13
13
|
* Global values: `AbortController`, `AbortSignal`, `__dirname`, `__filename`, `console`, `exports`, `gc`, `global`, `module`, `process`, `require`, `structuredClone`
|
|
14
14
|
|
node/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Type definitions for non-npm package Node.js 18.
|
|
1
|
+
// Type definitions for non-npm package Node.js 18.7
|
|
2
2
|
// Project: https://nodejs.org/
|
|
3
3
|
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
|
|
4
4
|
// DefinitelyTyped <https://github.com/DefinitelyTyped>
|
node/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.7.0",
|
|
4
4
|
"description": "TypeScript definitions for Node.js",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -220,6 +220,6 @@
|
|
|
220
220
|
},
|
|
221
221
|
"scripts": {},
|
|
222
222
|
"dependencies": {},
|
|
223
|
-
"typesPublisherContentHash": "
|
|
223
|
+
"typesPublisherContentHash": "a96c6707c1cbb47c9152c3197f9f3d7ffd3019aa1c93e963886447c481d34b2f",
|
|
224
224
|
"typeScriptVersion": "4.0"
|
|
225
225
|
}
|
node/util.d.ts
CHANGED
|
@@ -1105,6 +1105,193 @@ declare module 'util' {
|
|
|
1105
1105
|
*/
|
|
1106
1106
|
encodeInto(src: string, dest: Uint8Array): EncodeIntoResult;
|
|
1107
1107
|
}
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* Provides a high-level API for command-line argument parsing. Takes a
|
|
1111
|
+
* specification for the expected arguments and returns a structured object
|
|
1112
|
+
* with the parsed values and positionals.
|
|
1113
|
+
*
|
|
1114
|
+
* `config` provides arguments for parsing and configures the parser. It
|
|
1115
|
+
* supports the following properties:
|
|
1116
|
+
*
|
|
1117
|
+
* - `args` The array of argument strings. **Default:** `process.argv` with
|
|
1118
|
+
* `execPath` and `filename` removed.
|
|
1119
|
+
* - `options` Arguments known to the parser. Keys of `options` are the long
|
|
1120
|
+
* names of options and values are objects accepting the following properties:
|
|
1121
|
+
*
|
|
1122
|
+
* - `type` Type of argument, which must be either `boolean` (for options
|
|
1123
|
+
* which do not take values) or `string` (for options which do).
|
|
1124
|
+
* - `multiple` Whether this option can be provided multiple
|
|
1125
|
+
* times. If `true`, all values will be collected in an array. If
|
|
1126
|
+
* `false`, values for the option are last-wins. **Default:** `false`.
|
|
1127
|
+
* - `short` A single character alias for the option.
|
|
1128
|
+
*
|
|
1129
|
+
* - `strict`: Whether an error should be thrown when unknown arguments
|
|
1130
|
+
* are encountered, or when arguments are passed that do not match the
|
|
1131
|
+
* `type` configured in `options`. **Default:** `true`.
|
|
1132
|
+
* - `allowPositionals`: Whether this command accepts positional arguments.
|
|
1133
|
+
* **Default:** `false` if `strict` is `true`, otherwise `true`.
|
|
1134
|
+
* - `tokens`: Whether tokens {boolean} Return the parsed tokens. This is useful
|
|
1135
|
+
* for extending the built-in behavior, from adding additional checks through
|
|
1136
|
+
* to reprocessing the tokens in different ways.
|
|
1137
|
+
* **Default:** `false`.
|
|
1138
|
+
*
|
|
1139
|
+
* @returns The parsed command line arguments:
|
|
1140
|
+
*
|
|
1141
|
+
* - `values` A mapping of parsed option names with their string
|
|
1142
|
+
* or boolean values.
|
|
1143
|
+
* - `positionals` Positional arguments.
|
|
1144
|
+
* - `tokens` Detailed parse information (only if `tokens` was specified).
|
|
1145
|
+
*
|
|
1146
|
+
*/
|
|
1147
|
+
export function parseArgs<T extends ParseArgsConfig>(config: T): ParsedResults<T>;
|
|
1148
|
+
|
|
1149
|
+
interface ParseArgsOptionConfig {
|
|
1150
|
+
type: 'string' | 'boolean';
|
|
1151
|
+
short?: string;
|
|
1152
|
+
multiple?: boolean;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
interface ParseArgsOptionsConfig {
|
|
1156
|
+
[longOption: string]: ParseArgsOptionConfig;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
export interface ParseArgsConfig {
|
|
1160
|
+
strict?: boolean;
|
|
1161
|
+
allowPositionals?: boolean;
|
|
1162
|
+
tokens?: boolean;
|
|
1163
|
+
options?: ParseArgsOptionsConfig;
|
|
1164
|
+
args?: string[];
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
/*
|
|
1168
|
+
IfDefaultsTrue and IfDefaultsFalse are helpers to handle default values for missing boolean properties.
|
|
1169
|
+
TypeScript does not have exact types for objects: https://github.com/microsoft/TypeScript/issues/12936
|
|
1170
|
+
This means it is impossible to distinguish between "field X is definitely not present" and "field X may or may not be present".
|
|
1171
|
+
But we expect users to generally provide their config inline or `as const`, which means TS will always know whether a given field is present.
|
|
1172
|
+
So this helper treats "not definitely present" (i.e., not `extends boolean`) as being "definitely not present", i.e. it should have its default value.
|
|
1173
|
+
This is technically incorrect but is a much nicer UX for the common case.
|
|
1174
|
+
The IfDefaultsTrue version is for things which default to true; the IfDefaultsFalse version is for things which default to false.
|
|
1175
|
+
*/
|
|
1176
|
+
type IfDefaultsTrue<T, IfTrue, IfFalse> = T extends true
|
|
1177
|
+
? IfTrue
|
|
1178
|
+
: T extends false
|
|
1179
|
+
? IfFalse
|
|
1180
|
+
: IfTrue;
|
|
1181
|
+
|
|
1182
|
+
// we put the `extends false` condition first here because `undefined` compares like `any` when `strictNullChecks: false`
|
|
1183
|
+
type IfDefaultsFalse<T, IfTrue, IfFalse> = T extends false
|
|
1184
|
+
? IfFalse
|
|
1185
|
+
: T extends true
|
|
1186
|
+
? IfTrue
|
|
1187
|
+
: IfFalse;
|
|
1188
|
+
|
|
1189
|
+
type ExtractOptionValue<T extends ParseArgsConfig, O extends ParseArgsOptionConfig> = IfDefaultsTrue<
|
|
1190
|
+
T['strict'],
|
|
1191
|
+
O['type'] extends 'string' ? string : O['type'] extends 'boolean' ? boolean : string | boolean,
|
|
1192
|
+
string | boolean
|
|
1193
|
+
>;
|
|
1194
|
+
|
|
1195
|
+
type ParsedValues<T extends ParseArgsConfig> =
|
|
1196
|
+
& IfDefaultsTrue<T['strict'], unknown, { [longOption: string]: undefined | string | boolean }>
|
|
1197
|
+
& (T['options'] extends ParseArgsOptionsConfig
|
|
1198
|
+
? {
|
|
1199
|
+
-readonly [LongOption in keyof T['options']]: IfDefaultsFalse<
|
|
1200
|
+
T['options'][LongOption]['multiple'],
|
|
1201
|
+
undefined | Array<ExtractOptionValue<T, T['options'][LongOption]>>,
|
|
1202
|
+
undefined | ExtractOptionValue<T, T['options'][LongOption]>
|
|
1203
|
+
>;
|
|
1204
|
+
}
|
|
1205
|
+
: {});
|
|
1206
|
+
|
|
1207
|
+
type ParsedPositionals<T extends ParseArgsConfig> = IfDefaultsTrue<
|
|
1208
|
+
T['strict'],
|
|
1209
|
+
IfDefaultsFalse<T['allowPositionals'], string[], []>,
|
|
1210
|
+
IfDefaultsTrue<T['allowPositionals'], string[], []>
|
|
1211
|
+
>;
|
|
1212
|
+
|
|
1213
|
+
type PreciseTokenForOptions<
|
|
1214
|
+
K extends string,
|
|
1215
|
+
O extends ParseArgsOptionConfig,
|
|
1216
|
+
> = O['type'] extends 'string'
|
|
1217
|
+
? {
|
|
1218
|
+
kind: 'option';
|
|
1219
|
+
index: number;
|
|
1220
|
+
name: K;
|
|
1221
|
+
rawName: string;
|
|
1222
|
+
value: string;
|
|
1223
|
+
inlineValue: boolean;
|
|
1224
|
+
}
|
|
1225
|
+
: O['type'] extends 'boolean'
|
|
1226
|
+
? {
|
|
1227
|
+
kind: 'option';
|
|
1228
|
+
index: number;
|
|
1229
|
+
name: K;
|
|
1230
|
+
rawName: string;
|
|
1231
|
+
value: undefined;
|
|
1232
|
+
inlineValue: undefined;
|
|
1233
|
+
}
|
|
1234
|
+
: OptionToken & { name: K };
|
|
1235
|
+
|
|
1236
|
+
type TokenForOptions<
|
|
1237
|
+
T extends ParseArgsConfig,
|
|
1238
|
+
K extends keyof T['options'] = keyof T['options'],
|
|
1239
|
+
> = K extends unknown
|
|
1240
|
+
? T['options'] extends ParseArgsOptionsConfig
|
|
1241
|
+
? PreciseTokenForOptions<K & string, T['options'][K]>
|
|
1242
|
+
: OptionToken
|
|
1243
|
+
: never;
|
|
1244
|
+
|
|
1245
|
+
type ParsedOptionToken<T extends ParseArgsConfig> = IfDefaultsTrue<T['strict'], TokenForOptions<T>, OptionToken>;
|
|
1246
|
+
|
|
1247
|
+
type ParsedPositionalToken<T extends ParseArgsConfig> = IfDefaultsTrue<
|
|
1248
|
+
T['strict'],
|
|
1249
|
+
IfDefaultsFalse<T['allowPositionals'], { kind: 'positional'; index: number; value: string }, never>,
|
|
1250
|
+
IfDefaultsTrue<T['allowPositionals'], { kind: 'positional'; index: number; value: string }, never>
|
|
1251
|
+
>;
|
|
1252
|
+
|
|
1253
|
+
type ParsedTokens<T extends ParseArgsConfig> = Array<
|
|
1254
|
+
ParsedOptionToken<T> | ParsedPositionalToken<T> | { kind: 'option-terminator'; index: number }
|
|
1255
|
+
>;
|
|
1256
|
+
|
|
1257
|
+
type PreciseParsedResults<T extends ParseArgsConfig> = IfDefaultsFalse<
|
|
1258
|
+
T['tokens'],
|
|
1259
|
+
{
|
|
1260
|
+
values: ParsedValues<T>;
|
|
1261
|
+
positionals: ParsedPositionals<T>;
|
|
1262
|
+
tokens: ParsedTokens<T>;
|
|
1263
|
+
},
|
|
1264
|
+
{
|
|
1265
|
+
values: ParsedValues<T>;
|
|
1266
|
+
positionals: ParsedPositionals<T>;
|
|
1267
|
+
}
|
|
1268
|
+
>;
|
|
1269
|
+
|
|
1270
|
+
type OptionToken =
|
|
1271
|
+
| { kind: 'option'; index: number; name: string; rawName: string; value: string; inlineValue: boolean }
|
|
1272
|
+
| {
|
|
1273
|
+
kind: 'option';
|
|
1274
|
+
index: number;
|
|
1275
|
+
name: string;
|
|
1276
|
+
rawName: string;
|
|
1277
|
+
value: undefined;
|
|
1278
|
+
inlineValue: undefined;
|
|
1279
|
+
};
|
|
1280
|
+
|
|
1281
|
+
type Token =
|
|
1282
|
+
| OptionToken
|
|
1283
|
+
| { kind: 'positional'; index: number; value: string }
|
|
1284
|
+
| { kind: 'option-terminator'; index: number };
|
|
1285
|
+
|
|
1286
|
+
// If ParseArgsConfig extends T, then the user passed config constructed elsewhere.
|
|
1287
|
+
// So we can't rely on the `"not definitely present" implies "definitely not present"` assumption mentioned above.
|
|
1288
|
+
type ParsedResults<T extends ParseArgsConfig> = ParseArgsConfig extends T
|
|
1289
|
+
? {
|
|
1290
|
+
values: { [longOption: string]: undefined | string | boolean | Array<string | boolean> };
|
|
1291
|
+
positionals: string[];
|
|
1292
|
+
tokens?: Token[];
|
|
1293
|
+
}
|
|
1294
|
+
: PreciseParsedResults<T>;
|
|
1108
1295
|
}
|
|
1109
1296
|
declare module 'util/types' {
|
|
1110
1297
|
export * from 'util/types';
|