rahad-all-downloader 2.1.16 → 2.1.18
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.
- package/.github/workflows/Run.yml +20 -0
- package/README.md +1 -2
- package/index.js +1 -1
- package/package.json +6 -2
- package/.cache/nix/binary-cache-v6.sqlite +0 -0
- package/.cache/nix/binary-cache-v6.sqlite-journal +0 -0
- package/.cache/replit/env/latest +0 -123
- package/.cache/replit/env/latest.json +0 -1
- package/.cache/replit/modules/nix.res +0 -1
- package/.cache/replit/modules/nodejs-20.res +0 -1
- package/.cache/replit/modules/replit.res +0 -1
- package/.cache/replit/modules.stamp +0 -0
- package/.cache/replit/nix/env.json +0 -1
- package/.cache/typescript/5.4/node_modules/.package-lock.json +0 -137
- package/.cache/typescript/5.4/node_modules/@types/caseless/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/caseless/README.md +0 -48
- package/.cache/typescript/5.4/node_modules/@types/caseless/index.d.ts +0 -29
- package/.cache/typescript/5.4/node_modules/@types/caseless/package.json +0 -35
- package/.cache/typescript/5.4/node_modules/@types/node/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/node/README.md +0 -15
- package/.cache/typescript/5.4/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/.cache/typescript/5.4/node_modules/@types/node/assert.d.ts +0 -1040
- package/.cache/typescript/5.4/node_modules/@types/node/async_hooks.d.ts +0 -541
- package/.cache/typescript/5.4/node_modules/@types/node/buffer.d.ts +0 -2363
- package/.cache/typescript/5.4/node_modules/@types/node/child_process.d.ts +0 -1544
- package/.cache/typescript/5.4/node_modules/@types/node/cluster.d.ts +0 -578
- package/.cache/typescript/5.4/node_modules/@types/node/console.d.ts +0 -452
- package/.cache/typescript/5.4/node_modules/@types/node/constants.d.ts +0 -19
- package/.cache/typescript/5.4/node_modules/@types/node/crypto.d.ts +0 -4523
- package/.cache/typescript/5.4/node_modules/@types/node/dgram.d.ts +0 -596
- package/.cache/typescript/5.4/node_modules/@types/node/diagnostics_channel.d.ts +0 -554
- package/.cache/typescript/5.4/node_modules/@types/node/dns/promises.d.ts +0 -474
- package/.cache/typescript/5.4/node_modules/@types/node/dns.d.ts +0 -864
- package/.cache/typescript/5.4/node_modules/@types/node/dom-events.d.ts +0 -124
- package/.cache/typescript/5.4/node_modules/@types/node/domain.d.ts +0 -170
- package/.cache/typescript/5.4/node_modules/@types/node/events.d.ts +0 -909
- package/.cache/typescript/5.4/node_modules/@types/node/fs/promises.d.ts +0 -1245
- package/.cache/typescript/5.4/node_modules/@types/node/fs.d.ts +0 -4317
- package/.cache/typescript/5.4/node_modules/@types/node/globals.d.ts +0 -411
- package/.cache/typescript/5.4/node_modules/@types/node/globals.global.d.ts +0 -1
- package/.cache/typescript/5.4/node_modules/@types/node/http.d.ts +0 -1908
- package/.cache/typescript/5.4/node_modules/@types/node/http2.d.ts +0 -2418
- package/.cache/typescript/5.4/node_modules/@types/node/https.d.ts +0 -550
- package/.cache/typescript/5.4/node_modules/@types/node/index.d.ts +0 -89
- package/.cache/typescript/5.4/node_modules/@types/node/inspector.d.ts +0 -2746
- package/.cache/typescript/5.4/node_modules/@types/node/module.d.ts +0 -315
- package/.cache/typescript/5.4/node_modules/@types/node/net.d.ts +0 -999
- package/.cache/typescript/5.4/node_modules/@types/node/os.d.ts +0 -495
- package/.cache/typescript/5.4/node_modules/@types/node/package.json +0 -217
- package/.cache/typescript/5.4/node_modules/@types/node/path.d.ts +0 -191
- package/.cache/typescript/5.4/node_modules/@types/node/perf_hooks.d.ts +0 -905
- package/.cache/typescript/5.4/node_modules/@types/node/process.d.ts +0 -1754
- package/.cache/typescript/5.4/node_modules/@types/node/punycode.d.ts +0 -117
- package/.cache/typescript/5.4/node_modules/@types/node/querystring.d.ts +0 -153
- package/.cache/typescript/5.4/node_modules/@types/node/readline/promises.d.ts +0 -150
- package/.cache/typescript/5.4/node_modules/@types/node/readline.d.ts +0 -540
- package/.cache/typescript/5.4/node_modules/@types/node/repl.d.ts +0 -430
- package/.cache/typescript/5.4/node_modules/@types/node/sea.d.ts +0 -153
- package/.cache/typescript/5.4/node_modules/@types/node/stream/consumers.d.ts +0 -12
- package/.cache/typescript/5.4/node_modules/@types/node/stream/promises.d.ts +0 -83
- package/.cache/typescript/5.4/node_modules/@types/node/stream/web.d.ts +0 -367
- package/.cache/typescript/5.4/node_modules/@types/node/stream.d.ts +0 -1707
- package/.cache/typescript/5.4/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/.cache/typescript/5.4/node_modules/@types/node/test.d.ts +0 -1718
- package/.cache/typescript/5.4/node_modules/@types/node/timers/promises.d.ts +0 -97
- package/.cache/typescript/5.4/node_modules/@types/node/timers.d.ts +0 -240
- package/.cache/typescript/5.4/node_modules/@types/node/tls.d.ts +0 -1217
- package/.cache/typescript/5.4/node_modules/@types/node/trace_events.d.ts +0 -197
- package/.cache/typescript/5.4/node_modules/@types/node/tty.d.ts +0 -208
- package/.cache/typescript/5.4/node_modules/@types/node/url.d.ts +0 -952
- package/.cache/typescript/5.4/node_modules/@types/node/util.d.ts +0 -2292
- package/.cache/typescript/5.4/node_modules/@types/node/v8.d.ts +0 -808
- package/.cache/typescript/5.4/node_modules/@types/node/vm.d.ts +0 -924
- package/.cache/typescript/5.4/node_modules/@types/node/wasi.d.ts +0 -181
- package/.cache/typescript/5.4/node_modules/@types/node/worker_threads.d.ts +0 -691
- package/.cache/typescript/5.4/node_modules/@types/node/zlib.d.ts +0 -530
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/README.md +0 -15
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/externals.d.ts +0 -32
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/index.d.ts +0 -238
- package/.cache/typescript/5.4/node_modules/@types/node-fetch/package.json +0 -83
- package/.cache/typescript/5.4/node_modules/@types/request/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/request/README.md +0 -15
- package/.cache/typescript/5.4/node_modules/@types/request/index.d.ts +0 -395
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/License +0 -19
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/README.md +0 -350
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/README.md.bak +0 -350
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/index.d.ts +0 -51
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/lib/browser.js +0 -2
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/lib/form_data.js +0 -483
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/lib/populate.js +0 -10
- package/.cache/typescript/5.4/node_modules/@types/request/node_modules/form-data/package.json +0 -68
- package/.cache/typescript/5.4/node_modules/@types/request/package.json +0 -70
- package/.cache/typescript/5.4/node_modules/@types/tough-cookie/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/@types/tough-cookie/README.md +0 -15
- package/.cache/typescript/5.4/node_modules/@types/tough-cookie/index.d.ts +0 -321
- package/.cache/typescript/5.4/node_modules/@types/tough-cookie/package.json +0 -35
- package/.cache/typescript/5.4/node_modules/asynckit/LICENSE +0 -21
- package/.cache/typescript/5.4/node_modules/asynckit/README.md +0 -233
- package/.cache/typescript/5.4/node_modules/asynckit/bench.js +0 -76
- package/.cache/typescript/5.4/node_modules/asynckit/index.js +0 -6
- package/.cache/typescript/5.4/node_modules/asynckit/lib/abort.js +0 -29
- package/.cache/typescript/5.4/node_modules/asynckit/lib/async.js +0 -34
- package/.cache/typescript/5.4/node_modules/asynckit/lib/defer.js +0 -26
- package/.cache/typescript/5.4/node_modules/asynckit/lib/iterate.js +0 -75
- package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_asynckit.js +0 -91
- package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_parallel.js +0 -25
- package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_serial.js +0 -25
- package/.cache/typescript/5.4/node_modules/asynckit/lib/readable_serial_ordered.js +0 -29
- package/.cache/typescript/5.4/node_modules/asynckit/lib/state.js +0 -37
- package/.cache/typescript/5.4/node_modules/asynckit/lib/streamify.js +0 -141
- package/.cache/typescript/5.4/node_modules/asynckit/lib/terminator.js +0 -29
- package/.cache/typescript/5.4/node_modules/asynckit/package.json +0 -63
- package/.cache/typescript/5.4/node_modules/asynckit/parallel.js +0 -43
- package/.cache/typescript/5.4/node_modules/asynckit/serial.js +0 -17
- package/.cache/typescript/5.4/node_modules/asynckit/serialOrdered.js +0 -75
- package/.cache/typescript/5.4/node_modules/asynckit/stream.js +0 -21
- package/.cache/typescript/5.4/node_modules/combined-stream/License +0 -19
- package/.cache/typescript/5.4/node_modules/combined-stream/Readme.md +0 -138
- package/.cache/typescript/5.4/node_modules/combined-stream/lib/combined_stream.js +0 -208
- package/.cache/typescript/5.4/node_modules/combined-stream/package.json +0 -25
- package/.cache/typescript/5.4/node_modules/combined-stream/yarn.lock +0 -17
- package/.cache/typescript/5.4/node_modules/delayed-stream/License +0 -19
- package/.cache/typescript/5.4/node_modules/delayed-stream/Makefile +0 -7
- package/.cache/typescript/5.4/node_modules/delayed-stream/Readme.md +0 -141
- package/.cache/typescript/5.4/node_modules/delayed-stream/lib/delayed_stream.js +0 -107
- package/.cache/typescript/5.4/node_modules/delayed-stream/package.json +0 -27
- package/.cache/typescript/5.4/node_modules/form-data/License +0 -19
- package/.cache/typescript/5.4/node_modules/form-data/README.md.bak +0 -358
- package/.cache/typescript/5.4/node_modules/form-data/Readme.md +0 -358
- package/.cache/typescript/5.4/node_modules/form-data/index.d.ts +0 -62
- package/.cache/typescript/5.4/node_modules/form-data/lib/browser.js +0 -2
- package/.cache/typescript/5.4/node_modules/form-data/lib/form_data.js +0 -501
- package/.cache/typescript/5.4/node_modules/form-data/lib/populate.js +0 -10
- package/.cache/typescript/5.4/node_modules/form-data/package.json +0 -68
- package/.cache/typescript/5.4/node_modules/mime-db/HISTORY.md +0 -507
- package/.cache/typescript/5.4/node_modules/mime-db/LICENSE +0 -23
- package/.cache/typescript/5.4/node_modules/mime-db/README.md +0 -100
- package/.cache/typescript/5.4/node_modules/mime-db/db.json +0 -8519
- package/.cache/typescript/5.4/node_modules/mime-db/index.js +0 -12
- package/.cache/typescript/5.4/node_modules/mime-db/package.json +0 -60
- package/.cache/typescript/5.4/node_modules/mime-types/HISTORY.md +0 -397
- package/.cache/typescript/5.4/node_modules/mime-types/LICENSE +0 -23
- package/.cache/typescript/5.4/node_modules/mime-types/README.md +0 -113
- package/.cache/typescript/5.4/node_modules/mime-types/index.js +0 -188
- package/.cache/typescript/5.4/node_modules/mime-types/package.json +0 -44
- package/.cache/typescript/5.4/node_modules/types-registry/README.md +0 -2
- package/.cache/typescript/5.4/node_modules/types-registry/index.json +0 -1
- package/.cache/typescript/5.4/node_modules/types-registry/package.json +0 -20
- package/.cache/typescript/5.4/node_modules/undici-types/README.md +0 -6
- package/.cache/typescript/5.4/node_modules/undici-types/agent.d.ts +0 -31
- package/.cache/typescript/5.4/node_modules/undici-types/api.d.ts +0 -43
- package/.cache/typescript/5.4/node_modules/undici-types/balanced-pool.d.ts +0 -18
- package/.cache/typescript/5.4/node_modules/undici-types/cache.d.ts +0 -36
- package/.cache/typescript/5.4/node_modules/undici-types/client.d.ts +0 -97
- package/.cache/typescript/5.4/node_modules/undici-types/connector.d.ts +0 -34
- package/.cache/typescript/5.4/node_modules/undici-types/content-type.d.ts +0 -21
- package/.cache/typescript/5.4/node_modules/undici-types/cookies.d.ts +0 -28
- package/.cache/typescript/5.4/node_modules/undici-types/diagnostics-channel.d.ts +0 -67
- package/.cache/typescript/5.4/node_modules/undici-types/dispatcher.d.ts +0 -241
- package/.cache/typescript/5.4/node_modules/undici-types/errors.d.ts +0 -128
- package/.cache/typescript/5.4/node_modules/undici-types/fetch.d.ts +0 -209
- package/.cache/typescript/5.4/node_modules/undici-types/file.d.ts +0 -39
- package/.cache/typescript/5.4/node_modules/undici-types/filereader.d.ts +0 -54
- package/.cache/typescript/5.4/node_modules/undici-types/formdata.d.ts +0 -108
- package/.cache/typescript/5.4/node_modules/undici-types/global-dispatcher.d.ts +0 -9
- package/.cache/typescript/5.4/node_modules/undici-types/global-origin.d.ts +0 -7
- package/.cache/typescript/5.4/node_modules/undici-types/handlers.d.ts +0 -9
- package/.cache/typescript/5.4/node_modules/undici-types/header.d.ts +0 -4
- package/.cache/typescript/5.4/node_modules/undici-types/index.d.ts +0 -63
- package/.cache/typescript/5.4/node_modules/undici-types/interceptors.d.ts +0 -5
- package/.cache/typescript/5.4/node_modules/undici-types/mock-agent.d.ts +0 -50
- package/.cache/typescript/5.4/node_modules/undici-types/mock-client.d.ts +0 -25
- package/.cache/typescript/5.4/node_modules/undici-types/mock-errors.d.ts +0 -12
- package/.cache/typescript/5.4/node_modules/undici-types/mock-interceptor.d.ts +0 -93
- package/.cache/typescript/5.4/node_modules/undici-types/mock-pool.d.ts +0 -25
- package/.cache/typescript/5.4/node_modules/undici-types/package.json +0 -55
- package/.cache/typescript/5.4/node_modules/undici-types/patch.d.ts +0 -71
- package/.cache/typescript/5.4/node_modules/undici-types/pool-stats.d.ts +0 -19
- package/.cache/typescript/5.4/node_modules/undici-types/pool.d.ts +0 -28
- package/.cache/typescript/5.4/node_modules/undici-types/proxy-agent.d.ts +0 -30
- package/.cache/typescript/5.4/node_modules/undici-types/readable.d.ts +0 -61
- package/.cache/typescript/5.4/node_modules/undici-types/webidl.d.ts +0 -220
- package/.cache/typescript/5.4/node_modules/undici-types/websocket.d.ts +0 -131
- package/.cache/typescript/5.4/package-lock.json +0 -146
- package/.cache/typescript/5.4/package.json +0 -1
- package/.replit +0 -21
- package/replit.nix +0 -3
@@ -1,2292 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* The `node:util` module supports the needs of Node.js internal APIs. Many of the
|
3
|
-
* utilities are useful for application and module developers as well. To access
|
4
|
-
* it:
|
5
|
-
*
|
6
|
-
* ```js
|
7
|
-
* const util = require('node:util');
|
8
|
-
* ```
|
9
|
-
* @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/util.js)
|
10
|
-
*/
|
11
|
-
declare module "util" {
|
12
|
-
import * as types from "node:util/types";
|
13
|
-
export interface InspectOptions {
|
14
|
-
/**
|
15
|
-
* If `true`, object's non-enumerable symbols and properties are included in the formatted result.
|
16
|
-
* `WeakMap` and `WeakSet` entries are also included as well as user defined prototype properties (excluding method properties).
|
17
|
-
* @default false
|
18
|
-
*/
|
19
|
-
showHidden?: boolean | undefined;
|
20
|
-
/**
|
21
|
-
* Specifies the number of times to recurse while formatting object.
|
22
|
-
* This is useful for inspecting large objects.
|
23
|
-
* To recurse up to the maximum call stack size pass `Infinity` or `null`.
|
24
|
-
* @default 2
|
25
|
-
*/
|
26
|
-
depth?: number | null | undefined;
|
27
|
-
/**
|
28
|
-
* If `true`, the output is styled with ANSI color codes. Colors are customizable.
|
29
|
-
*/
|
30
|
-
colors?: boolean | undefined;
|
31
|
-
/**
|
32
|
-
* If `false`, `[util.inspect.custom](depth, opts, inspect)` functions are not invoked.
|
33
|
-
* @default true
|
34
|
-
*/
|
35
|
-
customInspect?: boolean | undefined;
|
36
|
-
/**
|
37
|
-
* If `true`, `Proxy` inspection includes the target and handler objects.
|
38
|
-
* @default false
|
39
|
-
*/
|
40
|
-
showProxy?: boolean | undefined;
|
41
|
-
/**
|
42
|
-
* Specifies the maximum number of `Array`, `TypedArray`, `WeakMap`, and `WeakSet` elements
|
43
|
-
* to include when formatting. Set to `null` or `Infinity` to show all elements.
|
44
|
-
* Set to `0` or negative to show no elements.
|
45
|
-
* @default 100
|
46
|
-
*/
|
47
|
-
maxArrayLength?: number | null | undefined;
|
48
|
-
/**
|
49
|
-
* Specifies the maximum number of characters to
|
50
|
-
* include when formatting. Set to `null` or `Infinity` to show all elements.
|
51
|
-
* Set to `0` or negative to show no characters.
|
52
|
-
* @default 10000
|
53
|
-
*/
|
54
|
-
maxStringLength?: number | null | undefined;
|
55
|
-
/**
|
56
|
-
* The length at which input values are split across multiple lines.
|
57
|
-
* Set to `Infinity` to format the input as a single line
|
58
|
-
* (in combination with `compact` set to `true` or any number >= `1`).
|
59
|
-
* @default 80
|
60
|
-
*/
|
61
|
-
breakLength?: number | undefined;
|
62
|
-
/**
|
63
|
-
* Setting this to `false` causes each object key
|
64
|
-
* to be displayed on a new line. It will also add new lines to text that is
|
65
|
-
* longer than `breakLength`. If set to a number, the most `n` inner elements
|
66
|
-
* are united on a single line as long as all properties fit into
|
67
|
-
* `breakLength`. Short array elements are also grouped together. Note that no
|
68
|
-
* text will be reduced below 16 characters, no matter the `breakLength` size.
|
69
|
-
* For more information, see the example below.
|
70
|
-
* @default true
|
71
|
-
*/
|
72
|
-
compact?: boolean | number | undefined;
|
73
|
-
/**
|
74
|
-
* If set to `true` or a function, all properties of an object, and `Set` and `Map`
|
75
|
-
* entries are sorted in the resulting string.
|
76
|
-
* If set to `true` the default sort is used.
|
77
|
-
* If set to a function, it is used as a compare function.
|
78
|
-
*/
|
79
|
-
sorted?: boolean | ((a: string, b: string) => number) | undefined;
|
80
|
-
/**
|
81
|
-
* If set to `true`, getters are going to be
|
82
|
-
* inspected as well. If set to `'get'` only getters without setter are going
|
83
|
-
* to be inspected. If set to `'set'` only getters having a corresponding
|
84
|
-
* setter are going to be inspected. This might cause side effects depending on
|
85
|
-
* the getter function.
|
86
|
-
* @default false
|
87
|
-
*/
|
88
|
-
getters?: "get" | "set" | boolean | undefined;
|
89
|
-
/**
|
90
|
-
* If set to `true`, an underscore is used to separate every three digits in all bigints and numbers.
|
91
|
-
* @default false
|
92
|
-
*/
|
93
|
-
numericSeparator?: boolean | undefined;
|
94
|
-
}
|
95
|
-
export type Style =
|
96
|
-
| "special"
|
97
|
-
| "number"
|
98
|
-
| "bigint"
|
99
|
-
| "boolean"
|
100
|
-
| "undefined"
|
101
|
-
| "null"
|
102
|
-
| "string"
|
103
|
-
| "symbol"
|
104
|
-
| "date"
|
105
|
-
| "regexp"
|
106
|
-
| "module";
|
107
|
-
export type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) => any; // TODO: , inspect: inspect
|
108
|
-
export interface InspectOptionsStylized extends InspectOptions {
|
109
|
-
stylize(text: string, styleType: Style): string;
|
110
|
-
}
|
111
|
-
/**
|
112
|
-
* The `util.format()` method returns a formatted string using the first argument
|
113
|
-
* as a `printf`-like format string which can contain zero or more format
|
114
|
-
* specifiers. Each specifier is replaced with the converted value from the
|
115
|
-
* corresponding argument. Supported specifiers are:
|
116
|
-
*
|
117
|
-
* If a specifier does not have a corresponding argument, it is not replaced:
|
118
|
-
*
|
119
|
-
* ```js
|
120
|
-
* util.format('%s:%s', 'foo');
|
121
|
-
* // Returns: 'foo:%s'
|
122
|
-
* ```
|
123
|
-
*
|
124
|
-
* Values that are not part of the format string are formatted using `util.inspect()` if their type is not `string`.
|
125
|
-
*
|
126
|
-
* If there are more arguments passed to the `util.format()` method than the
|
127
|
-
* number of specifiers, the extra arguments are concatenated to the returned
|
128
|
-
* string, separated by spaces:
|
129
|
-
*
|
130
|
-
* ```js
|
131
|
-
* util.format('%s:%s', 'foo', 'bar', 'baz');
|
132
|
-
* // Returns: 'foo:bar baz'
|
133
|
-
* ```
|
134
|
-
*
|
135
|
-
* If the first argument does not contain a valid format specifier, `util.format()` returns a string that is the concatenation of all arguments separated by spaces:
|
136
|
-
*
|
137
|
-
* ```js
|
138
|
-
* util.format(1, 2, 3);
|
139
|
-
* // Returns: '1 2 3'
|
140
|
-
* ```
|
141
|
-
*
|
142
|
-
* If only one argument is passed to `util.format()`, it is returned as it is
|
143
|
-
* without any formatting:
|
144
|
-
*
|
145
|
-
* ```js
|
146
|
-
* util.format('%% %s');
|
147
|
-
* // Returns: '%% %s'
|
148
|
-
* ```
|
149
|
-
*
|
150
|
-
* `util.format()` is a synchronous method that is intended as a debugging tool.
|
151
|
-
* Some input values can have a significant performance overhead that can block the
|
152
|
-
* event loop. Use this function with care and never in a hot code path.
|
153
|
-
* @since v0.5.3
|
154
|
-
* @param format A `printf`-like format string.
|
155
|
-
*/
|
156
|
-
export function format(format?: any, ...param: any[]): string;
|
157
|
-
/**
|
158
|
-
* This function is identical to {@link format}, except in that it takes
|
159
|
-
* an `inspectOptions` argument which specifies options that are passed along to {@link inspect}.
|
160
|
-
*
|
161
|
-
* ```js
|
162
|
-
* util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 });
|
163
|
-
* // Returns 'See object { foo: 42 }', where `42` is colored as a number
|
164
|
-
* // when printed to a terminal.
|
165
|
-
* ```
|
166
|
-
* @since v10.0.0
|
167
|
-
*/
|
168
|
-
export function formatWithOptions(inspectOptions: InspectOptions, format?: any, ...param: any[]): string;
|
169
|
-
/**
|
170
|
-
* Returns the string name for a numeric error code that comes from a Node.js API.
|
171
|
-
* The mapping between error codes and error names is platform-dependent.
|
172
|
-
* See `Common System Errors` for the names of common errors.
|
173
|
-
*
|
174
|
-
* ```js
|
175
|
-
* fs.access('file/that/does/not/exist', (err) => {
|
176
|
-
* const name = util.getSystemErrorName(err.errno);
|
177
|
-
* console.error(name); // ENOENT
|
178
|
-
* });
|
179
|
-
* ```
|
180
|
-
* @since v9.7.0
|
181
|
-
*/
|
182
|
-
export function getSystemErrorName(err: number): string;
|
183
|
-
/**
|
184
|
-
* Returns a Map of all system error codes available from the Node.js API.
|
185
|
-
* The mapping between error codes and error names is platform-dependent.
|
186
|
-
* See `Common System Errors` for the names of common errors.
|
187
|
-
*
|
188
|
-
* ```js
|
189
|
-
* fs.access('file/that/does/not/exist', (err) => {
|
190
|
-
* const errorMap = util.getSystemErrorMap();
|
191
|
-
* const name = errorMap.get(err.errno);
|
192
|
-
* console.error(name); // ENOENT
|
193
|
-
* });
|
194
|
-
* ```
|
195
|
-
* @since v16.0.0, v14.17.0
|
196
|
-
*/
|
197
|
-
export function getSystemErrorMap(): Map<number, [string, string]>;
|
198
|
-
/**
|
199
|
-
* The `util.log()` method prints the given `string` to `stdout` with an included
|
200
|
-
* timestamp.
|
201
|
-
*
|
202
|
-
* ```js
|
203
|
-
* const util = require('node:util');
|
204
|
-
*
|
205
|
-
* util.log('Timestamped message.');
|
206
|
-
* ```
|
207
|
-
* @since v0.3.0
|
208
|
-
* @deprecated Since v6.0.0 - Use a third party module instead.
|
209
|
-
*/
|
210
|
-
export function log(string: string): void;
|
211
|
-
/**
|
212
|
-
* Returns the `string` after replacing any surrogate code points
|
213
|
-
* (or equivalently, any unpaired surrogate code units) with the
|
214
|
-
* Unicode "replacement character" U+FFFD.
|
215
|
-
* @since v16.8.0, v14.18.0
|
216
|
-
*/
|
217
|
-
export function toUSVString(string: string): string;
|
218
|
-
/**
|
219
|
-
* Creates and returns an `AbortController` instance whose `AbortSignal` is marked
|
220
|
-
* as transferable and can be used with `structuredClone()` or `postMessage()`.
|
221
|
-
* @since v18.11.0
|
222
|
-
* @experimental
|
223
|
-
* @returns A transferable AbortController
|
224
|
-
*/
|
225
|
-
export function transferableAbortController(): AbortController;
|
226
|
-
/**
|
227
|
-
* Marks the given `AbortSignal` as transferable so that it can be used with`structuredClone()` and `postMessage()`.
|
228
|
-
*
|
229
|
-
* ```js
|
230
|
-
* const signal = transferableAbortSignal(AbortSignal.timeout(100));
|
231
|
-
* const channel = new MessageChannel();
|
232
|
-
* channel.port2.postMessage(signal, [signal]);
|
233
|
-
* ```
|
234
|
-
* @since v18.11.0
|
235
|
-
* @experimental
|
236
|
-
* @param signal The AbortSignal
|
237
|
-
* @returns The same AbortSignal
|
238
|
-
*/
|
239
|
-
export function transferableAbortSignal(signal: AbortSignal): AbortSignal;
|
240
|
-
/**
|
241
|
-
* Listens to abort event on the provided `signal` and
|
242
|
-
* returns a promise that is fulfilled when the `signal` is
|
243
|
-
* aborted. If the passed `resource` is garbage collected before the `signal` is
|
244
|
-
* aborted, the returned promise shall remain pending indefinitely.
|
245
|
-
*
|
246
|
-
* ```js
|
247
|
-
* import { aborted } from 'node:util';
|
248
|
-
*
|
249
|
-
* const dependent = obtainSomethingAbortable();
|
250
|
-
*
|
251
|
-
* aborted(dependent.signal, dependent).then(() => {
|
252
|
-
* // Do something when dependent is aborted.
|
253
|
-
* });
|
254
|
-
*
|
255
|
-
* dependent.on('event', () => {
|
256
|
-
* dependent.abort();
|
257
|
-
* });
|
258
|
-
* ```
|
259
|
-
* @since v19.7.0
|
260
|
-
* @experimental
|
261
|
-
* @param resource Any non-null entity, reference to which is held weakly.
|
262
|
-
*/
|
263
|
-
export function aborted(signal: AbortSignal, resource: any): Promise<void>;
|
264
|
-
/**
|
265
|
-
* The `util.inspect()` method returns a string representation of `object` that is
|
266
|
-
* intended for debugging. The output of `util.inspect` may change at any time
|
267
|
-
* and should not be depended upon programmatically. Additional `options` may be
|
268
|
-
* passed that alter the result. `util.inspect()` will use the constructor's name and/or `@@toStringTag` to make
|
269
|
-
* an identifiable tag for an inspected value.
|
270
|
-
*
|
271
|
-
* ```js
|
272
|
-
* class Foo {
|
273
|
-
* get [Symbol.toStringTag]() {
|
274
|
-
* return 'bar';
|
275
|
-
* }
|
276
|
-
* }
|
277
|
-
*
|
278
|
-
* class Bar {}
|
279
|
-
*
|
280
|
-
* const baz = Object.create(null, { [Symbol.toStringTag]: { value: 'foo' } });
|
281
|
-
*
|
282
|
-
* util.inspect(new Foo()); // 'Foo [bar] {}'
|
283
|
-
* util.inspect(new Bar()); // 'Bar {}'
|
284
|
-
* util.inspect(baz); // '[foo] {}'
|
285
|
-
* ```
|
286
|
-
*
|
287
|
-
* Circular references point to their anchor by using a reference index:
|
288
|
-
*
|
289
|
-
* ```js
|
290
|
-
* const { inspect } = require('node:util');
|
291
|
-
*
|
292
|
-
* const obj = {};
|
293
|
-
* obj.a = [obj];
|
294
|
-
* obj.b = {};
|
295
|
-
* obj.b.inner = obj.b;
|
296
|
-
* obj.b.obj = obj;
|
297
|
-
*
|
298
|
-
* console.log(inspect(obj));
|
299
|
-
* // <ref *1> {
|
300
|
-
* // a: [ [Circular *1] ],
|
301
|
-
* // b: <ref *2> { inner: [Circular *2], obj: [Circular *1] }
|
302
|
-
* // }
|
303
|
-
* ```
|
304
|
-
*
|
305
|
-
* The following example inspects all properties of the `util` object:
|
306
|
-
*
|
307
|
-
* ```js
|
308
|
-
* const util = require('node:util');
|
309
|
-
*
|
310
|
-
* console.log(util.inspect(util, { showHidden: true, depth: null }));
|
311
|
-
* ```
|
312
|
-
*
|
313
|
-
* The following example highlights the effect of the `compact` option:
|
314
|
-
*
|
315
|
-
* ```js
|
316
|
-
* const util = require('node:util');
|
317
|
-
*
|
318
|
-
* const o = {
|
319
|
-
* a: [1, 2, [[
|
320
|
-
* 'Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit, sed do ' +
|
321
|
-
* 'eiusmod \ntempor incididunt ut labore et dolore magna aliqua.',
|
322
|
-
* 'test',
|
323
|
-
* 'foo']], 4],
|
324
|
-
* b: new Map([['za', 1], ['zb', 'test']]),
|
325
|
-
* };
|
326
|
-
* console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));
|
327
|
-
*
|
328
|
-
* // { a:
|
329
|
-
* // [ 1,
|
330
|
-
* // 2,
|
331
|
-
* // [ [ 'Lorem ipsum dolor sit amet,\nconsectetur [...]', // A long line
|
332
|
-
* // 'test',
|
333
|
-
* // 'foo' ] ],
|
334
|
-
* // 4 ],
|
335
|
-
* // b: Map(2) { 'za' => 1, 'zb' => 'test' } }
|
336
|
-
*
|
337
|
-
* // Setting `compact` to false or an integer creates more reader friendly output.
|
338
|
-
* console.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));
|
339
|
-
*
|
340
|
-
* // {
|
341
|
-
* // a: [
|
342
|
-
* // 1,
|
343
|
-
* // 2,
|
344
|
-
* // [
|
345
|
-
* // [
|
346
|
-
* // 'Lorem ipsum dolor sit amet,\n' +
|
347
|
-
* // 'consectetur adipiscing elit, sed do eiusmod \n' +
|
348
|
-
* // 'tempor incididunt ut labore et dolore magna aliqua.',
|
349
|
-
* // 'test',
|
350
|
-
* // 'foo'
|
351
|
-
* // ]
|
352
|
-
* // ],
|
353
|
-
* // 4
|
354
|
-
* // ],
|
355
|
-
* // b: Map(2) {
|
356
|
-
* // 'za' => 1,
|
357
|
-
* // 'zb' => 'test'
|
358
|
-
* // }
|
359
|
-
* // }
|
360
|
-
*
|
361
|
-
* // Setting `breakLength` to e.g. 150 will print the "Lorem ipsum" text in a
|
362
|
-
* // single line.
|
363
|
-
* ```
|
364
|
-
*
|
365
|
-
* The `showHidden` option allows [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) and
|
366
|
-
* [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) entries to be
|
367
|
-
* inspected. If there are more entries than `maxArrayLength`, there is no
|
368
|
-
* guarantee which entries are displayed. That means retrieving the same [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) entries twice may
|
369
|
-
* result in different output. Furthermore, entries
|
370
|
-
* with no remaining strong references may be garbage collected at any time.
|
371
|
-
*
|
372
|
-
* ```js
|
373
|
-
* const { inspect } = require('node:util');
|
374
|
-
*
|
375
|
-
* const obj = { a: 1 };
|
376
|
-
* const obj2 = { b: 2 };
|
377
|
-
* const weakSet = new WeakSet([obj, obj2]);
|
378
|
-
*
|
379
|
-
* console.log(inspect(weakSet, { showHidden: true }));
|
380
|
-
* // WeakSet { { a: 1 }, { b: 2 } }
|
381
|
-
* ```
|
382
|
-
*
|
383
|
-
* The `sorted` option ensures that an object's property insertion order does not
|
384
|
-
* impact the result of `util.inspect()`.
|
385
|
-
*
|
386
|
-
* ```js
|
387
|
-
* const { inspect } = require('node:util');
|
388
|
-
* const assert = require('node:assert');
|
389
|
-
*
|
390
|
-
* const o1 = {
|
391
|
-
* b: [2, 3, 1],
|
392
|
-
* a: '`a` comes before `b`',
|
393
|
-
* c: new Set([2, 3, 1]),
|
394
|
-
* };
|
395
|
-
* console.log(inspect(o1, { sorted: true }));
|
396
|
-
* // { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set(3) { 1, 2, 3 } }
|
397
|
-
* console.log(inspect(o1, { sorted: (a, b) => b.localeCompare(a) }));
|
398
|
-
* // { c: Set(3) { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' }
|
399
|
-
*
|
400
|
-
* const o2 = {
|
401
|
-
* c: new Set([2, 1, 3]),
|
402
|
-
* a: '`a` comes before `b`',
|
403
|
-
* b: [2, 3, 1],
|
404
|
-
* };
|
405
|
-
* assert.strict.equal(
|
406
|
-
* inspect(o1, { sorted: true }),
|
407
|
-
* inspect(o2, { sorted: true }),
|
408
|
-
* );
|
409
|
-
* ```
|
410
|
-
*
|
411
|
-
* The `numericSeparator` option adds an underscore every three digits to all
|
412
|
-
* numbers.
|
413
|
-
*
|
414
|
-
* ```js
|
415
|
-
* const { inspect } = require('node:util');
|
416
|
-
*
|
417
|
-
* const thousand = 1_000;
|
418
|
-
* const million = 1_000_000;
|
419
|
-
* const bigNumber = 123_456_789n;
|
420
|
-
* const bigDecimal = 1_234.123_45;
|
421
|
-
*
|
422
|
-
* console.log(inspect(thousand, { numericSeparator: true }));
|
423
|
-
* // 1_000
|
424
|
-
* console.log(inspect(million, { numericSeparator: true }));
|
425
|
-
* // 1_000_000
|
426
|
-
* console.log(inspect(bigNumber, { numericSeparator: true }));
|
427
|
-
* // 123_456_789n
|
428
|
-
* console.log(inspect(bigDecimal, { numericSeparator: true }));
|
429
|
-
* // 1_234.123_45
|
430
|
-
* ```
|
431
|
-
*
|
432
|
-
* `util.inspect()` is a synchronous method intended for debugging. Its maximum
|
433
|
-
* output length is approximately 128 MiB. Inputs that result in longer output will
|
434
|
-
* be truncated.
|
435
|
-
* @since v0.3.0
|
436
|
-
* @param object Any JavaScript primitive or `Object`.
|
437
|
-
* @return The representation of `object`.
|
438
|
-
*/
|
439
|
-
export function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
|
440
|
-
export function inspect(object: any, options?: InspectOptions): string;
|
441
|
-
export namespace inspect {
|
442
|
-
let colors: NodeJS.Dict<[number, number]>;
|
443
|
-
let styles: {
|
444
|
-
[K in Style]: string;
|
445
|
-
};
|
446
|
-
let defaultOptions: InspectOptions;
|
447
|
-
/**
|
448
|
-
* Allows changing inspect settings from the repl.
|
449
|
-
*/
|
450
|
-
let replDefaults: InspectOptions;
|
451
|
-
/**
|
452
|
-
* That can be used to declare custom inspect functions.
|
453
|
-
*/
|
454
|
-
const custom: unique symbol;
|
455
|
-
}
|
456
|
-
/**
|
457
|
-
* Alias for [`Array.isArray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray).
|
458
|
-
*
|
459
|
-
* Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`.
|
460
|
-
*
|
461
|
-
* ```js
|
462
|
-
* const util = require('node:util');
|
463
|
-
*
|
464
|
-
* util.isArray([]);
|
465
|
-
* // Returns: true
|
466
|
-
* util.isArray(new Array());
|
467
|
-
* // Returns: true
|
468
|
-
* util.isArray({});
|
469
|
-
* // Returns: false
|
470
|
-
* ```
|
471
|
-
* @since v0.6.0
|
472
|
-
* @deprecated Since v4.0.0 - Use `isArray` instead.
|
473
|
-
*/
|
474
|
-
export function isArray(object: unknown): object is unknown[];
|
475
|
-
/**
|
476
|
-
* Returns `true` if the given `object` is a `RegExp`. Otherwise, returns `false`.
|
477
|
-
*
|
478
|
-
* ```js
|
479
|
-
* const util = require('node:util');
|
480
|
-
*
|
481
|
-
* util.isRegExp(/some regexp/);
|
482
|
-
* // Returns: true
|
483
|
-
* util.isRegExp(new RegExp('another regexp'));
|
484
|
-
* // Returns: true
|
485
|
-
* util.isRegExp({});
|
486
|
-
* // Returns: false
|
487
|
-
* ```
|
488
|
-
* @since v0.6.0
|
489
|
-
* @deprecated Since v4.0.0 - Deprecated
|
490
|
-
*/
|
491
|
-
export function isRegExp(object: unknown): object is RegExp;
|
492
|
-
/**
|
493
|
-
* Returns `true` if the given `object` is a `Date`. Otherwise, returns `false`.
|
494
|
-
*
|
495
|
-
* ```js
|
496
|
-
* const util = require('node:util');
|
497
|
-
*
|
498
|
-
* util.isDate(new Date());
|
499
|
-
* // Returns: true
|
500
|
-
* util.isDate(Date());
|
501
|
-
* // false (without 'new' returns a String)
|
502
|
-
* util.isDate({});
|
503
|
-
* // Returns: false
|
504
|
-
* ```
|
505
|
-
* @since v0.6.0
|
506
|
-
* @deprecated Since v4.0.0 - Use {@link types.isDate} instead.
|
507
|
-
*/
|
508
|
-
export function isDate(object: unknown): object is Date;
|
509
|
-
/**
|
510
|
-
* Returns `true` if the given `object` is an `Error`. Otherwise, returns `false`.
|
511
|
-
*
|
512
|
-
* ```js
|
513
|
-
* const util = require('node:util');
|
514
|
-
*
|
515
|
-
* util.isError(new Error());
|
516
|
-
* // Returns: true
|
517
|
-
* util.isError(new TypeError());
|
518
|
-
* // Returns: true
|
519
|
-
* util.isError({ name: 'Error', message: 'an error occurred' });
|
520
|
-
* // Returns: false
|
521
|
-
* ```
|
522
|
-
*
|
523
|
-
* This method relies on `Object.prototype.toString()` behavior. It is
|
524
|
-
* possible to obtain an incorrect result when the `object` argument manipulates `@@toStringTag`.
|
525
|
-
*
|
526
|
-
* ```js
|
527
|
-
* const util = require('node:util');
|
528
|
-
* const obj = { name: 'Error', message: 'an error occurred' };
|
529
|
-
*
|
530
|
-
* util.isError(obj);
|
531
|
-
* // Returns: false
|
532
|
-
* obj[Symbol.toStringTag] = 'Error';
|
533
|
-
* util.isError(obj);
|
534
|
-
* // Returns: true
|
535
|
-
* ```
|
536
|
-
* @since v0.6.0
|
537
|
-
* @deprecated Since v4.0.0 - Use {@link types.isNativeError} instead.
|
538
|
-
*/
|
539
|
-
export function isError(object: unknown): object is Error;
|
540
|
-
/**
|
541
|
-
* Usage of `util.inherits()` is discouraged. Please use the ES6 `class` and `extends` keywords to get language level inheritance support. Also note
|
542
|
-
* that the two styles are [semantically incompatible](https://github.com/nodejs/node/issues/4179).
|
543
|
-
*
|
544
|
-
* Inherit the prototype methods from one [constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor) into another. The
|
545
|
-
* prototype of `constructor` will be set to a new object created from `superConstructor`.
|
546
|
-
*
|
547
|
-
* This mainly adds some input validation on top of`Object.setPrototypeOf(constructor.prototype, superConstructor.prototype)`.
|
548
|
-
* As an additional convenience, `superConstructor` will be accessible
|
549
|
-
* through the `constructor.super_` property.
|
550
|
-
*
|
551
|
-
* ```js
|
552
|
-
* const util = require('node:util');
|
553
|
-
* const EventEmitter = require('node:events');
|
554
|
-
*
|
555
|
-
* function MyStream() {
|
556
|
-
* EventEmitter.call(this);
|
557
|
-
* }
|
558
|
-
*
|
559
|
-
* util.inherits(MyStream, EventEmitter);
|
560
|
-
*
|
561
|
-
* MyStream.prototype.write = function(data) {
|
562
|
-
* this.emit('data', data);
|
563
|
-
* };
|
564
|
-
*
|
565
|
-
* const stream = new MyStream();
|
566
|
-
*
|
567
|
-
* console.log(stream instanceof EventEmitter); // true
|
568
|
-
* console.log(MyStream.super_ === EventEmitter); // true
|
569
|
-
*
|
570
|
-
* stream.on('data', (data) => {
|
571
|
-
* console.log(`Received data: "${data}"`);
|
572
|
-
* });
|
573
|
-
* stream.write('It works!'); // Received data: "It works!"
|
574
|
-
* ```
|
575
|
-
*
|
576
|
-
* ES6 example using `class` and `extends`:
|
577
|
-
*
|
578
|
-
* ```js
|
579
|
-
* const EventEmitter = require('node:events');
|
580
|
-
*
|
581
|
-
* class MyStream extends EventEmitter {
|
582
|
-
* write(data) {
|
583
|
-
* this.emit('data', data);
|
584
|
-
* }
|
585
|
-
* }
|
586
|
-
*
|
587
|
-
* const stream = new MyStream();
|
588
|
-
*
|
589
|
-
* stream.on('data', (data) => {
|
590
|
-
* console.log(`Received data: "${data}"`);
|
591
|
-
* });
|
592
|
-
* stream.write('With ES6');
|
593
|
-
* ```
|
594
|
-
* @since v0.3.0
|
595
|
-
* @legacy Use ES2015 class syntax and `extends` keyword instead.
|
596
|
-
*/
|
597
|
-
export function inherits(constructor: unknown, superConstructor: unknown): void;
|
598
|
-
export type DebugLoggerFunction = (msg: string, ...param: unknown[]) => void;
|
599
|
-
export interface DebugLogger extends DebugLoggerFunction {
|
600
|
-
enabled: boolean;
|
601
|
-
}
|
602
|
-
/**
|
603
|
-
* The `util.debuglog()` method is used to create a function that conditionally
|
604
|
-
* writes debug messages to `stderr` based on the existence of the `NODE_DEBUG`environment variable. If the `section` name appears within the value of that
|
605
|
-
* environment variable, then the returned function operates similar to `console.error()`. If not, then the returned function is a no-op.
|
606
|
-
*
|
607
|
-
* ```js
|
608
|
-
* const util = require('node:util');
|
609
|
-
* const debuglog = util.debuglog('foo');
|
610
|
-
*
|
611
|
-
* debuglog('hello from foo [%d]', 123);
|
612
|
-
* ```
|
613
|
-
*
|
614
|
-
* If this program is run with `NODE_DEBUG=foo` in the environment, then
|
615
|
-
* it will output something like:
|
616
|
-
*
|
617
|
-
* ```console
|
618
|
-
* FOO 3245: hello from foo [123]
|
619
|
-
* ```
|
620
|
-
*
|
621
|
-
* where `3245` is the process id. If it is not run with that
|
622
|
-
* environment variable set, then it will not print anything.
|
623
|
-
*
|
624
|
-
* The `section` supports wildcard also:
|
625
|
-
*
|
626
|
-
* ```js
|
627
|
-
* const util = require('node:util');
|
628
|
-
* const debuglog = util.debuglog('foo-bar');
|
629
|
-
*
|
630
|
-
* debuglog('hi there, it\'s foo-bar [%d]', 2333);
|
631
|
-
* ```
|
632
|
-
*
|
633
|
-
* if it is run with `NODE_DEBUG=foo*` in the environment, then it will output
|
634
|
-
* something like:
|
635
|
-
*
|
636
|
-
* ```console
|
637
|
-
* FOO-BAR 3257: hi there, it's foo-bar [2333]
|
638
|
-
* ```
|
639
|
-
*
|
640
|
-
* Multiple comma-separated `section` names may be specified in the `NODE_DEBUG`environment variable: `NODE_DEBUG=fs,net,tls`.
|
641
|
-
*
|
642
|
-
* The optional `callback` argument can be used to replace the logging function
|
643
|
-
* with a different function that doesn't have any initialization or
|
644
|
-
* unnecessary wrapping.
|
645
|
-
*
|
646
|
-
* ```js
|
647
|
-
* const util = require('node:util');
|
648
|
-
* let debuglog = util.debuglog('internals', (debug) => {
|
649
|
-
* // Replace with a logging function that optimizes out
|
650
|
-
* // testing if the section is enabled
|
651
|
-
* debuglog = debug;
|
652
|
-
* });
|
653
|
-
* ```
|
654
|
-
* @since v0.11.3
|
655
|
-
* @param section A string identifying the portion of the application for which the `debuglog` function is being created.
|
656
|
-
* @param callback A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function.
|
657
|
-
* @return The logging function
|
658
|
-
*/
|
659
|
-
export function debuglog(section: string, callback?: (fn: DebugLoggerFunction) => void): DebugLogger;
|
660
|
-
export const debug: typeof debuglog;
|
661
|
-
/**
|
662
|
-
* Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`.
|
663
|
-
*
|
664
|
-
* ```js
|
665
|
-
* const util = require('node:util');
|
666
|
-
*
|
667
|
-
* util.isBoolean(1);
|
668
|
-
* // Returns: false
|
669
|
-
* util.isBoolean(0);
|
670
|
-
* // Returns: false
|
671
|
-
* util.isBoolean(false);
|
672
|
-
* // Returns: true
|
673
|
-
* ```
|
674
|
-
* @since v0.11.5
|
675
|
-
* @deprecated Since v4.0.0 - Use `typeof value === 'boolean'` instead.
|
676
|
-
*/
|
677
|
-
export function isBoolean(object: unknown): object is boolean;
|
678
|
-
/**
|
679
|
-
* Returns `true` if the given `object` is a `Buffer`. Otherwise, returns `false`.
|
680
|
-
*
|
681
|
-
* ```js
|
682
|
-
* const util = require('node:util');
|
683
|
-
*
|
684
|
-
* util.isBuffer({ length: 0 });
|
685
|
-
* // Returns: false
|
686
|
-
* util.isBuffer([]);
|
687
|
-
* // Returns: false
|
688
|
-
* util.isBuffer(Buffer.from('hello world'));
|
689
|
-
* // Returns: true
|
690
|
-
* ```
|
691
|
-
* @since v0.11.5
|
692
|
-
* @deprecated Since v4.0.0 - Use `isBuffer` instead.
|
693
|
-
*/
|
694
|
-
export function isBuffer(object: unknown): object is Buffer;
|
695
|
-
/**
|
696
|
-
* Returns `true` if the given `object` is a `Function`. Otherwise, returns `false`.
|
697
|
-
*
|
698
|
-
* ```js
|
699
|
-
* const util = require('node:util');
|
700
|
-
*
|
701
|
-
* function Foo() {}
|
702
|
-
* const Bar = () => {};
|
703
|
-
*
|
704
|
-
* util.isFunction({});
|
705
|
-
* // Returns: false
|
706
|
-
* util.isFunction(Foo);
|
707
|
-
* // Returns: true
|
708
|
-
* util.isFunction(Bar);
|
709
|
-
* // Returns: true
|
710
|
-
* ```
|
711
|
-
* @since v0.11.5
|
712
|
-
* @deprecated Since v4.0.0 - Use `typeof value === 'function'` instead.
|
713
|
-
*/
|
714
|
-
export function isFunction(object: unknown): boolean;
|
715
|
-
/**
|
716
|
-
* Returns `true` if the given `object` is strictly `null`. Otherwise, returns`false`.
|
717
|
-
*
|
718
|
-
* ```js
|
719
|
-
* const util = require('node:util');
|
720
|
-
*
|
721
|
-
* util.isNull(0);
|
722
|
-
* // Returns: false
|
723
|
-
* util.isNull(undefined);
|
724
|
-
* // Returns: false
|
725
|
-
* util.isNull(null);
|
726
|
-
* // Returns: true
|
727
|
-
* ```
|
728
|
-
* @since v0.11.5
|
729
|
-
* @deprecated Since v4.0.0 - Use `value === null` instead.
|
730
|
-
*/
|
731
|
-
export function isNull(object: unknown): object is null;
|
732
|
-
/**
|
733
|
-
* Returns `true` if the given `object` is `null` or `undefined`. Otherwise,
|
734
|
-
* returns `false`.
|
735
|
-
*
|
736
|
-
* ```js
|
737
|
-
* const util = require('node:util');
|
738
|
-
*
|
739
|
-
* util.isNullOrUndefined(0);
|
740
|
-
* // Returns: false
|
741
|
-
* util.isNullOrUndefined(undefined);
|
742
|
-
* // Returns: true
|
743
|
-
* util.isNullOrUndefined(null);
|
744
|
-
* // Returns: true
|
745
|
-
* ```
|
746
|
-
* @since v0.11.5
|
747
|
-
* @deprecated Since v4.0.0 - Use `value === undefined || value === null` instead.
|
748
|
-
*/
|
749
|
-
export function isNullOrUndefined(object: unknown): object is null | undefined;
|
750
|
-
/**
|
751
|
-
* Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`.
|
752
|
-
*
|
753
|
-
* ```js
|
754
|
-
* const util = require('node:util');
|
755
|
-
*
|
756
|
-
* util.isNumber(false);
|
757
|
-
* // Returns: false
|
758
|
-
* util.isNumber(Infinity);
|
759
|
-
* // Returns: true
|
760
|
-
* util.isNumber(0);
|
761
|
-
* // Returns: true
|
762
|
-
* util.isNumber(NaN);
|
763
|
-
* // Returns: true
|
764
|
-
* ```
|
765
|
-
* @since v0.11.5
|
766
|
-
* @deprecated Since v4.0.0 - Use `typeof value === 'number'` instead.
|
767
|
-
*/
|
768
|
-
export function isNumber(object: unknown): object is number;
|
769
|
-
/**
|
770
|
-
* Returns `true` if the given `object` is strictly an `Object`**and** not a`Function` (even though functions are objects in JavaScript).
|
771
|
-
* Otherwise, returns `false`.
|
772
|
-
*
|
773
|
-
* ```js
|
774
|
-
* const util = require('node:util');
|
775
|
-
*
|
776
|
-
* util.isObject(5);
|
777
|
-
* // Returns: false
|
778
|
-
* util.isObject(null);
|
779
|
-
* // Returns: false
|
780
|
-
* util.isObject({});
|
781
|
-
* // Returns: true
|
782
|
-
* util.isObject(() => {});
|
783
|
-
* // Returns: false
|
784
|
-
* ```
|
785
|
-
* @since v0.11.5
|
786
|
-
* @deprecated Since v4.0.0 - Use `value !== null && typeof value === 'object'` instead.
|
787
|
-
*/
|
788
|
-
export function isObject(object: unknown): boolean;
|
789
|
-
/**
|
790
|
-
* Returns `true` if the given `object` is a primitive type. Otherwise, returns`false`.
|
791
|
-
*
|
792
|
-
* ```js
|
793
|
-
* const util = require('node:util');
|
794
|
-
*
|
795
|
-
* util.isPrimitive(5);
|
796
|
-
* // Returns: true
|
797
|
-
* util.isPrimitive('foo');
|
798
|
-
* // Returns: true
|
799
|
-
* util.isPrimitive(false);
|
800
|
-
* // Returns: true
|
801
|
-
* util.isPrimitive(null);
|
802
|
-
* // Returns: true
|
803
|
-
* util.isPrimitive(undefined);
|
804
|
-
* // Returns: true
|
805
|
-
* util.isPrimitive({});
|
806
|
-
* // Returns: false
|
807
|
-
* util.isPrimitive(() => {});
|
808
|
-
* // Returns: false
|
809
|
-
* util.isPrimitive(/^$/);
|
810
|
-
* // Returns: false
|
811
|
-
* util.isPrimitive(new Date());
|
812
|
-
* // Returns: false
|
813
|
-
* ```
|
814
|
-
* @since v0.11.5
|
815
|
-
* @deprecated Since v4.0.0 - Use `(typeof value !== 'object' && typeof value !== 'function') || value === null` instead.
|
816
|
-
*/
|
817
|
-
export function isPrimitive(object: unknown): boolean;
|
818
|
-
/**
|
819
|
-
* Returns `true` if the given `object` is a `string`. Otherwise, returns `false`.
|
820
|
-
*
|
821
|
-
* ```js
|
822
|
-
* const util = require('node:util');
|
823
|
-
*
|
824
|
-
* util.isString('');
|
825
|
-
* // Returns: true
|
826
|
-
* util.isString('foo');
|
827
|
-
* // Returns: true
|
828
|
-
* util.isString(String('foo'));
|
829
|
-
* // Returns: true
|
830
|
-
* util.isString(5);
|
831
|
-
* // Returns: false
|
832
|
-
* ```
|
833
|
-
* @since v0.11.5
|
834
|
-
* @deprecated Since v4.0.0 - Use `typeof value === 'string'` instead.
|
835
|
-
*/
|
836
|
-
export function isString(object: unknown): object is string;
|
837
|
-
/**
|
838
|
-
* Returns `true` if the given `object` is a `Symbol`. Otherwise, returns `false`.
|
839
|
-
*
|
840
|
-
* ```js
|
841
|
-
* const util = require('node:util');
|
842
|
-
*
|
843
|
-
* util.isSymbol(5);
|
844
|
-
* // Returns: false
|
845
|
-
* util.isSymbol('foo');
|
846
|
-
* // Returns: false
|
847
|
-
* util.isSymbol(Symbol('foo'));
|
848
|
-
* // Returns: true
|
849
|
-
* ```
|
850
|
-
* @since v0.11.5
|
851
|
-
* @deprecated Since v4.0.0 - Use `typeof value === 'symbol'` instead.
|
852
|
-
*/
|
853
|
-
export function isSymbol(object: unknown): object is symbol;
|
854
|
-
/**
|
855
|
-
* Returns `true` if the given `object` is `undefined`. Otherwise, returns `false`.
|
856
|
-
*
|
857
|
-
* ```js
|
858
|
-
* const util = require('node:util');
|
859
|
-
*
|
860
|
-
* const foo = undefined;
|
861
|
-
* util.isUndefined(5);
|
862
|
-
* // Returns: false
|
863
|
-
* util.isUndefined(foo);
|
864
|
-
* // Returns: true
|
865
|
-
* util.isUndefined(null);
|
866
|
-
* // Returns: false
|
867
|
-
* ```
|
868
|
-
* @since v0.11.5
|
869
|
-
* @deprecated Since v4.0.0 - Use `value === undefined` instead.
|
870
|
-
*/
|
871
|
-
export function isUndefined(object: unknown): object is undefined;
|
872
|
-
/**
|
873
|
-
* The `util.deprecate()` method wraps `fn` (which may be a function or class) in
|
874
|
-
* such a way that it is marked as deprecated.
|
875
|
-
*
|
876
|
-
* ```js
|
877
|
-
* const util = require('node:util');
|
878
|
-
*
|
879
|
-
* exports.obsoleteFunction = util.deprecate(() => {
|
880
|
-
* // Do something here.
|
881
|
-
* }, 'obsoleteFunction() is deprecated. Use newShinyFunction() instead.');
|
882
|
-
* ```
|
883
|
-
*
|
884
|
-
* When called, `util.deprecate()` will return a function that will emit a `DeprecationWarning` using the `'warning'` event. The warning will
|
885
|
-
* be emitted and printed to `stderr` the first time the returned function is
|
886
|
-
* called. After the warning is emitted, the wrapped function is called without
|
887
|
-
* emitting a warning.
|
888
|
-
*
|
889
|
-
* If the same optional `code` is supplied in multiple calls to `util.deprecate()`,
|
890
|
-
* the warning will be emitted only once for that `code`.
|
891
|
-
*
|
892
|
-
* ```js
|
893
|
-
* const util = require('node:util');
|
894
|
-
*
|
895
|
-
* const fn1 = util.deprecate(someFunction, someMessage, 'DEP0001');
|
896
|
-
* const fn2 = util.deprecate(someOtherFunction, someOtherMessage, 'DEP0001');
|
897
|
-
* fn1(); // Emits a deprecation warning with code DEP0001
|
898
|
-
* fn2(); // Does not emit a deprecation warning because it has the same code
|
899
|
-
* ```
|
900
|
-
*
|
901
|
-
* If either the `--no-deprecation` or `--no-warnings` command-line flags are
|
902
|
-
* used, or if the `process.noDeprecation` property is set to `true`_prior_ to
|
903
|
-
* the first deprecation warning, the `util.deprecate()` method does nothing.
|
904
|
-
*
|
905
|
-
* If the `--trace-deprecation` or `--trace-warnings` command-line flags are set,
|
906
|
-
* or the `process.traceDeprecation` property is set to `true`, a warning and a
|
907
|
-
* stack trace are printed to `stderr` the first time the deprecated function is
|
908
|
-
* called.
|
909
|
-
*
|
910
|
-
* If the `--throw-deprecation` command-line flag is set, or the `process.throwDeprecation` property is set to `true`, then an exception will be
|
911
|
-
* thrown when the deprecated function is called.
|
912
|
-
*
|
913
|
-
* The `--throw-deprecation` command-line flag and `process.throwDeprecation` property take precedence over `--trace-deprecation` and `process.traceDeprecation`.
|
914
|
-
* @since v0.8.0
|
915
|
-
* @param fn The function that is being deprecated.
|
916
|
-
* @param msg A warning message to display when the deprecated function is invoked.
|
917
|
-
* @param code A deprecation code. See the `list of deprecated APIs` for a list of codes.
|
918
|
-
* @return The deprecated function wrapped to emit a warning.
|
919
|
-
*/
|
920
|
-
export function deprecate<T extends Function>(fn: T, msg: string, code?: string): T;
|
921
|
-
/**
|
922
|
-
* Returns `true` if there is deep strict equality between `val1` and `val2`.
|
923
|
-
* Otherwise, returns `false`.
|
924
|
-
*
|
925
|
-
* See `assert.deepStrictEqual()` for more information about deep strict
|
926
|
-
* equality.
|
927
|
-
* @since v9.0.0
|
928
|
-
*/
|
929
|
-
export function isDeepStrictEqual(val1: unknown, val2: unknown): boolean;
|
930
|
-
/**
|
931
|
-
* Returns `str` with any ANSI escape codes removed.
|
932
|
-
*
|
933
|
-
* ```js
|
934
|
-
* console.log(util.stripVTControlCharacters('\u001B[4mvalue\u001B[0m'));
|
935
|
-
* // Prints "value"
|
936
|
-
* ```
|
937
|
-
* @since v16.11.0
|
938
|
-
*/
|
939
|
-
export function stripVTControlCharacters(str: string): string;
|
940
|
-
/**
|
941
|
-
* Takes an `async` function (or a function that returns a `Promise`) and returns a
|
942
|
-
* function following the error-first callback style, i.e. taking
|
943
|
-
* an `(err, value) => ...` callback as the last argument. In the callback, the
|
944
|
-
* first argument will be the rejection reason (or `null` if the `Promise` resolved), and the second argument will be the resolved value.
|
945
|
-
*
|
946
|
-
* ```js
|
947
|
-
* const util = require('node:util');
|
948
|
-
*
|
949
|
-
* async function fn() {
|
950
|
-
* return 'hello world';
|
951
|
-
* }
|
952
|
-
* const callbackFunction = util.callbackify(fn);
|
953
|
-
*
|
954
|
-
* callbackFunction((err, ret) => {
|
955
|
-
* if (err) throw err;
|
956
|
-
* console.log(ret);
|
957
|
-
* });
|
958
|
-
* ```
|
959
|
-
*
|
960
|
-
* Will print:
|
961
|
-
*
|
962
|
-
* ```text
|
963
|
-
* hello world
|
964
|
-
* ```
|
965
|
-
*
|
966
|
-
* The callback is executed asynchronously, and will have a limited stack trace.
|
967
|
-
* If the callback throws, the process will emit an `'uncaughtException'` event, and if not handled will exit.
|
968
|
-
*
|
969
|
-
* Since `null` has a special meaning as the first argument to a callback, if a
|
970
|
-
* wrapped function rejects a `Promise` with a falsy value as a reason, the value
|
971
|
-
* is wrapped in an `Error` with the original value stored in a field named `reason`.
|
972
|
-
*
|
973
|
-
* ```js
|
974
|
-
* function fn() {
|
975
|
-
* return Promise.reject(null);
|
976
|
-
* }
|
977
|
-
* const callbackFunction = util.callbackify(fn);
|
978
|
-
*
|
979
|
-
* callbackFunction((err, ret) => {
|
980
|
-
* // When the Promise was rejected with `null` it is wrapped with an Error and
|
981
|
-
* // the original value is stored in `reason`.
|
982
|
-
* err && Object.hasOwn(err, 'reason') && err.reason === null; // true
|
983
|
-
* });
|
984
|
-
* ```
|
985
|
-
* @since v8.2.0
|
986
|
-
* @param fn An `async` function
|
987
|
-
* @return a callback style function
|
988
|
-
*/
|
989
|
-
export function callbackify(fn: () => Promise<void>): (callback: (err: NodeJS.ErrnoException) => void) => void;
|
990
|
-
export function callbackify<TResult>(
|
991
|
-
fn: () => Promise<TResult>,
|
992
|
-
): (callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
|
993
|
-
export function callbackify<T1>(
|
994
|
-
fn: (arg1: T1) => Promise<void>,
|
995
|
-
): (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void;
|
996
|
-
export function callbackify<T1, TResult>(
|
997
|
-
fn: (arg1: T1) => Promise<TResult>,
|
998
|
-
): (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void;
|
999
|
-
export function callbackify<T1, T2>(
|
1000
|
-
fn: (arg1: T1, arg2: T2) => Promise<void>,
|
1001
|
-
): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void;
|
1002
|
-
export function callbackify<T1, T2, TResult>(
|
1003
|
-
fn: (arg1: T1, arg2: T2) => Promise<TResult>,
|
1004
|
-
): (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
|
1005
|
-
export function callbackify<T1, T2, T3>(
|
1006
|
-
fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<void>,
|
1007
|
-
): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException) => void) => void;
|
1008
|
-
export function callbackify<T1, T2, T3, TResult>(
|
1009
|
-
fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>,
|
1010
|
-
): (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException | null, result: TResult) => void) => void;
|
1011
|
-
export function callbackify<T1, T2, T3, T4>(
|
1012
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>,
|
1013
|
-
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException) => void) => void;
|
1014
|
-
export function callbackify<T1, T2, T3, T4, TResult>(
|
1015
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>,
|
1016
|
-
): (
|
1017
|
-
arg1: T1,
|
1018
|
-
arg2: T2,
|
1019
|
-
arg3: T3,
|
1020
|
-
arg4: T4,
|
1021
|
-
callback: (err: NodeJS.ErrnoException | null, result: TResult) => void,
|
1022
|
-
) => void;
|
1023
|
-
export function callbackify<T1, T2, T3, T4, T5>(
|
1024
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>,
|
1025
|
-
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException) => void) => void;
|
1026
|
-
export function callbackify<T1, T2, T3, T4, T5, TResult>(
|
1027
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>,
|
1028
|
-
): (
|
1029
|
-
arg1: T1,
|
1030
|
-
arg2: T2,
|
1031
|
-
arg3: T3,
|
1032
|
-
arg4: T4,
|
1033
|
-
arg5: T5,
|
1034
|
-
callback: (err: NodeJS.ErrnoException | null, result: TResult) => void,
|
1035
|
-
) => void;
|
1036
|
-
export function callbackify<T1, T2, T3, T4, T5, T6>(
|
1037
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>,
|
1038
|
-
): (
|
1039
|
-
arg1: T1,
|
1040
|
-
arg2: T2,
|
1041
|
-
arg3: T3,
|
1042
|
-
arg4: T4,
|
1043
|
-
arg5: T5,
|
1044
|
-
arg6: T6,
|
1045
|
-
callback: (err: NodeJS.ErrnoException) => void,
|
1046
|
-
) => void;
|
1047
|
-
export function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
|
1048
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>,
|
1049
|
-
): (
|
1050
|
-
arg1: T1,
|
1051
|
-
arg2: T2,
|
1052
|
-
arg3: T3,
|
1053
|
-
arg4: T4,
|
1054
|
-
arg5: T5,
|
1055
|
-
arg6: T6,
|
1056
|
-
callback: (err: NodeJS.ErrnoException | null, result: TResult) => void,
|
1057
|
-
) => void;
|
1058
|
-
export interface CustomPromisifyLegacy<TCustom extends Function> extends Function {
|
1059
|
-
__promisify__: TCustom;
|
1060
|
-
}
|
1061
|
-
export interface CustomPromisifySymbol<TCustom extends Function> extends Function {
|
1062
|
-
[promisify.custom]: TCustom;
|
1063
|
-
}
|
1064
|
-
export type CustomPromisify<TCustom extends Function> =
|
1065
|
-
| CustomPromisifySymbol<TCustom>
|
1066
|
-
| CustomPromisifyLegacy<TCustom>;
|
1067
|
-
/**
|
1068
|
-
* Takes a function following the common error-first callback style, i.e. taking
|
1069
|
-
* an `(err, value) => ...` callback as the last argument, and returns a version
|
1070
|
-
* that returns promises.
|
1071
|
-
*
|
1072
|
-
* ```js
|
1073
|
-
* const util = require('node:util');
|
1074
|
-
* const fs = require('node:fs');
|
1075
|
-
*
|
1076
|
-
* const stat = util.promisify(fs.stat);
|
1077
|
-
* stat('.').then((stats) => {
|
1078
|
-
* // Do something with `stats`
|
1079
|
-
* }).catch((error) => {
|
1080
|
-
* // Handle the error.
|
1081
|
-
* });
|
1082
|
-
* ```
|
1083
|
-
*
|
1084
|
-
* Or, equivalently using `async function`s:
|
1085
|
-
*
|
1086
|
-
* ```js
|
1087
|
-
* const util = require('node:util');
|
1088
|
-
* const fs = require('node:fs');
|
1089
|
-
*
|
1090
|
-
* const stat = util.promisify(fs.stat);
|
1091
|
-
*
|
1092
|
-
* async function callStat() {
|
1093
|
-
* const stats = await stat('.');
|
1094
|
-
* console.log(`This directory is owned by ${stats.uid}`);
|
1095
|
-
* }
|
1096
|
-
*
|
1097
|
-
* callStat();
|
1098
|
-
* ```
|
1099
|
-
*
|
1100
|
-
* If there is an `original[util.promisify.custom]` property present, `promisify` will return its value, see `Custom promisified functions`.
|
1101
|
-
*
|
1102
|
-
* `promisify()` assumes that `original` is a function taking a callback as its
|
1103
|
-
* final argument in all cases. If `original` is not a function, `promisify()` will throw an error. If `original` is a function but its last argument is not
|
1104
|
-
* an error-first callback, it will still be passed an error-first
|
1105
|
-
* callback as its last argument.
|
1106
|
-
*
|
1107
|
-
* Using `promisify()` on class methods or other methods that use `this` may not
|
1108
|
-
* work as expected unless handled specially:
|
1109
|
-
*
|
1110
|
-
* ```js
|
1111
|
-
* const util = require('node:util');
|
1112
|
-
*
|
1113
|
-
* class Foo {
|
1114
|
-
* constructor() {
|
1115
|
-
* this.a = 42;
|
1116
|
-
* }
|
1117
|
-
*
|
1118
|
-
* bar(callback) {
|
1119
|
-
* callback(null, this.a);
|
1120
|
-
* }
|
1121
|
-
* }
|
1122
|
-
*
|
1123
|
-
* const foo = new Foo();
|
1124
|
-
*
|
1125
|
-
* const naiveBar = util.promisify(foo.bar);
|
1126
|
-
* // TypeError: Cannot read property 'a' of undefined
|
1127
|
-
* // naiveBar().then(a => console.log(a));
|
1128
|
-
*
|
1129
|
-
* naiveBar.call(foo).then((a) => console.log(a)); // '42'
|
1130
|
-
*
|
1131
|
-
* const bindBar = naiveBar.bind(foo);
|
1132
|
-
* bindBar().then((a) => console.log(a)); // '42'
|
1133
|
-
* ```
|
1134
|
-
* @since v8.0.0
|
1135
|
-
*/
|
1136
|
-
export function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
|
1137
|
-
export function promisify<TResult>(
|
1138
|
-
fn: (callback: (err: any, result: TResult) => void) => void,
|
1139
|
-
): () => Promise<TResult>;
|
1140
|
-
export function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
|
1141
|
-
export function promisify<T1, TResult>(
|
1142
|
-
fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void,
|
1143
|
-
): (arg1: T1) => Promise<TResult>;
|
1144
|
-
export function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
|
1145
|
-
export function promisify<T1, T2, TResult>(
|
1146
|
-
fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void,
|
1147
|
-
): (arg1: T1, arg2: T2) => Promise<TResult>;
|
1148
|
-
export function promisify<T1, T2>(
|
1149
|
-
fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void,
|
1150
|
-
): (arg1: T1, arg2: T2) => Promise<void>;
|
1151
|
-
export function promisify<T1, T2, T3, TResult>(
|
1152
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void,
|
1153
|
-
): (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
|
1154
|
-
export function promisify<T1, T2, T3>(
|
1155
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err?: any) => void) => void,
|
1156
|
-
): (arg1: T1, arg2: T2, arg3: T3) => Promise<void>;
|
1157
|
-
export function promisify<T1, T2, T3, T4, TResult>(
|
1158
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void,
|
1159
|
-
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
|
1160
|
-
export function promisify<T1, T2, T3, T4>(
|
1161
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void,
|
1162
|
-
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
|
1163
|
-
export function promisify<T1, T2, T3, T4, T5, TResult>(
|
1164
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void,
|
1165
|
-
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
|
1166
|
-
export function promisify<T1, T2, T3, T4, T5>(
|
1167
|
-
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void,
|
1168
|
-
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
|
1169
|
-
export function promisify(fn: Function): Function;
|
1170
|
-
export namespace promisify {
|
1171
|
-
/**
|
1172
|
-
* That can be used to declare custom promisified variants of functions.
|
1173
|
-
*/
|
1174
|
-
const custom: unique symbol;
|
1175
|
-
}
|
1176
|
-
/**
|
1177
|
-
* Stability: 1.1 - Active development
|
1178
|
-
* Given an example `.env` file:
|
1179
|
-
*
|
1180
|
-
* ```js
|
1181
|
-
* const { parseEnv } = require('node:util');
|
1182
|
-
*
|
1183
|
-
* parseEnv('HELLO=world\nHELLO=oh my\n');
|
1184
|
-
* // Returns: { HELLO: 'oh my' }
|
1185
|
-
* ```
|
1186
|
-
* @param content The raw contents of a `.env` file.
|
1187
|
-
* @since v20.12.0
|
1188
|
-
*/
|
1189
|
-
export function parseEnv(content: string): object;
|
1190
|
-
// https://nodejs.org/docs/latest/api/util.html#foreground-colors
|
1191
|
-
type ForegroundColors =
|
1192
|
-
| "black"
|
1193
|
-
| "blackBright"
|
1194
|
-
| "blue"
|
1195
|
-
| "blueBright"
|
1196
|
-
| "cyan"
|
1197
|
-
| "cyanBright"
|
1198
|
-
| "gray"
|
1199
|
-
| "green"
|
1200
|
-
| "greenBright"
|
1201
|
-
| "grey"
|
1202
|
-
| "magenta"
|
1203
|
-
| "magentaBright"
|
1204
|
-
| "red"
|
1205
|
-
| "redBright"
|
1206
|
-
| "white"
|
1207
|
-
| "whiteBright"
|
1208
|
-
| "yellow"
|
1209
|
-
| "yellowBright";
|
1210
|
-
// https://nodejs.org/docs/latest/api/util.html#background-colors
|
1211
|
-
type BackgroundColors =
|
1212
|
-
| "bgBlack"
|
1213
|
-
| "bgBlackBright"
|
1214
|
-
| "bgBlue"
|
1215
|
-
| "bgBlueBright"
|
1216
|
-
| "bgCyan"
|
1217
|
-
| "bgCyanBright"
|
1218
|
-
| "bgGray"
|
1219
|
-
| "bgGreen"
|
1220
|
-
| "bgGreenBright"
|
1221
|
-
| "bgGrey"
|
1222
|
-
| "bgMagenta"
|
1223
|
-
| "bgMagentaBright"
|
1224
|
-
| "bgRed"
|
1225
|
-
| "bgRedBright"
|
1226
|
-
| "bgWhite"
|
1227
|
-
| "bgWhiteBright"
|
1228
|
-
| "bgYellow"
|
1229
|
-
| "bgYellowBright";
|
1230
|
-
// https://nodejs.org/docs/latest/api/util.html#modifiers
|
1231
|
-
type Modifiers =
|
1232
|
-
| "blink"
|
1233
|
-
| "bold"
|
1234
|
-
| "dim"
|
1235
|
-
| "doubleunderline"
|
1236
|
-
| "framed"
|
1237
|
-
| "hidden"
|
1238
|
-
| "inverse"
|
1239
|
-
| "italic"
|
1240
|
-
| "overlined"
|
1241
|
-
| "reset"
|
1242
|
-
| "strikethrough"
|
1243
|
-
| "underline";
|
1244
|
-
/**
|
1245
|
-
* Stability: 1.1 - Active development
|
1246
|
-
*
|
1247
|
-
* This function returns a formatted text considering the `format` passed.
|
1248
|
-
*
|
1249
|
-
* ```js
|
1250
|
-
* const { styleText } = require('node:util');
|
1251
|
-
* const errorMessage = styleText('red', 'Error! Error!');
|
1252
|
-
* console.log(errorMessage);
|
1253
|
-
* ```
|
1254
|
-
*
|
1255
|
-
* `util.inspect.colors` also provides text formats such as `italic`, and `underline` and you can combine both:
|
1256
|
-
*
|
1257
|
-
* ```js
|
1258
|
-
* console.log(
|
1259
|
-
* util.styleText(['underline', 'italic'], 'My italic underlined message'),
|
1260
|
-
* );
|
1261
|
-
* ```
|
1262
|
-
*
|
1263
|
-
* When passing an array of formats, the order of the format applied is left to right so the following style
|
1264
|
-
* might overwrite the previous one.
|
1265
|
-
*
|
1266
|
-
* ```js
|
1267
|
-
* console.log(
|
1268
|
-
* util.styleText(['red', 'green'], 'text'), // green
|
1269
|
-
* );
|
1270
|
-
* ```
|
1271
|
-
*
|
1272
|
-
* The full list of formats can be found in [modifiers](https://nodejs.org/docs/latest-v20.x/api/util.html#modifiers).
|
1273
|
-
* @param format A text format or an Array of text formats defined in `util.inspect.colors`.
|
1274
|
-
* @param text The text to to be formatted.
|
1275
|
-
* @since v20.12.0
|
1276
|
-
*/
|
1277
|
-
export function styleText(
|
1278
|
-
format:
|
1279
|
-
| ForegroundColors
|
1280
|
-
| BackgroundColors
|
1281
|
-
| Modifiers
|
1282
|
-
| Array<ForegroundColors | BackgroundColors | Modifiers>,
|
1283
|
-
text: string,
|
1284
|
-
): string;
|
1285
|
-
/**
|
1286
|
-
* An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextDecoder` API.
|
1287
|
-
*
|
1288
|
-
* ```js
|
1289
|
-
* const decoder = new TextDecoder();
|
1290
|
-
* const u8arr = new Uint8Array([72, 101, 108, 108, 111]);
|
1291
|
-
* console.log(decoder.decode(u8arr)); // Hello
|
1292
|
-
* ```
|
1293
|
-
* @since v8.3.0
|
1294
|
-
*/
|
1295
|
-
export class TextDecoder {
|
1296
|
-
/**
|
1297
|
-
* The encoding supported by the `TextDecoder` instance.
|
1298
|
-
*/
|
1299
|
-
readonly encoding: string;
|
1300
|
-
/**
|
1301
|
-
* The value will be `true` if decoding errors result in a `TypeError` being
|
1302
|
-
* thrown.
|
1303
|
-
*/
|
1304
|
-
readonly fatal: boolean;
|
1305
|
-
/**
|
1306
|
-
* The value will be `true` if the decoding result will include the byte order
|
1307
|
-
* mark.
|
1308
|
-
*/
|
1309
|
-
readonly ignoreBOM: boolean;
|
1310
|
-
constructor(
|
1311
|
-
encoding?: string,
|
1312
|
-
options?: {
|
1313
|
-
fatal?: boolean | undefined;
|
1314
|
-
ignoreBOM?: boolean | undefined;
|
1315
|
-
},
|
1316
|
-
);
|
1317
|
-
/**
|
1318
|
-
* Decodes the `input` and returns a string. If `options.stream` is `true`, any
|
1319
|
-
* incomplete byte sequences occurring at the end of the `input` are buffered
|
1320
|
-
* internally and emitted after the next call to `textDecoder.decode()`.
|
1321
|
-
*
|
1322
|
-
* If `textDecoder.fatal` is `true`, decoding errors that occur will result in a `TypeError` being thrown.
|
1323
|
-
* @param input An `ArrayBuffer`, `DataView`, or `TypedArray` instance containing the encoded data.
|
1324
|
-
*/
|
1325
|
-
decode(
|
1326
|
-
input?: NodeJS.ArrayBufferView | ArrayBuffer | null,
|
1327
|
-
options?: {
|
1328
|
-
stream?: boolean | undefined;
|
1329
|
-
},
|
1330
|
-
): string;
|
1331
|
-
}
|
1332
|
-
export interface EncodeIntoResult {
|
1333
|
-
/**
|
1334
|
-
* The read Unicode code units of input.
|
1335
|
-
*/
|
1336
|
-
read: number;
|
1337
|
-
/**
|
1338
|
-
* The written UTF-8 bytes of output.
|
1339
|
-
*/
|
1340
|
-
written: number;
|
1341
|
-
}
|
1342
|
-
export { types };
|
1343
|
-
|
1344
|
-
//// TextEncoder/Decoder
|
1345
|
-
/**
|
1346
|
-
* An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextEncoder` API. All
|
1347
|
-
* instances of `TextEncoder` only support UTF-8 encoding.
|
1348
|
-
*
|
1349
|
-
* ```js
|
1350
|
-
* const encoder = new TextEncoder();
|
1351
|
-
* const uint8array = encoder.encode('this is some data');
|
1352
|
-
* ```
|
1353
|
-
*
|
1354
|
-
* The `TextEncoder` class is also available on the global object.
|
1355
|
-
* @since v8.3.0
|
1356
|
-
*/
|
1357
|
-
export class TextEncoder {
|
1358
|
-
/**
|
1359
|
-
* The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`.
|
1360
|
-
*/
|
1361
|
-
readonly encoding: string;
|
1362
|
-
/**
|
1363
|
-
* UTF-8 encodes the `input` string and returns a `Uint8Array` containing the
|
1364
|
-
* encoded bytes.
|
1365
|
-
* @param [input='an empty string'] The text to encode.
|
1366
|
-
*/
|
1367
|
-
encode(input?: string): Uint8Array;
|
1368
|
-
/**
|
1369
|
-
* UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object
|
1370
|
-
* containing the read Unicode code units and written UTF-8 bytes.
|
1371
|
-
*
|
1372
|
-
* ```js
|
1373
|
-
* const encoder = new TextEncoder();
|
1374
|
-
* const src = 'this is some data';
|
1375
|
-
* const dest = new Uint8Array(10);
|
1376
|
-
* const { read, written } = encoder.encodeInto(src, dest);
|
1377
|
-
* ```
|
1378
|
-
* @param src The text to encode.
|
1379
|
-
* @param dest The array to hold the encode result.
|
1380
|
-
*/
|
1381
|
-
encodeInto(src: string, dest: Uint8Array): EncodeIntoResult;
|
1382
|
-
}
|
1383
|
-
import { TextDecoder as _TextDecoder, TextEncoder as _TextEncoder } from "util";
|
1384
|
-
global {
|
1385
|
-
/**
|
1386
|
-
* `TextDecoder` class is a global reference for `require('util').TextDecoder`
|
1387
|
-
* https://nodejs.org/api/globals.html#textdecoder
|
1388
|
-
* @since v11.0.0
|
1389
|
-
*/
|
1390
|
-
var TextDecoder: typeof globalThis extends {
|
1391
|
-
onmessage: any;
|
1392
|
-
TextDecoder: infer TextDecoder;
|
1393
|
-
} ? TextDecoder
|
1394
|
-
: typeof _TextDecoder;
|
1395
|
-
/**
|
1396
|
-
* `TextEncoder` class is a global reference for `require('util').TextEncoder`
|
1397
|
-
* https://nodejs.org/api/globals.html#textencoder
|
1398
|
-
* @since v11.0.0
|
1399
|
-
*/
|
1400
|
-
var TextEncoder: typeof globalThis extends {
|
1401
|
-
onmessage: any;
|
1402
|
-
TextEncoder: infer TextEncoder;
|
1403
|
-
} ? TextEncoder
|
1404
|
-
: typeof _TextEncoder;
|
1405
|
-
}
|
1406
|
-
|
1407
|
-
//// parseArgs
|
1408
|
-
/**
|
1409
|
-
* Provides a higher level API for command-line argument parsing than interacting
|
1410
|
-
* with `process.argv` directly. Takes a specification for the expected arguments
|
1411
|
-
* and returns a structured object with the parsed options and positionals.
|
1412
|
-
*
|
1413
|
-
* ```js
|
1414
|
-
* import { parseArgs } from 'node:util';
|
1415
|
-
* const args = ['-f', '--bar', 'b'];
|
1416
|
-
* const options = {
|
1417
|
-
* foo: {
|
1418
|
-
* type: 'boolean',
|
1419
|
-
* short: 'f',
|
1420
|
-
* },
|
1421
|
-
* bar: {
|
1422
|
-
* type: 'string',
|
1423
|
-
* },
|
1424
|
-
* };
|
1425
|
-
* const {
|
1426
|
-
* values,
|
1427
|
-
* positionals,
|
1428
|
-
* } = parseArgs({ args, options });
|
1429
|
-
* console.log(values, positionals);
|
1430
|
-
* // Prints: [Object: null prototype] { foo: true, bar: 'b' } []
|
1431
|
-
* ```
|
1432
|
-
* @since v18.3.0, v16.17.0
|
1433
|
-
* @param config Used to provide arguments for parsing and to configure the parser. `config` supports the following properties:
|
1434
|
-
* @return The parsed command line arguments:
|
1435
|
-
*/
|
1436
|
-
export function parseArgs<T extends ParseArgsConfig>(config?: T): ParsedResults<T>;
|
1437
|
-
interface ParseArgsOptionConfig {
|
1438
|
-
/**
|
1439
|
-
* Type of argument.
|
1440
|
-
*/
|
1441
|
-
type: "string" | "boolean";
|
1442
|
-
/**
|
1443
|
-
* Whether this option can be provided multiple times.
|
1444
|
-
* If `true`, all values will be collected in an array.
|
1445
|
-
* If `false`, values for the option are last-wins.
|
1446
|
-
* @default false.
|
1447
|
-
*/
|
1448
|
-
multiple?: boolean | undefined;
|
1449
|
-
/**
|
1450
|
-
* A single character alias for the option.
|
1451
|
-
*/
|
1452
|
-
short?: string | undefined;
|
1453
|
-
/**
|
1454
|
-
* The default option value when it is not set by args.
|
1455
|
-
* It must be of the same type as the the `type` property.
|
1456
|
-
* When `multiple` is `true`, it must be an array.
|
1457
|
-
* @since v18.11.0
|
1458
|
-
*/
|
1459
|
-
default?: string | boolean | string[] | boolean[] | undefined;
|
1460
|
-
}
|
1461
|
-
interface ParseArgsOptionsConfig {
|
1462
|
-
[longOption: string]: ParseArgsOptionConfig;
|
1463
|
-
}
|
1464
|
-
export interface ParseArgsConfig {
|
1465
|
-
/**
|
1466
|
-
* Array of argument strings.
|
1467
|
-
*/
|
1468
|
-
args?: string[] | undefined;
|
1469
|
-
/**
|
1470
|
-
* Used to describe arguments known to the parser.
|
1471
|
-
*/
|
1472
|
-
options?: ParseArgsOptionsConfig | undefined;
|
1473
|
-
/**
|
1474
|
-
* Should an error be thrown when unknown arguments are encountered,
|
1475
|
-
* or when arguments are passed that do not match the `type` configured in `options`.
|
1476
|
-
* @default true
|
1477
|
-
*/
|
1478
|
-
strict?: boolean | undefined;
|
1479
|
-
/**
|
1480
|
-
* Whether this command accepts positional arguments.
|
1481
|
-
*/
|
1482
|
-
allowPositionals?: boolean | undefined;
|
1483
|
-
/**
|
1484
|
-
* Return the parsed tokens. This is useful for extending the built-in behavior,
|
1485
|
-
* from adding additional checks through to reprocessing the tokens in different ways.
|
1486
|
-
* @default false
|
1487
|
-
*/
|
1488
|
-
tokens?: boolean | undefined;
|
1489
|
-
}
|
1490
|
-
/*
|
1491
|
-
IfDefaultsTrue and IfDefaultsFalse are helpers to handle default values for missing boolean properties.
|
1492
|
-
TypeScript does not have exact types for objects: https://github.com/microsoft/TypeScript/issues/12936
|
1493
|
-
This means it is impossible to distinguish between "field X is definitely not present" and "field X may or may not be present".
|
1494
|
-
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.
|
1495
|
-
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.
|
1496
|
-
This is technically incorrect but is a much nicer UX for the common case.
|
1497
|
-
The IfDefaultsTrue version is for things which default to true; the IfDefaultsFalse version is for things which default to false.
|
1498
|
-
*/
|
1499
|
-
type IfDefaultsTrue<T, IfTrue, IfFalse> = T extends true ? IfTrue
|
1500
|
-
: T extends false ? IfFalse
|
1501
|
-
: IfTrue;
|
1502
|
-
|
1503
|
-
// we put the `extends false` condition first here because `undefined` compares like `any` when `strictNullChecks: false`
|
1504
|
-
type IfDefaultsFalse<T, IfTrue, IfFalse> = T extends false ? IfFalse
|
1505
|
-
: T extends true ? IfTrue
|
1506
|
-
: IfFalse;
|
1507
|
-
|
1508
|
-
type ExtractOptionValue<T extends ParseArgsConfig, O extends ParseArgsOptionConfig> = IfDefaultsTrue<
|
1509
|
-
T["strict"],
|
1510
|
-
O["type"] extends "string" ? string : O["type"] extends "boolean" ? boolean : string | boolean,
|
1511
|
-
string | boolean
|
1512
|
-
>;
|
1513
|
-
|
1514
|
-
type ParsedValues<T extends ParseArgsConfig> =
|
1515
|
-
& IfDefaultsTrue<T["strict"], unknown, { [longOption: string]: undefined | string | boolean }>
|
1516
|
-
& (T["options"] extends ParseArgsOptionsConfig ? {
|
1517
|
-
-readonly [LongOption in keyof T["options"]]: IfDefaultsFalse<
|
1518
|
-
T["options"][LongOption]["multiple"],
|
1519
|
-
undefined | Array<ExtractOptionValue<T, T["options"][LongOption]>>,
|
1520
|
-
undefined | ExtractOptionValue<T, T["options"][LongOption]>
|
1521
|
-
>;
|
1522
|
-
}
|
1523
|
-
: {});
|
1524
|
-
|
1525
|
-
type ParsedPositionals<T extends ParseArgsConfig> = IfDefaultsTrue<
|
1526
|
-
T["strict"],
|
1527
|
-
IfDefaultsFalse<T["allowPositionals"], string[], []>,
|
1528
|
-
IfDefaultsTrue<T["allowPositionals"], string[], []>
|
1529
|
-
>;
|
1530
|
-
|
1531
|
-
type PreciseTokenForOptions<
|
1532
|
-
K extends string,
|
1533
|
-
O extends ParseArgsOptionConfig,
|
1534
|
-
> = O["type"] extends "string" ? {
|
1535
|
-
kind: "option";
|
1536
|
-
index: number;
|
1537
|
-
name: K;
|
1538
|
-
rawName: string;
|
1539
|
-
value: string;
|
1540
|
-
inlineValue: boolean;
|
1541
|
-
}
|
1542
|
-
: O["type"] extends "boolean" ? {
|
1543
|
-
kind: "option";
|
1544
|
-
index: number;
|
1545
|
-
name: K;
|
1546
|
-
rawName: string;
|
1547
|
-
value: undefined;
|
1548
|
-
inlineValue: undefined;
|
1549
|
-
}
|
1550
|
-
: OptionToken & { name: K };
|
1551
|
-
|
1552
|
-
type TokenForOptions<
|
1553
|
-
T extends ParseArgsConfig,
|
1554
|
-
K extends keyof T["options"] = keyof T["options"],
|
1555
|
-
> = K extends unknown
|
1556
|
-
? T["options"] extends ParseArgsOptionsConfig ? PreciseTokenForOptions<K & string, T["options"][K]>
|
1557
|
-
: OptionToken
|
1558
|
-
: never;
|
1559
|
-
|
1560
|
-
type ParsedOptionToken<T extends ParseArgsConfig> = IfDefaultsTrue<T["strict"], TokenForOptions<T>, OptionToken>;
|
1561
|
-
|
1562
|
-
type ParsedPositionalToken<T extends ParseArgsConfig> = IfDefaultsTrue<
|
1563
|
-
T["strict"],
|
1564
|
-
IfDefaultsFalse<T["allowPositionals"], { kind: "positional"; index: number; value: string }, never>,
|
1565
|
-
IfDefaultsTrue<T["allowPositionals"], { kind: "positional"; index: number; value: string }, never>
|
1566
|
-
>;
|
1567
|
-
|
1568
|
-
type ParsedTokens<T extends ParseArgsConfig> = Array<
|
1569
|
-
ParsedOptionToken<T> | ParsedPositionalToken<T> | { kind: "option-terminator"; index: number }
|
1570
|
-
>;
|
1571
|
-
|
1572
|
-
type PreciseParsedResults<T extends ParseArgsConfig> = IfDefaultsFalse<
|
1573
|
-
T["tokens"],
|
1574
|
-
{
|
1575
|
-
values: ParsedValues<T>;
|
1576
|
-
positionals: ParsedPositionals<T>;
|
1577
|
-
tokens: ParsedTokens<T>;
|
1578
|
-
},
|
1579
|
-
{
|
1580
|
-
values: ParsedValues<T>;
|
1581
|
-
positionals: ParsedPositionals<T>;
|
1582
|
-
}
|
1583
|
-
>;
|
1584
|
-
|
1585
|
-
type OptionToken =
|
1586
|
-
| { kind: "option"; index: number; name: string; rawName: string; value: string; inlineValue: boolean }
|
1587
|
-
| {
|
1588
|
-
kind: "option";
|
1589
|
-
index: number;
|
1590
|
-
name: string;
|
1591
|
-
rawName: string;
|
1592
|
-
value: undefined;
|
1593
|
-
inlineValue: undefined;
|
1594
|
-
};
|
1595
|
-
|
1596
|
-
type Token =
|
1597
|
-
| OptionToken
|
1598
|
-
| { kind: "positional"; index: number; value: string }
|
1599
|
-
| { kind: "option-terminator"; index: number };
|
1600
|
-
|
1601
|
-
// If ParseArgsConfig extends T, then the user passed config constructed elsewhere.
|
1602
|
-
// So we can't rely on the `"not definitely present" implies "definitely not present"` assumption mentioned above.
|
1603
|
-
type ParsedResults<T extends ParseArgsConfig> = ParseArgsConfig extends T ? {
|
1604
|
-
values: {
|
1605
|
-
[longOption: string]: undefined | string | boolean | Array<string | boolean>;
|
1606
|
-
};
|
1607
|
-
positionals: string[];
|
1608
|
-
tokens?: Token[];
|
1609
|
-
}
|
1610
|
-
: PreciseParsedResults<T>;
|
1611
|
-
|
1612
|
-
/**
|
1613
|
-
* An implementation of [the MIMEType class](https://bmeck.github.io/node-proposal-mime-api/).
|
1614
|
-
*
|
1615
|
-
* In accordance with browser conventions, all properties of `MIMEType` objects
|
1616
|
-
* are implemented as getters and setters on the class prototype, rather than as
|
1617
|
-
* data properties on the object itself.
|
1618
|
-
*
|
1619
|
-
* A MIME string is a structured string containing multiple meaningful
|
1620
|
-
* components. When parsed, a `MIMEType` object is returned containing
|
1621
|
-
* properties for each of these components.
|
1622
|
-
* @since v19.1.0, v18.13.0
|
1623
|
-
* @experimental
|
1624
|
-
*/
|
1625
|
-
export class MIMEType {
|
1626
|
-
/**
|
1627
|
-
* Creates a new MIMEType object by parsing the input.
|
1628
|
-
*
|
1629
|
-
* A `TypeError` will be thrown if the `input` is not a valid MIME.
|
1630
|
-
* Note that an effort will be made to coerce the given values into strings.
|
1631
|
-
* @param input The input MIME to parse.
|
1632
|
-
*/
|
1633
|
-
constructor(input: string | { toString: () => string });
|
1634
|
-
|
1635
|
-
/**
|
1636
|
-
* Gets and sets the type portion of the MIME.
|
1637
|
-
*
|
1638
|
-
* ```js
|
1639
|
-
* import { MIMEType } from 'node:util';
|
1640
|
-
*
|
1641
|
-
* const myMIME = new MIMEType('text/javascript');
|
1642
|
-
* console.log(myMIME.type);
|
1643
|
-
* // Prints: text
|
1644
|
-
* myMIME.type = 'application';
|
1645
|
-
* console.log(myMIME.type);
|
1646
|
-
* // Prints: application
|
1647
|
-
* console.log(String(myMIME));
|
1648
|
-
* // Prints: application/javascript
|
1649
|
-
* ```
|
1650
|
-
*/
|
1651
|
-
type: string;
|
1652
|
-
/**
|
1653
|
-
* Gets and sets the subtype portion of the MIME.
|
1654
|
-
*
|
1655
|
-
* ```js
|
1656
|
-
* import { MIMEType } from 'node:util';
|
1657
|
-
*
|
1658
|
-
* const myMIME = new MIMEType('text/ecmascript');
|
1659
|
-
* console.log(myMIME.subtype);
|
1660
|
-
* // Prints: ecmascript
|
1661
|
-
* myMIME.subtype = 'javascript';
|
1662
|
-
* console.log(myMIME.subtype);
|
1663
|
-
* // Prints: javascript
|
1664
|
-
* console.log(String(myMIME));
|
1665
|
-
* // Prints: text/javascript
|
1666
|
-
* ```
|
1667
|
-
*/
|
1668
|
-
subtype: string;
|
1669
|
-
/**
|
1670
|
-
* Gets the essence of the MIME. This property is read only.
|
1671
|
-
* Use `mime.type` or `mime.subtype` to alter the MIME.
|
1672
|
-
*
|
1673
|
-
* ```js
|
1674
|
-
* import { MIMEType } from 'node:util';
|
1675
|
-
*
|
1676
|
-
* const myMIME = new MIMEType('text/javascript;key=value');
|
1677
|
-
* console.log(myMIME.essence);
|
1678
|
-
* // Prints: text/javascript
|
1679
|
-
* myMIME.type = 'application';
|
1680
|
-
* console.log(myMIME.essence);
|
1681
|
-
* // Prints: application/javascript
|
1682
|
-
* console.log(String(myMIME));
|
1683
|
-
* // Prints: application/javascript;key=value
|
1684
|
-
* ```
|
1685
|
-
*/
|
1686
|
-
readonly essence: string;
|
1687
|
-
/**
|
1688
|
-
* Gets the `MIMEParams` object representing the
|
1689
|
-
* parameters of the MIME. This property is read-only. See `MIMEParams` documentation for details.
|
1690
|
-
*/
|
1691
|
-
readonly params: MIMEParams;
|
1692
|
-
/**
|
1693
|
-
* The `toString()` method on the `MIMEType` object returns the serialized MIME.
|
1694
|
-
*
|
1695
|
-
* Because of the need for standard compliance, this method does not allow users
|
1696
|
-
* to customize the serialization process of the MIME.
|
1697
|
-
*/
|
1698
|
-
toString(): string;
|
1699
|
-
}
|
1700
|
-
/**
|
1701
|
-
* The `MIMEParams` API provides read and write access to the parameters of a `MIMEType`.
|
1702
|
-
* @since v19.1.0, v18.13.0
|
1703
|
-
*/
|
1704
|
-
export class MIMEParams {
|
1705
|
-
/**
|
1706
|
-
* Remove all name-value pairs whose name is `name`.
|
1707
|
-
*/
|
1708
|
-
delete(name: string): void;
|
1709
|
-
/**
|
1710
|
-
* Returns an iterator over each of the name-value pairs in the parameters.
|
1711
|
-
* Each item of the iterator is a JavaScript `Array`. The first item of the array
|
1712
|
-
* is the `name`, the second item of the array is the `value`.
|
1713
|
-
*/
|
1714
|
-
entries(): IterableIterator<[name: string, value: string]>;
|
1715
|
-
/**
|
1716
|
-
* Returns the value of the first name-value pair whose name is `name`. If there
|
1717
|
-
* are no such pairs, `null` is returned.
|
1718
|
-
* @return or `null` if there is no name-value pair with the given `name`.
|
1719
|
-
*/
|
1720
|
-
get(name: string): string | null;
|
1721
|
-
/**
|
1722
|
-
* Returns `true` if there is at least one name-value pair whose name is `name`.
|
1723
|
-
*/
|
1724
|
-
has(name: string): boolean;
|
1725
|
-
/**
|
1726
|
-
* Returns an iterator over the names of each name-value pair.
|
1727
|
-
*
|
1728
|
-
* ```js
|
1729
|
-
* import { MIMEType } from 'node:util';
|
1730
|
-
*
|
1731
|
-
* const { params } = new MIMEType('text/plain;foo=0;bar=1');
|
1732
|
-
* for (const name of params.keys()) {
|
1733
|
-
* console.log(name);
|
1734
|
-
* }
|
1735
|
-
* // Prints:
|
1736
|
-
* // foo
|
1737
|
-
* // bar
|
1738
|
-
* ```
|
1739
|
-
*/
|
1740
|
-
keys(): IterableIterator<string>;
|
1741
|
-
/**
|
1742
|
-
* Sets the value in the `MIMEParams` object associated with `name` to `value`. If there are any pre-existing name-value pairs whose names are `name`,
|
1743
|
-
* set the first such pair's value to `value`.
|
1744
|
-
*
|
1745
|
-
* ```js
|
1746
|
-
* import { MIMEType } from 'node:util';
|
1747
|
-
*
|
1748
|
-
* const { params } = new MIMEType('text/plain;foo=0;bar=1');
|
1749
|
-
* params.set('foo', 'def');
|
1750
|
-
* params.set('baz', 'xyz');
|
1751
|
-
* console.log(params.toString());
|
1752
|
-
* // Prints: foo=def;bar=1;baz=xyz
|
1753
|
-
* ```
|
1754
|
-
*/
|
1755
|
-
set(name: string, value: string): void;
|
1756
|
-
/**
|
1757
|
-
* Returns an iterator over the values of each name-value pair.
|
1758
|
-
*/
|
1759
|
-
values(): IterableIterator<string>;
|
1760
|
-
/**
|
1761
|
-
* Returns an iterator over each of the name-value pairs in the parameters.
|
1762
|
-
*/
|
1763
|
-
[Symbol.iterator]: typeof MIMEParams.prototype.entries;
|
1764
|
-
}
|
1765
|
-
}
|
1766
|
-
declare module "util/types" {
|
1767
|
-
import { KeyObject, webcrypto } from "node:crypto";
|
1768
|
-
/**
|
1769
|
-
* Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or
|
1770
|
-
* [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
|
1771
|
-
*
|
1772
|
-
* See also `util.types.isArrayBuffer()` and `util.types.isSharedArrayBuffer()`.
|
1773
|
-
*
|
1774
|
-
* ```js
|
1775
|
-
* util.types.isAnyArrayBuffer(new ArrayBuffer()); // Returns true
|
1776
|
-
* util.types.isAnyArrayBuffer(new SharedArrayBuffer()); // Returns true
|
1777
|
-
* ```
|
1778
|
-
* @since v10.0.0
|
1779
|
-
*/
|
1780
|
-
function isAnyArrayBuffer(object: unknown): object is ArrayBufferLike;
|
1781
|
-
/**
|
1782
|
-
* Returns `true` if the value is an `arguments` object.
|
1783
|
-
*
|
1784
|
-
* ```js
|
1785
|
-
* function foo() {
|
1786
|
-
* util.types.isArgumentsObject(arguments); // Returns true
|
1787
|
-
* }
|
1788
|
-
* ```
|
1789
|
-
* @since v10.0.0
|
1790
|
-
*/
|
1791
|
-
function isArgumentsObject(object: unknown): object is IArguments;
|
1792
|
-
/**
|
1793
|
-
* Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instance.
|
1794
|
-
* This does _not_ include [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances. Usually, it is
|
1795
|
-
* desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
|
1796
|
-
*
|
1797
|
-
* ```js
|
1798
|
-
* util.types.isArrayBuffer(new ArrayBuffer()); // Returns true
|
1799
|
-
* util.types.isArrayBuffer(new SharedArrayBuffer()); // Returns false
|
1800
|
-
* ```
|
1801
|
-
* @since v10.0.0
|
1802
|
-
*/
|
1803
|
-
function isArrayBuffer(object: unknown): object is ArrayBuffer;
|
1804
|
-
/**
|
1805
|
-
* Returns `true` if the value is an instance of one of the [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) views, such as typed
|
1806
|
-
* array objects or [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView). Equivalent to
|
1807
|
-
* [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
|
1808
|
-
*
|
1809
|
-
* ```js
|
1810
|
-
* util.types.isArrayBufferView(new Int8Array()); // true
|
1811
|
-
* util.types.isArrayBufferView(Buffer.from('hello world')); // true
|
1812
|
-
* util.types.isArrayBufferView(new DataView(new ArrayBuffer(16))); // true
|
1813
|
-
* util.types.isArrayBufferView(new ArrayBuffer()); // false
|
1814
|
-
* ```
|
1815
|
-
* @since v10.0.0
|
1816
|
-
*/
|
1817
|
-
function isArrayBufferView(object: unknown): object is NodeJS.ArrayBufferView;
|
1818
|
-
/**
|
1819
|
-
* Returns `true` if the value is an [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
|
1820
|
-
* This only reports back what the JavaScript engine is seeing;
|
1821
|
-
* in particular, the return value may not match the original source code if
|
1822
|
-
* a transpilation tool was used.
|
1823
|
-
*
|
1824
|
-
* ```js
|
1825
|
-
* util.types.isAsyncFunction(function foo() {}); // Returns false
|
1826
|
-
* util.types.isAsyncFunction(async function foo() {}); // Returns true
|
1827
|
-
* ```
|
1828
|
-
* @since v10.0.0
|
1829
|
-
*/
|
1830
|
-
function isAsyncFunction(object: unknown): boolean;
|
1831
|
-
/**
|
1832
|
-
* Returns `true` if the value is a `BigInt64Array` instance.
|
1833
|
-
*
|
1834
|
-
* ```js
|
1835
|
-
* util.types.isBigInt64Array(new BigInt64Array()); // Returns true
|
1836
|
-
* util.types.isBigInt64Array(new BigUint64Array()); // Returns false
|
1837
|
-
* ```
|
1838
|
-
* @since v10.0.0
|
1839
|
-
*/
|
1840
|
-
function isBigInt64Array(value: unknown): value is BigInt64Array;
|
1841
|
-
/**
|
1842
|
-
* Returns `true` if the value is a `BigUint64Array` instance.
|
1843
|
-
*
|
1844
|
-
* ```js
|
1845
|
-
* util.types.isBigUint64Array(new BigInt64Array()); // Returns false
|
1846
|
-
* util.types.isBigUint64Array(new BigUint64Array()); // Returns true
|
1847
|
-
* ```
|
1848
|
-
* @since v10.0.0
|
1849
|
-
*/
|
1850
|
-
function isBigUint64Array(value: unknown): value is BigUint64Array;
|
1851
|
-
/**
|
1852
|
-
* Returns `true` if the value is a boolean object, e.g. created
|
1853
|
-
* by `new Boolean()`.
|
1854
|
-
*
|
1855
|
-
* ```js
|
1856
|
-
* util.types.isBooleanObject(false); // Returns false
|
1857
|
-
* util.types.isBooleanObject(true); // Returns false
|
1858
|
-
* util.types.isBooleanObject(new Boolean(false)); // Returns true
|
1859
|
-
* util.types.isBooleanObject(new Boolean(true)); // Returns true
|
1860
|
-
* util.types.isBooleanObject(Boolean(false)); // Returns false
|
1861
|
-
* util.types.isBooleanObject(Boolean(true)); // Returns false
|
1862
|
-
* ```
|
1863
|
-
* @since v10.0.0
|
1864
|
-
*/
|
1865
|
-
function isBooleanObject(object: unknown): object is Boolean;
|
1866
|
-
/**
|
1867
|
-
* Returns `true` if the value is any boxed primitive object, e.g. created
|
1868
|
-
* by `new Boolean()`, `new String()` or `Object(Symbol())`.
|
1869
|
-
*
|
1870
|
-
* For example:
|
1871
|
-
*
|
1872
|
-
* ```js
|
1873
|
-
* util.types.isBoxedPrimitive(false); // Returns false
|
1874
|
-
* util.types.isBoxedPrimitive(new Boolean(false)); // Returns true
|
1875
|
-
* util.types.isBoxedPrimitive(Symbol('foo')); // Returns false
|
1876
|
-
* util.types.isBoxedPrimitive(Object(Symbol('foo'))); // Returns true
|
1877
|
-
* util.types.isBoxedPrimitive(Object(BigInt(5))); // Returns true
|
1878
|
-
* ```
|
1879
|
-
* @since v10.11.0
|
1880
|
-
*/
|
1881
|
-
function isBoxedPrimitive(object: unknown): object is String | Number | BigInt | Boolean | Symbol;
|
1882
|
-
/**
|
1883
|
-
* Returns `true` if the value is a built-in [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) instance.
|
1884
|
-
*
|
1885
|
-
* ```js
|
1886
|
-
* const ab = new ArrayBuffer(20);
|
1887
|
-
* util.types.isDataView(new DataView(ab)); // Returns true
|
1888
|
-
* util.types.isDataView(new Float64Array()); // Returns false
|
1889
|
-
* ```
|
1890
|
-
*
|
1891
|
-
* See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
|
1892
|
-
* @since v10.0.0
|
1893
|
-
*/
|
1894
|
-
function isDataView(object: unknown): object is DataView;
|
1895
|
-
/**
|
1896
|
-
* Returns `true` if the value is a built-in [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance.
|
1897
|
-
*
|
1898
|
-
* ```js
|
1899
|
-
* util.types.isDate(new Date()); // Returns true
|
1900
|
-
* ```
|
1901
|
-
* @since v10.0.0
|
1902
|
-
*/
|
1903
|
-
function isDate(object: unknown): object is Date;
|
1904
|
-
/**
|
1905
|
-
* Returns `true` if the value is a native `External` value.
|
1906
|
-
*
|
1907
|
-
* A native `External` value is a special type of object that contains a
|
1908
|
-
* raw C++ pointer (`void*`) for access from native code, and has no other
|
1909
|
-
* properties. Such objects are created either by Node.js internals or native
|
1910
|
-
* addons. In JavaScript, they are [frozen](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) objects with a`null` prototype.
|
1911
|
-
*
|
1912
|
-
* ```c
|
1913
|
-
* #include <js_native_api.h>
|
1914
|
-
* #include <stdlib.h>
|
1915
|
-
* napi_value result;
|
1916
|
-
* static napi_value MyNapi(napi_env env, napi_callback_info info) {
|
1917
|
-
* int* raw = (int*) malloc(1024);
|
1918
|
-
* napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &result);
|
1919
|
-
* if (status != napi_ok) {
|
1920
|
-
* napi_throw_error(env, NULL, "napi_create_external failed");
|
1921
|
-
* return NULL;
|
1922
|
-
* }
|
1923
|
-
* return result;
|
1924
|
-
* }
|
1925
|
-
* ...
|
1926
|
-
* DECLARE_NAPI_PROPERTY("myNapi", MyNapi)
|
1927
|
-
* ...
|
1928
|
-
* ```
|
1929
|
-
*
|
1930
|
-
* ```js
|
1931
|
-
* const native = require('napi_addon.node');
|
1932
|
-
* const data = native.myNapi();
|
1933
|
-
* util.types.isExternal(data); // returns true
|
1934
|
-
* util.types.isExternal(0); // returns false
|
1935
|
-
* util.types.isExternal(new String('foo')); // returns false
|
1936
|
-
* ```
|
1937
|
-
*
|
1938
|
-
* For further information on `napi_create_external`, refer to `napi_create_external()`.
|
1939
|
-
* @since v10.0.0
|
1940
|
-
*/
|
1941
|
-
function isExternal(object: unknown): boolean;
|
1942
|
-
/**
|
1943
|
-
* Returns `true` if the value is a built-in [`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) instance.
|
1944
|
-
*
|
1945
|
-
* ```js
|
1946
|
-
* util.types.isFloat32Array(new ArrayBuffer()); // Returns false
|
1947
|
-
* util.types.isFloat32Array(new Float32Array()); // Returns true
|
1948
|
-
* util.types.isFloat32Array(new Float64Array()); // Returns false
|
1949
|
-
* ```
|
1950
|
-
* @since v10.0.0
|
1951
|
-
*/
|
1952
|
-
function isFloat32Array(object: unknown): object is Float32Array;
|
1953
|
-
/**
|
1954
|
-
* Returns `true` if the value is a built-in [`Float64Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array) instance.
|
1955
|
-
*
|
1956
|
-
* ```js
|
1957
|
-
* util.types.isFloat64Array(new ArrayBuffer()); // Returns false
|
1958
|
-
* util.types.isFloat64Array(new Uint8Array()); // Returns false
|
1959
|
-
* util.types.isFloat64Array(new Float64Array()); // Returns true
|
1960
|
-
* ```
|
1961
|
-
* @since v10.0.0
|
1962
|
-
*/
|
1963
|
-
function isFloat64Array(object: unknown): object is Float64Array;
|
1964
|
-
/**
|
1965
|
-
* Returns `true` if the value is a generator function.
|
1966
|
-
* This only reports back what the JavaScript engine is seeing;
|
1967
|
-
* in particular, the return value may not match the original source code if
|
1968
|
-
* a transpilation tool was used.
|
1969
|
-
*
|
1970
|
-
* ```js
|
1971
|
-
* util.types.isGeneratorFunction(function foo() {}); // Returns false
|
1972
|
-
* util.types.isGeneratorFunction(function* foo() {}); // Returns true
|
1973
|
-
* ```
|
1974
|
-
* @since v10.0.0
|
1975
|
-
*/
|
1976
|
-
function isGeneratorFunction(object: unknown): object is GeneratorFunction;
|
1977
|
-
/**
|
1978
|
-
* Returns `true` if the value is a generator object as returned from a
|
1979
|
-
* built-in generator function.
|
1980
|
-
* This only reports back what the JavaScript engine is seeing;
|
1981
|
-
* in particular, the return value may not match the original source code if
|
1982
|
-
* a transpilation tool was used.
|
1983
|
-
*
|
1984
|
-
* ```js
|
1985
|
-
* function* foo() {}
|
1986
|
-
* const generator = foo();
|
1987
|
-
* util.types.isGeneratorObject(generator); // Returns true
|
1988
|
-
* ```
|
1989
|
-
* @since v10.0.0
|
1990
|
-
*/
|
1991
|
-
function isGeneratorObject(object: unknown): object is Generator;
|
1992
|
-
/**
|
1993
|
-
* Returns `true` if the value is a built-in [`Int8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array) instance.
|
1994
|
-
*
|
1995
|
-
* ```js
|
1996
|
-
* util.types.isInt8Array(new ArrayBuffer()); // Returns false
|
1997
|
-
* util.types.isInt8Array(new Int8Array()); // Returns true
|
1998
|
-
* util.types.isInt8Array(new Float64Array()); // Returns false
|
1999
|
-
* ```
|
2000
|
-
* @since v10.0.0
|
2001
|
-
*/
|
2002
|
-
function isInt8Array(object: unknown): object is Int8Array;
|
2003
|
-
/**
|
2004
|
-
* Returns `true` if the value is a built-in [`Int16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array) instance.
|
2005
|
-
*
|
2006
|
-
* ```js
|
2007
|
-
* util.types.isInt16Array(new ArrayBuffer()); // Returns false
|
2008
|
-
* util.types.isInt16Array(new Int16Array()); // Returns true
|
2009
|
-
* util.types.isInt16Array(new Float64Array()); // Returns false
|
2010
|
-
* ```
|
2011
|
-
* @since v10.0.0
|
2012
|
-
*/
|
2013
|
-
function isInt16Array(object: unknown): object is Int16Array;
|
2014
|
-
/**
|
2015
|
-
* Returns `true` if the value is a built-in [`Int32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array) instance.
|
2016
|
-
*
|
2017
|
-
* ```js
|
2018
|
-
* util.types.isInt32Array(new ArrayBuffer()); // Returns false
|
2019
|
-
* util.types.isInt32Array(new Int32Array()); // Returns true
|
2020
|
-
* util.types.isInt32Array(new Float64Array()); // Returns false
|
2021
|
-
* ```
|
2022
|
-
* @since v10.0.0
|
2023
|
-
*/
|
2024
|
-
function isInt32Array(object: unknown): object is Int32Array;
|
2025
|
-
/**
|
2026
|
-
* Returns `true` if the value is a built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance.
|
2027
|
-
*
|
2028
|
-
* ```js
|
2029
|
-
* util.types.isMap(new Map()); // Returns true
|
2030
|
-
* ```
|
2031
|
-
* @since v10.0.0
|
2032
|
-
*/
|
2033
|
-
function isMap<T>(
|
2034
|
-
object: T | {},
|
2035
|
-
): object is T extends ReadonlyMap<any, any> ? (unknown extends T ? never : ReadonlyMap<any, any>)
|
2036
|
-
: Map<unknown, unknown>;
|
2037
|
-
/**
|
2038
|
-
* Returns `true` if the value is an iterator returned for a built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance.
|
2039
|
-
*
|
2040
|
-
* ```js
|
2041
|
-
* const map = new Map();
|
2042
|
-
* util.types.isMapIterator(map.keys()); // Returns true
|
2043
|
-
* util.types.isMapIterator(map.values()); // Returns true
|
2044
|
-
* util.types.isMapIterator(map.entries()); // Returns true
|
2045
|
-
* util.types.isMapIterator(map[Symbol.iterator]()); // Returns true
|
2046
|
-
* ```
|
2047
|
-
* @since v10.0.0
|
2048
|
-
*/
|
2049
|
-
function isMapIterator(object: unknown): boolean;
|
2050
|
-
/**
|
2051
|
-
* Returns `true` if the value is an instance of a [Module Namespace Object](https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects).
|
2052
|
-
*
|
2053
|
-
* ```js
|
2054
|
-
* import * as ns from './a.js';
|
2055
|
-
*
|
2056
|
-
* util.types.isModuleNamespaceObject(ns); // Returns true
|
2057
|
-
* ```
|
2058
|
-
* @since v10.0.0
|
2059
|
-
*/
|
2060
|
-
function isModuleNamespaceObject(value: unknown): boolean;
|
2061
|
-
/**
|
2062
|
-
* Returns `true` if the value was returned by the constructor of a [built-in `Error` type](https://tc39.es/ecma262/#sec-error-objects).
|
2063
|
-
*
|
2064
|
-
* ```js
|
2065
|
-
* console.log(util.types.isNativeError(new Error())); // true
|
2066
|
-
* console.log(util.types.isNativeError(new TypeError())); // true
|
2067
|
-
* console.log(util.types.isNativeError(new RangeError())); // true
|
2068
|
-
* ```
|
2069
|
-
*
|
2070
|
-
* Subclasses of the native error types are also native errors:
|
2071
|
-
*
|
2072
|
-
* ```js
|
2073
|
-
* class MyError extends Error {}
|
2074
|
-
* console.log(util.types.isNativeError(new MyError())); // true
|
2075
|
-
* ```
|
2076
|
-
*
|
2077
|
-
* A value being `instanceof` a native error class is not equivalent to `isNativeError()` returning `true` for that value. `isNativeError()` returns `true` for errors
|
2078
|
-
* which come from a different [realm](https://tc39.es/ecma262/#realm) while `instanceof Error` returns `false` for these errors:
|
2079
|
-
*
|
2080
|
-
* ```js
|
2081
|
-
* const vm = require('node:vm');
|
2082
|
-
* const context = vm.createContext({});
|
2083
|
-
* const myError = vm.runInContext('new Error()', context);
|
2084
|
-
* console.log(util.types.isNativeError(myError)); // true
|
2085
|
-
* console.log(myError instanceof Error); // false
|
2086
|
-
* ```
|
2087
|
-
*
|
2088
|
-
* Conversely, `isNativeError()` returns `false` for all objects which were not
|
2089
|
-
* returned by the constructor of a native error. That includes values
|
2090
|
-
* which are `instanceof` native errors:
|
2091
|
-
*
|
2092
|
-
* ```js
|
2093
|
-
* const myError = { __proto__: Error.prototype };
|
2094
|
-
* console.log(util.types.isNativeError(myError)); // false
|
2095
|
-
* console.log(myError instanceof Error); // true
|
2096
|
-
* ```
|
2097
|
-
* @since v10.0.0
|
2098
|
-
*/
|
2099
|
-
function isNativeError(object: unknown): object is Error;
|
2100
|
-
/**
|
2101
|
-
* Returns `true` if the value is a number object, e.g. created
|
2102
|
-
* by `new Number()`.
|
2103
|
-
*
|
2104
|
-
* ```js
|
2105
|
-
* util.types.isNumberObject(0); // Returns false
|
2106
|
-
* util.types.isNumberObject(new Number(0)); // Returns true
|
2107
|
-
* ```
|
2108
|
-
* @since v10.0.0
|
2109
|
-
*/
|
2110
|
-
function isNumberObject(object: unknown): object is Number;
|
2111
|
-
/**
|
2112
|
-
* Returns `true` if the value is a built-in [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
|
2113
|
-
*
|
2114
|
-
* ```js
|
2115
|
-
* util.types.isPromise(Promise.resolve(42)); // Returns true
|
2116
|
-
* ```
|
2117
|
-
* @since v10.0.0
|
2118
|
-
*/
|
2119
|
-
function isPromise(object: unknown): object is Promise<unknown>;
|
2120
|
-
/**
|
2121
|
-
* Returns `true` if the value is a [`Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) instance.
|
2122
|
-
*
|
2123
|
-
* ```js
|
2124
|
-
* const target = {};
|
2125
|
-
* const proxy = new Proxy(target, {});
|
2126
|
-
* util.types.isProxy(target); // Returns false
|
2127
|
-
* util.types.isProxy(proxy); // Returns true
|
2128
|
-
* ```
|
2129
|
-
* @since v10.0.0
|
2130
|
-
*/
|
2131
|
-
function isProxy(object: unknown): boolean;
|
2132
|
-
/**
|
2133
|
-
* Returns `true` if the value is a regular expression object.
|
2134
|
-
*
|
2135
|
-
* ```js
|
2136
|
-
* util.types.isRegExp(/abc/); // Returns true
|
2137
|
-
* util.types.isRegExp(new RegExp('abc')); // Returns true
|
2138
|
-
* ```
|
2139
|
-
* @since v10.0.0
|
2140
|
-
*/
|
2141
|
-
function isRegExp(object: unknown): object is RegExp;
|
2142
|
-
/**
|
2143
|
-
* Returns `true` if the value is a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance.
|
2144
|
-
*
|
2145
|
-
* ```js
|
2146
|
-
* util.types.isSet(new Set()); // Returns true
|
2147
|
-
* ```
|
2148
|
-
* @since v10.0.0
|
2149
|
-
*/
|
2150
|
-
function isSet<T>(
|
2151
|
-
object: T | {},
|
2152
|
-
): object is T extends ReadonlySet<any> ? (unknown extends T ? never : ReadonlySet<any>) : Set<unknown>;
|
2153
|
-
/**
|
2154
|
-
* Returns `true` if the value is an iterator returned for a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance.
|
2155
|
-
*
|
2156
|
-
* ```js
|
2157
|
-
* const set = new Set();
|
2158
|
-
* util.types.isSetIterator(set.keys()); // Returns true
|
2159
|
-
* util.types.isSetIterator(set.values()); // Returns true
|
2160
|
-
* util.types.isSetIterator(set.entries()); // Returns true
|
2161
|
-
* util.types.isSetIterator(set[Symbol.iterator]()); // Returns true
|
2162
|
-
* ```
|
2163
|
-
* @since v10.0.0
|
2164
|
-
*/
|
2165
|
-
function isSetIterator(object: unknown): boolean;
|
2166
|
-
/**
|
2167
|
-
* Returns `true` if the value is a built-in [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
|
2168
|
-
* This does _not_ include [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instances. Usually, it is
|
2169
|
-
* desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
|
2170
|
-
*
|
2171
|
-
* ```js
|
2172
|
-
* util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false
|
2173
|
-
* util.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true
|
2174
|
-
* ```
|
2175
|
-
* @since v10.0.0
|
2176
|
-
*/
|
2177
|
-
function isSharedArrayBuffer(object: unknown): object is SharedArrayBuffer;
|
2178
|
-
/**
|
2179
|
-
* Returns `true` if the value is a string object, e.g. created
|
2180
|
-
* by `new String()`.
|
2181
|
-
*
|
2182
|
-
* ```js
|
2183
|
-
* util.types.isStringObject('foo'); // Returns false
|
2184
|
-
* util.types.isStringObject(new String('foo')); // Returns true
|
2185
|
-
* ```
|
2186
|
-
* @since v10.0.0
|
2187
|
-
*/
|
2188
|
-
function isStringObject(object: unknown): object is String;
|
2189
|
-
/**
|
2190
|
-
* Returns `true` if the value is a symbol object, created
|
2191
|
-
* by calling `Object()` on a `Symbol` primitive.
|
2192
|
-
*
|
2193
|
-
* ```js
|
2194
|
-
* const symbol = Symbol('foo');
|
2195
|
-
* util.types.isSymbolObject(symbol); // Returns false
|
2196
|
-
* util.types.isSymbolObject(Object(symbol)); // Returns true
|
2197
|
-
* ```
|
2198
|
-
* @since v10.0.0
|
2199
|
-
*/
|
2200
|
-
function isSymbolObject(object: unknown): object is Symbol;
|
2201
|
-
/**
|
2202
|
-
* Returns `true` if the value is a built-in [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) instance.
|
2203
|
-
*
|
2204
|
-
* ```js
|
2205
|
-
* util.types.isTypedArray(new ArrayBuffer()); // Returns false
|
2206
|
-
* util.types.isTypedArray(new Uint8Array()); // Returns true
|
2207
|
-
* util.types.isTypedArray(new Float64Array()); // Returns true
|
2208
|
-
* ```
|
2209
|
-
*
|
2210
|
-
* See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
|
2211
|
-
* @since v10.0.0
|
2212
|
-
*/
|
2213
|
-
function isTypedArray(object: unknown): object is NodeJS.TypedArray;
|
2214
|
-
/**
|
2215
|
-
* Returns `true` if the value is a built-in [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) instance.
|
2216
|
-
*
|
2217
|
-
* ```js
|
2218
|
-
* util.types.isUint8Array(new ArrayBuffer()); // Returns false
|
2219
|
-
* util.types.isUint8Array(new Uint8Array()); // Returns true
|
2220
|
-
* util.types.isUint8Array(new Float64Array()); // Returns false
|
2221
|
-
* ```
|
2222
|
-
* @since v10.0.0
|
2223
|
-
*/
|
2224
|
-
function isUint8Array(object: unknown): object is Uint8Array;
|
2225
|
-
/**
|
2226
|
-
* Returns `true` if the value is a built-in [`Uint8ClampedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) instance.
|
2227
|
-
*
|
2228
|
-
* ```js
|
2229
|
-
* util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false
|
2230
|
-
* util.types.isUint8ClampedArray(new Uint8ClampedArray()); // Returns true
|
2231
|
-
* util.types.isUint8ClampedArray(new Float64Array()); // Returns false
|
2232
|
-
* ```
|
2233
|
-
* @since v10.0.0
|
2234
|
-
*/
|
2235
|
-
function isUint8ClampedArray(object: unknown): object is Uint8ClampedArray;
|
2236
|
-
/**
|
2237
|
-
* Returns `true` if the value is a built-in [`Uint16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array) instance.
|
2238
|
-
*
|
2239
|
-
* ```js
|
2240
|
-
* util.types.isUint16Array(new ArrayBuffer()); // Returns false
|
2241
|
-
* util.types.isUint16Array(new Uint16Array()); // Returns true
|
2242
|
-
* util.types.isUint16Array(new Float64Array()); // Returns false
|
2243
|
-
* ```
|
2244
|
-
* @since v10.0.0
|
2245
|
-
*/
|
2246
|
-
function isUint16Array(object: unknown): object is Uint16Array;
|
2247
|
-
/**
|
2248
|
-
* Returns `true` if the value is a built-in [`Uint32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array) instance.
|
2249
|
-
*
|
2250
|
-
* ```js
|
2251
|
-
* util.types.isUint32Array(new ArrayBuffer()); // Returns false
|
2252
|
-
* util.types.isUint32Array(new Uint32Array()); // Returns true
|
2253
|
-
* util.types.isUint32Array(new Float64Array()); // Returns false
|
2254
|
-
* ```
|
2255
|
-
* @since v10.0.0
|
2256
|
-
*/
|
2257
|
-
function isUint32Array(object: unknown): object is Uint32Array;
|
2258
|
-
/**
|
2259
|
-
* Returns `true` if the value is a built-in [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) instance.
|
2260
|
-
*
|
2261
|
-
* ```js
|
2262
|
-
* util.types.isWeakMap(new WeakMap()); // Returns true
|
2263
|
-
* ```
|
2264
|
-
* @since v10.0.0
|
2265
|
-
*/
|
2266
|
-
function isWeakMap(object: unknown): object is WeakMap<object, unknown>;
|
2267
|
-
/**
|
2268
|
-
* Returns `true` if the value is a built-in [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) instance.
|
2269
|
-
*
|
2270
|
-
* ```js
|
2271
|
-
* util.types.isWeakSet(new WeakSet()); // Returns true
|
2272
|
-
* ```
|
2273
|
-
* @since v10.0.0
|
2274
|
-
*/
|
2275
|
-
function isWeakSet(object: unknown): object is WeakSet<object>;
|
2276
|
-
/**
|
2277
|
-
* Returns `true` if `value` is a `KeyObject`, `false` otherwise.
|
2278
|
-
* @since v16.2.0
|
2279
|
-
*/
|
2280
|
-
function isKeyObject(object: unknown): object is KeyObject;
|
2281
|
-
/**
|
2282
|
-
* Returns `true` if `value` is a `CryptoKey`, `false` otherwise.
|
2283
|
-
* @since v16.2.0
|
2284
|
-
*/
|
2285
|
-
function isCryptoKey(object: unknown): object is webcrypto.CryptoKey;
|
2286
|
-
}
|
2287
|
-
declare module "node:util" {
|
2288
|
-
export * from "util";
|
2289
|
-
}
|
2290
|
-
declare module "node:util/types" {
|
2291
|
-
export * from "util/types";
|
2292
|
-
}
|