@types/node 20.3.2 → 20.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- node/README.md +1 -1
- node/buffer.d.ts +1 -1
- node/crypto.d.ts +9 -1
- node/index.d.ts +1 -1
- node/module.d.ts +17 -4
- node/package.json +2 -2
- node/test.d.ts +213 -2
- node/tls.d.ts +11 -0
- node/ts4.8/crypto.d.ts +9 -1
- node/ts4.8/module.d.ts +17 -4
- node/ts4.8/test.d.ts +213 -2
- node/ts4.8/tls.d.ts +11 -0
- node/ts4.8/util.d.ts +75 -11
- node/util.d.ts +75 -11
node/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This package contains type definitions for Node.js (https://nodejs.org/).
|
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated:
|
|
11
|
+
* Last updated: Wed, 05 Jul 2023 21:32:40 GMT
|
|
12
12
|
* Dependencies: none
|
|
13
13
|
* Global values: `AbortController`, `AbortSignal`, `__dirname`, `__filename`, `console`, `exports`, `gc`, `global`, `module`, `process`, `require`, `structuredClone`
|
|
14
14
|
|
node/buffer.d.ts
CHANGED
|
@@ -530,7 +530,7 @@ declare module 'buffer' {
|
|
|
530
530
|
* @param [fill=0] A value to pre-fill the new `Buffer` with.
|
|
531
531
|
* @param [encoding='utf8'] If `fill` is a string, this is its encoding.
|
|
532
532
|
*/
|
|
533
|
-
alloc(size: number, fill?: string |
|
|
533
|
+
alloc(size: number, fill?: string | Uint8Array | number, encoding?: BufferEncoding): Buffer;
|
|
534
534
|
/**
|
|
535
535
|
* Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.
|
|
536
536
|
*
|
node/crypto.d.ts
CHANGED
|
@@ -1516,10 +1516,15 @@ declare module 'crypto' {
|
|
|
1516
1516
|
class DiffieHellman {
|
|
1517
1517
|
private constructor();
|
|
1518
1518
|
/**
|
|
1519
|
-
* Generates private and public Diffie-Hellman key values
|
|
1519
|
+
* Generates private and public Diffie-Hellman key values unless they have been
|
|
1520
|
+
* generated or computed already, and returns
|
|
1520
1521
|
* the public key in the specified `encoding`. This key should be
|
|
1521
1522
|
* transferred to the other party.
|
|
1522
1523
|
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
|
|
1524
|
+
*
|
|
1525
|
+
* This function is a thin wrapper around [`DH_generate_key()`](https://www.openssl.org/docs/man3.0/man3/DH_generate_key.html). In particular,
|
|
1526
|
+
* once a private key has been generated or set, calling this function only updates
|
|
1527
|
+
* the public key but does not generate a new private key.
|
|
1523
1528
|
* @since v0.5.0
|
|
1524
1529
|
* @param encoding The `encoding` of the return value.
|
|
1525
1530
|
*/
|
|
@@ -1591,6 +1596,9 @@ declare module 'crypto' {
|
|
|
1591
1596
|
* Sets the Diffie-Hellman private key. If the `encoding` argument is provided,`privateKey` is expected
|
|
1592
1597
|
* to be a string. If no `encoding` is provided, `privateKey` is expected
|
|
1593
1598
|
* to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
1599
|
+
*
|
|
1600
|
+
* This function does not automatically compute the associated public key. Either `diffieHellman.setPublicKey()` or `diffieHellman.generateKeys()` can be
|
|
1601
|
+
* used to manually provide the public key or to automatically derive it.
|
|
1594
1602
|
* @since v0.5.0
|
|
1595
1603
|
* @param encoding The `encoding` of the `privateKey` string.
|
|
1596
1604
|
*/
|
node/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Type definitions for non-npm package Node.js 20.
|
|
1
|
+
// Type definitions for non-npm package Node.js 20.4
|
|
2
2
|
// Project: https://nodejs.org/
|
|
3
3
|
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
|
|
4
4
|
// DefinitelyTyped <https://github.com/DefinitelyTyped>
|
node/module.d.ts
CHANGED
|
@@ -73,11 +73,24 @@ declare module 'module' {
|
|
|
73
73
|
readonly payload: SourceMapPayload;
|
|
74
74
|
constructor(payload: SourceMapPayload);
|
|
75
75
|
/**
|
|
76
|
-
* Given a line
|
|
77
|
-
* an object representing the
|
|
78
|
-
*
|
|
76
|
+
* Given a line offset and column offset in the generated source
|
|
77
|
+
* file, returns an object representing the SourceMap range in the
|
|
78
|
+
* original file if found, or an empty object if not.
|
|
79
|
+
*
|
|
80
|
+
* The object returned contains the following keys:
|
|
81
|
+
*
|
|
82
|
+
* The returned value represents the raw range as it appears in the
|
|
83
|
+
* SourceMap, based on zero-indexed offsets, _not_ 1-indexed line and
|
|
84
|
+
* column numbers as they appear in Error messages and CallSite
|
|
85
|
+
* objects.
|
|
86
|
+
*
|
|
87
|
+
* To get the corresponding 1-indexed line and column numbers from a
|
|
88
|
+
* lineNumber and columnNumber as they are reported by Error stacks
|
|
89
|
+
* and CallSite objects, use `sourceMap.findOrigin(lineNumber, columnNumber)`
|
|
90
|
+
* @param lineOffset The zero-indexed line number offset in the generated source
|
|
91
|
+
* @param columnOffset The zero-indexed column number offset in the generated source
|
|
79
92
|
*/
|
|
80
|
-
findEntry(
|
|
93
|
+
findEntry(lineOffset: number, columnOffset: number): SourceMapping;
|
|
81
94
|
}
|
|
82
95
|
}
|
|
83
96
|
interface Module extends NodeModule {}
|
node/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.4.0",
|
|
4
4
|
"description": "TypeScript definitions for Node.js",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -232,6 +232,6 @@
|
|
|
232
232
|
},
|
|
233
233
|
"scripts": {},
|
|
234
234
|
"dependencies": {},
|
|
235
|
-
"typesPublisherContentHash": "
|
|
235
|
+
"typesPublisherContentHash": "c342b7a9708bb206f3dfc674c1d142bfdaf5a01b59dc5d8bd88d18fc226c2de3",
|
|
236
236
|
"typeScriptVersion": "4.3"
|
|
237
237
|
}
|
node/test.d.ts
CHANGED
|
@@ -159,7 +159,7 @@ declare module 'node:test' {
|
|
|
159
159
|
* @param [name='The name'] The name of the suite, which is displayed when reporting test results.
|
|
160
160
|
* @param options Configuration options for the suite. supports the same options as `test([name][, options][, fn])`.
|
|
161
161
|
* @param [fn='A no-op function'] The function under suite declaring all subtests and subsuites. The first argument to this function is a {@link SuiteContext} object.
|
|
162
|
-
* @return `undefined`.
|
|
162
|
+
* @return Immediately fulfilled with `undefined`.
|
|
163
163
|
*/
|
|
164
164
|
function describe(name?: string, options?: TestOptions, fn?: SuiteFn): void;
|
|
165
165
|
function describe(name?: string, fn?: SuiteFn): void;
|
|
@@ -821,6 +821,7 @@ declare module 'node:test' {
|
|
|
821
821
|
* @since v19.1.0, v18.13.0
|
|
822
822
|
*/
|
|
823
823
|
restoreAll(): void;
|
|
824
|
+
timers: MockTimers;
|
|
824
825
|
}
|
|
825
826
|
const mock: MockTracker;
|
|
826
827
|
interface MockFunctionCall<
|
|
@@ -964,6 +965,216 @@ declare module 'node:test' {
|
|
|
964
965
|
*/
|
|
965
966
|
restore(): void;
|
|
966
967
|
}
|
|
968
|
+
type Timer = 'setInterval' | 'clearInterval' | 'setTimeout' | 'clearTimeout';
|
|
969
|
+
/**
|
|
970
|
+
* Mocking timers is a technique commonly used in software testing to simulate and
|
|
971
|
+
* control the behavior of timers, such as `setInterval` and `setTimeout`,
|
|
972
|
+
* without actually waiting for the specified time intervals.
|
|
973
|
+
*
|
|
974
|
+
* The `MockTracker` provides a top-level `timers` export
|
|
975
|
+
* which is a `MockTimers` instance.
|
|
976
|
+
* @since v20.4.0
|
|
977
|
+
* @experimental
|
|
978
|
+
*/
|
|
979
|
+
class MockTimers {
|
|
980
|
+
/**
|
|
981
|
+
* Enables timer mocking for the specified timers.
|
|
982
|
+
*
|
|
983
|
+
* **Note:** When you enable mocking for a specific timer, its associated
|
|
984
|
+
* clear function will also be implicitly mocked.
|
|
985
|
+
*
|
|
986
|
+
* Example usage:
|
|
987
|
+
*
|
|
988
|
+
* ```js
|
|
989
|
+
* import { mock } from 'node:test';
|
|
990
|
+
* mock.timers.enable(['setInterval']);
|
|
991
|
+
* ```
|
|
992
|
+
*
|
|
993
|
+
* ```js
|
|
994
|
+
* const { mock } = require('node:test');
|
|
995
|
+
* mock.timers.enable(['setInterval']);
|
|
996
|
+
* ```
|
|
997
|
+
*
|
|
998
|
+
* The above example enables mocking for the `setInterval` timer and
|
|
999
|
+
* implicitly mocks the `clearInterval` function. Only the `setInterval`and `clearInterval` functions from `node:timers`,`node:timers/promises`, and`globalThis` will be mocked.
|
|
1000
|
+
*
|
|
1001
|
+
* Alternatively, if you call `mock.timers.enable()` without any parameters:
|
|
1002
|
+
*
|
|
1003
|
+
* All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
|
|
1004
|
+
* will be mocked. The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout`functions from `node:timers`, `node:timers/promises`,
|
|
1005
|
+
* and `globalThis` will be mocked.
|
|
1006
|
+
* @since v20.4.0
|
|
1007
|
+
*/
|
|
1008
|
+
enable(timers?: Timer[]): void;
|
|
1009
|
+
/**
|
|
1010
|
+
* This function restores the default behavior of all mocks that were previously
|
|
1011
|
+
* created by this `MockTimers` instance and disassociates the mocks
|
|
1012
|
+
* from the `MockTracker` instance.
|
|
1013
|
+
*
|
|
1014
|
+
* **Note:** After each test completes, this function is called on
|
|
1015
|
+
* the test context's `MockTracker`.
|
|
1016
|
+
*
|
|
1017
|
+
* ```js
|
|
1018
|
+
* import { mock } from 'node:test';
|
|
1019
|
+
* mock.timers.reset();
|
|
1020
|
+
* ```
|
|
1021
|
+
*
|
|
1022
|
+
* ```js
|
|
1023
|
+
* const { mock } = require('node:test');
|
|
1024
|
+
* mock.timers.reset();
|
|
1025
|
+
* ```
|
|
1026
|
+
* @since v20.4.0
|
|
1027
|
+
*/
|
|
1028
|
+
reset(): void;
|
|
1029
|
+
/**
|
|
1030
|
+
* Advances time for all mocked timers.
|
|
1031
|
+
*
|
|
1032
|
+
* **Note:** This diverges from how `setTimeout` in Node.js behaves and accepts
|
|
1033
|
+
* only positive numbers. In Node.js, `setTimeout` with negative numbers is
|
|
1034
|
+
* only supported for web compatibility reasons.
|
|
1035
|
+
*
|
|
1036
|
+
* The following example mocks a `setTimeout` function and
|
|
1037
|
+
* by using `.tick` advances in
|
|
1038
|
+
* time triggering all pending timers.
|
|
1039
|
+
*
|
|
1040
|
+
* ```js
|
|
1041
|
+
* import assert from 'node:assert';
|
|
1042
|
+
* import { test } from 'node:test';
|
|
1043
|
+
*
|
|
1044
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
|
1045
|
+
* const fn = context.mock.fn();
|
|
1046
|
+
*
|
|
1047
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1048
|
+
*
|
|
1049
|
+
* setTimeout(fn, 9999);
|
|
1050
|
+
*
|
|
1051
|
+
* assert.strictEqual(fn.mock.callCount(), 0);
|
|
1052
|
+
*
|
|
1053
|
+
* // Advance in time
|
|
1054
|
+
* context.mock.timers.tick(9999);
|
|
1055
|
+
*
|
|
1056
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
|
1057
|
+
* });
|
|
1058
|
+
* ```
|
|
1059
|
+
*
|
|
1060
|
+
* ```js
|
|
1061
|
+
* const assert = require('node:assert');
|
|
1062
|
+
* const { test } = require('node:test');
|
|
1063
|
+
*
|
|
1064
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
|
1065
|
+
* const fn = context.mock.fn();
|
|
1066
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1067
|
+
*
|
|
1068
|
+
* setTimeout(fn, 9999);
|
|
1069
|
+
* assert.strictEqual(fn.mock.callCount(), 0);
|
|
1070
|
+
*
|
|
1071
|
+
* // Advance in time
|
|
1072
|
+
* context.mock.timers.tick(9999);
|
|
1073
|
+
*
|
|
1074
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
|
1075
|
+
* });
|
|
1076
|
+
* ```
|
|
1077
|
+
*
|
|
1078
|
+
* Alternativelly, the `.tick` function can be called many times
|
|
1079
|
+
*
|
|
1080
|
+
* ```js
|
|
1081
|
+
* import assert from 'node:assert';
|
|
1082
|
+
* import { test } from 'node:test';
|
|
1083
|
+
*
|
|
1084
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
|
1085
|
+
* const fn = context.mock.fn();
|
|
1086
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1087
|
+
* const nineSecs = 9000;
|
|
1088
|
+
* setTimeout(fn, nineSecs);
|
|
1089
|
+
*
|
|
1090
|
+
* const twoSeconds = 3000;
|
|
1091
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1092
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1093
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1094
|
+
*
|
|
1095
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
|
1096
|
+
* });
|
|
1097
|
+
* ```
|
|
1098
|
+
*
|
|
1099
|
+
* ```js
|
|
1100
|
+
* const assert = require('node:assert');
|
|
1101
|
+
* const { test } = require('node:test');
|
|
1102
|
+
*
|
|
1103
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
|
1104
|
+
* const fn = context.mock.fn();
|
|
1105
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1106
|
+
* const nineSecs = 9000;
|
|
1107
|
+
* setTimeout(fn, nineSecs);
|
|
1108
|
+
*
|
|
1109
|
+
* const twoSeconds = 3000;
|
|
1110
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1111
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1112
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1113
|
+
*
|
|
1114
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
|
1115
|
+
* });
|
|
1116
|
+
* ```
|
|
1117
|
+
* @since v20.4.0
|
|
1118
|
+
*/
|
|
1119
|
+
tick(milliseconds: number): void;
|
|
1120
|
+
/**
|
|
1121
|
+
* Triggers all pending mocked timers immediately.
|
|
1122
|
+
*
|
|
1123
|
+
* The example below triggers all pending timers immediately,
|
|
1124
|
+
* causing them to execute without any delay.
|
|
1125
|
+
*
|
|
1126
|
+
* ```js
|
|
1127
|
+
* import assert from 'node:assert';
|
|
1128
|
+
* import { test } from 'node:test';
|
|
1129
|
+
*
|
|
1130
|
+
* test('runAll functions following the given order', (context) => {
|
|
1131
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1132
|
+
* const results = [];
|
|
1133
|
+
* setTimeout(() => results.push(1), 9999);
|
|
1134
|
+
*
|
|
1135
|
+
* // Notice that if both timers have the same timeout,
|
|
1136
|
+
* // the order of execution is guaranteed
|
|
1137
|
+
* setTimeout(() => results.push(3), 8888);
|
|
1138
|
+
* setTimeout(() => results.push(2), 8888);
|
|
1139
|
+
*
|
|
1140
|
+
* assert.deepStrictEqual(results, []);
|
|
1141
|
+
*
|
|
1142
|
+
* context.mock.timers.runAll();
|
|
1143
|
+
*
|
|
1144
|
+
* assert.deepStrictEqual(results, [3, 2, 1]);
|
|
1145
|
+
* });
|
|
1146
|
+
* ```
|
|
1147
|
+
*
|
|
1148
|
+
* ```js
|
|
1149
|
+
* const assert = require('node:assert');
|
|
1150
|
+
* const { test } = require('node:test');
|
|
1151
|
+
*
|
|
1152
|
+
* test('runAll functions following the given order', (context) => {
|
|
1153
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1154
|
+
* const results = [];
|
|
1155
|
+
* setTimeout(() => results.push(1), 9999);
|
|
1156
|
+
*
|
|
1157
|
+
* // Notice that if both timers have the same timeout,
|
|
1158
|
+
* // the order of execution is guaranteed
|
|
1159
|
+
* setTimeout(() => results.push(3), 8888);
|
|
1160
|
+
* setTimeout(() => results.push(2), 8888);
|
|
1161
|
+
*
|
|
1162
|
+
* assert.deepStrictEqual(results, []);
|
|
1163
|
+
*
|
|
1164
|
+
* context.mock.timers.runAll();
|
|
1165
|
+
*
|
|
1166
|
+
* assert.deepStrictEqual(results, [3, 2, 1]);
|
|
1167
|
+
* });
|
|
1168
|
+
* ```
|
|
1169
|
+
*
|
|
1170
|
+
* **Note:** The `runAll()` function is specifically designed for
|
|
1171
|
+
* triggering timers in the context of timer mocking.
|
|
1172
|
+
* It does not have any effect on real-time system
|
|
1173
|
+
* clocks or actual timers outside of the mocking environment.
|
|
1174
|
+
* @since v20.4.0
|
|
1175
|
+
*/
|
|
1176
|
+
runAll(): void;
|
|
1177
|
+
}
|
|
967
1178
|
export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock, skip, only, todo };
|
|
968
1179
|
}
|
|
969
1180
|
|
|
@@ -1139,7 +1350,7 @@ declare module 'node:test/reporters' {
|
|
|
1139
1350
|
* where each passing test is represented by a `.`,
|
|
1140
1351
|
* and each failing test is represented by a `X`.
|
|
1141
1352
|
*/
|
|
1142
|
-
function dot(source: TestEventGenerator): AsyncGenerator<
|
|
1353
|
+
function dot(source: TestEventGenerator): AsyncGenerator<'\n' | '.' | 'X', void>;
|
|
1143
1354
|
/**
|
|
1144
1355
|
* The `tap` reporter outputs the test results in the [TAP](https://testanything.org/) format.
|
|
1145
1356
|
*/
|
node/tls.d.ts
CHANGED
|
@@ -728,6 +728,17 @@ declare module 'tls' {
|
|
|
728
728
|
}
|
|
729
729
|
type SecureVersion = 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1';
|
|
730
730
|
interface SecureContextOptions {
|
|
731
|
+
/**
|
|
732
|
+
* If set, this will be called when a client opens a connection using the ALPN extension.
|
|
733
|
+
* One argument will be passed to the callback: an object containing `servername` and `protocols` fields,
|
|
734
|
+
* respectively containing the server name from the SNI extension (if any) and an array of
|
|
735
|
+
* ALPN protocol name strings. The callback must return either one of the strings listed in `protocols`,
|
|
736
|
+
* which will be returned to the client as the selected ALPN protocol, or `undefined`,
|
|
737
|
+
* to reject the connection with a fatal alert. If a string is returned that does not match one of
|
|
738
|
+
* the client's ALPN protocols, an error will be thrown.
|
|
739
|
+
* This option cannot be used with the `ALPNProtocols` option, and setting both options will throw an error.
|
|
740
|
+
*/
|
|
741
|
+
ALPNCallback?: ((arg: { servername: string; protocols: string[] }) => string | undefined) | undefined;
|
|
731
742
|
/**
|
|
732
743
|
* Optionally override the trusted CA certificates. Default is to trust
|
|
733
744
|
* the well-known CAs curated by Mozilla. Mozilla's CAs are completely
|
node/ts4.8/crypto.d.ts
CHANGED
|
@@ -1516,10 +1516,15 @@ declare module 'crypto' {
|
|
|
1516
1516
|
class DiffieHellman {
|
|
1517
1517
|
private constructor();
|
|
1518
1518
|
/**
|
|
1519
|
-
* Generates private and public Diffie-Hellman key values
|
|
1519
|
+
* Generates private and public Diffie-Hellman key values unless they have been
|
|
1520
|
+
* generated or computed already, and returns
|
|
1520
1521
|
* the public key in the specified `encoding`. This key should be
|
|
1521
1522
|
* transferred to the other party.
|
|
1522
1523
|
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
|
|
1524
|
+
*
|
|
1525
|
+
* This function is a thin wrapper around [`DH_generate_key()`](https://www.openssl.org/docs/man3.0/man3/DH_generate_key.html). In particular,
|
|
1526
|
+
* once a private key has been generated or set, calling this function only updates
|
|
1527
|
+
* the public key but does not generate a new private key.
|
|
1523
1528
|
* @since v0.5.0
|
|
1524
1529
|
* @param encoding The `encoding` of the return value.
|
|
1525
1530
|
*/
|
|
@@ -1591,6 +1596,9 @@ declare module 'crypto' {
|
|
|
1591
1596
|
* Sets the Diffie-Hellman private key. If the `encoding` argument is provided,`privateKey` is expected
|
|
1592
1597
|
* to be a string. If no `encoding` is provided, `privateKey` is expected
|
|
1593
1598
|
* to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
1599
|
+
*
|
|
1600
|
+
* This function does not automatically compute the associated public key. Either `diffieHellman.setPublicKey()` or `diffieHellman.generateKeys()` can be
|
|
1601
|
+
* used to manually provide the public key or to automatically derive it.
|
|
1594
1602
|
* @since v0.5.0
|
|
1595
1603
|
* @param encoding The `encoding` of the `privateKey` string.
|
|
1596
1604
|
*/
|
node/ts4.8/module.d.ts
CHANGED
|
@@ -73,11 +73,24 @@ declare module 'module' {
|
|
|
73
73
|
readonly payload: SourceMapPayload;
|
|
74
74
|
constructor(payload: SourceMapPayload);
|
|
75
75
|
/**
|
|
76
|
-
* Given a line
|
|
77
|
-
* an object representing the
|
|
78
|
-
*
|
|
76
|
+
* Given a line offset and column offset in the generated source
|
|
77
|
+
* file, returns an object representing the SourceMap range in the
|
|
78
|
+
* original file if found, or an empty object if not.
|
|
79
|
+
*
|
|
80
|
+
* The object returned contains the following keys:
|
|
81
|
+
*
|
|
82
|
+
* The returned value represents the raw range as it appears in the
|
|
83
|
+
* SourceMap, based on zero-indexed offsets, _not_ 1-indexed line and
|
|
84
|
+
* column numbers as they appear in Error messages and CallSite
|
|
85
|
+
* objects.
|
|
86
|
+
*
|
|
87
|
+
* To get the corresponding 1-indexed line and column numbers from a
|
|
88
|
+
* lineNumber and columnNumber as they are reported by Error stacks
|
|
89
|
+
* and CallSite objects, use `sourceMap.findOrigin(lineNumber, columnNumber)`
|
|
90
|
+
* @param lineOffset The zero-indexed line number offset in the generated source
|
|
91
|
+
* @param columnOffset The zero-indexed column number offset in the generated source
|
|
79
92
|
*/
|
|
80
|
-
findEntry(
|
|
93
|
+
findEntry(lineOffset: number, columnOffset: number): SourceMapping;
|
|
81
94
|
}
|
|
82
95
|
}
|
|
83
96
|
interface Module extends NodeModule {}
|
node/ts4.8/test.d.ts
CHANGED
|
@@ -159,7 +159,7 @@ declare module 'node:test' {
|
|
|
159
159
|
* @param [name='The name'] The name of the suite, which is displayed when reporting test results.
|
|
160
160
|
* @param options Configuration options for the suite. supports the same options as `test([name][, options][, fn])`.
|
|
161
161
|
* @param [fn='A no-op function'] The function under suite declaring all subtests and subsuites. The first argument to this function is a {@link SuiteContext} object.
|
|
162
|
-
* @return `undefined`.
|
|
162
|
+
* @return Immediately fulfilled with `undefined`.
|
|
163
163
|
*/
|
|
164
164
|
function describe(name?: string, options?: TestOptions, fn?: SuiteFn): void;
|
|
165
165
|
function describe(name?: string, fn?: SuiteFn): void;
|
|
@@ -821,6 +821,7 @@ declare module 'node:test' {
|
|
|
821
821
|
* @since v19.1.0, v18.13.0
|
|
822
822
|
*/
|
|
823
823
|
restoreAll(): void;
|
|
824
|
+
timers: MockTimers;
|
|
824
825
|
}
|
|
825
826
|
const mock: MockTracker;
|
|
826
827
|
interface MockFunctionCall<
|
|
@@ -964,6 +965,216 @@ declare module 'node:test' {
|
|
|
964
965
|
*/
|
|
965
966
|
restore(): void;
|
|
966
967
|
}
|
|
968
|
+
type Timer = 'setInterval' | 'clearInterval' | 'setTimeout' | 'clearTimeout';
|
|
969
|
+
/**
|
|
970
|
+
* Mocking timers is a technique commonly used in software testing to simulate and
|
|
971
|
+
* control the behavior of timers, such as `setInterval` and `setTimeout`,
|
|
972
|
+
* without actually waiting for the specified time intervals.
|
|
973
|
+
*
|
|
974
|
+
* The `MockTracker` provides a top-level `timers` export
|
|
975
|
+
* which is a `MockTimers` instance.
|
|
976
|
+
* @since v20.4.0
|
|
977
|
+
* @experimental
|
|
978
|
+
*/
|
|
979
|
+
class MockTimers {
|
|
980
|
+
/**
|
|
981
|
+
* Enables timer mocking for the specified timers.
|
|
982
|
+
*
|
|
983
|
+
* **Note:** When you enable mocking for a specific timer, its associated
|
|
984
|
+
* clear function will also be implicitly mocked.
|
|
985
|
+
*
|
|
986
|
+
* Example usage:
|
|
987
|
+
*
|
|
988
|
+
* ```js
|
|
989
|
+
* import { mock } from 'node:test';
|
|
990
|
+
* mock.timers.enable(['setInterval']);
|
|
991
|
+
* ```
|
|
992
|
+
*
|
|
993
|
+
* ```js
|
|
994
|
+
* const { mock } = require('node:test');
|
|
995
|
+
* mock.timers.enable(['setInterval']);
|
|
996
|
+
* ```
|
|
997
|
+
*
|
|
998
|
+
* The above example enables mocking for the `setInterval` timer and
|
|
999
|
+
* implicitly mocks the `clearInterval` function. Only the `setInterval`and `clearInterval` functions from `node:timers`,`node:timers/promises`, and`globalThis` will be mocked.
|
|
1000
|
+
*
|
|
1001
|
+
* Alternatively, if you call `mock.timers.enable()` without any parameters:
|
|
1002
|
+
*
|
|
1003
|
+
* All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
|
|
1004
|
+
* will be mocked. The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout`functions from `node:timers`, `node:timers/promises`,
|
|
1005
|
+
* and `globalThis` will be mocked.
|
|
1006
|
+
* @since v20.4.0
|
|
1007
|
+
*/
|
|
1008
|
+
enable(timers?: Timer[]): void;
|
|
1009
|
+
/**
|
|
1010
|
+
* This function restores the default behavior of all mocks that were previously
|
|
1011
|
+
* created by this `MockTimers` instance and disassociates the mocks
|
|
1012
|
+
* from the `MockTracker` instance.
|
|
1013
|
+
*
|
|
1014
|
+
* **Note:** After each test completes, this function is called on
|
|
1015
|
+
* the test context's `MockTracker`.
|
|
1016
|
+
*
|
|
1017
|
+
* ```js
|
|
1018
|
+
* import { mock } from 'node:test';
|
|
1019
|
+
* mock.timers.reset();
|
|
1020
|
+
* ```
|
|
1021
|
+
*
|
|
1022
|
+
* ```js
|
|
1023
|
+
* const { mock } = require('node:test');
|
|
1024
|
+
* mock.timers.reset();
|
|
1025
|
+
* ```
|
|
1026
|
+
* @since v20.4.0
|
|
1027
|
+
*/
|
|
1028
|
+
reset(): void;
|
|
1029
|
+
/**
|
|
1030
|
+
* Advances time for all mocked timers.
|
|
1031
|
+
*
|
|
1032
|
+
* **Note:** This diverges from how `setTimeout` in Node.js behaves and accepts
|
|
1033
|
+
* only positive numbers. In Node.js, `setTimeout` with negative numbers is
|
|
1034
|
+
* only supported for web compatibility reasons.
|
|
1035
|
+
*
|
|
1036
|
+
* The following example mocks a `setTimeout` function and
|
|
1037
|
+
* by using `.tick` advances in
|
|
1038
|
+
* time triggering all pending timers.
|
|
1039
|
+
*
|
|
1040
|
+
* ```js
|
|
1041
|
+
* import assert from 'node:assert';
|
|
1042
|
+
* import { test } from 'node:test';
|
|
1043
|
+
*
|
|
1044
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
|
1045
|
+
* const fn = context.mock.fn();
|
|
1046
|
+
*
|
|
1047
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1048
|
+
*
|
|
1049
|
+
* setTimeout(fn, 9999);
|
|
1050
|
+
*
|
|
1051
|
+
* assert.strictEqual(fn.mock.callCount(), 0);
|
|
1052
|
+
*
|
|
1053
|
+
* // Advance in time
|
|
1054
|
+
* context.mock.timers.tick(9999);
|
|
1055
|
+
*
|
|
1056
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
|
1057
|
+
* });
|
|
1058
|
+
* ```
|
|
1059
|
+
*
|
|
1060
|
+
* ```js
|
|
1061
|
+
* const assert = require('node:assert');
|
|
1062
|
+
* const { test } = require('node:test');
|
|
1063
|
+
*
|
|
1064
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
|
1065
|
+
* const fn = context.mock.fn();
|
|
1066
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1067
|
+
*
|
|
1068
|
+
* setTimeout(fn, 9999);
|
|
1069
|
+
* assert.strictEqual(fn.mock.callCount(), 0);
|
|
1070
|
+
*
|
|
1071
|
+
* // Advance in time
|
|
1072
|
+
* context.mock.timers.tick(9999);
|
|
1073
|
+
*
|
|
1074
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
|
1075
|
+
* });
|
|
1076
|
+
* ```
|
|
1077
|
+
*
|
|
1078
|
+
* Alternativelly, the `.tick` function can be called many times
|
|
1079
|
+
*
|
|
1080
|
+
* ```js
|
|
1081
|
+
* import assert from 'node:assert';
|
|
1082
|
+
* import { test } from 'node:test';
|
|
1083
|
+
*
|
|
1084
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
|
1085
|
+
* const fn = context.mock.fn();
|
|
1086
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1087
|
+
* const nineSecs = 9000;
|
|
1088
|
+
* setTimeout(fn, nineSecs);
|
|
1089
|
+
*
|
|
1090
|
+
* const twoSeconds = 3000;
|
|
1091
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1092
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1093
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1094
|
+
*
|
|
1095
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
|
1096
|
+
* });
|
|
1097
|
+
* ```
|
|
1098
|
+
*
|
|
1099
|
+
* ```js
|
|
1100
|
+
* const assert = require('node:assert');
|
|
1101
|
+
* const { test } = require('node:test');
|
|
1102
|
+
*
|
|
1103
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
|
1104
|
+
* const fn = context.mock.fn();
|
|
1105
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1106
|
+
* const nineSecs = 9000;
|
|
1107
|
+
* setTimeout(fn, nineSecs);
|
|
1108
|
+
*
|
|
1109
|
+
* const twoSeconds = 3000;
|
|
1110
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1111
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1112
|
+
* context.mock.timers.tick(twoSeconds);
|
|
1113
|
+
*
|
|
1114
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
|
1115
|
+
* });
|
|
1116
|
+
* ```
|
|
1117
|
+
* @since v20.4.0
|
|
1118
|
+
*/
|
|
1119
|
+
tick(milliseconds: number): void;
|
|
1120
|
+
/**
|
|
1121
|
+
* Triggers all pending mocked timers immediately.
|
|
1122
|
+
*
|
|
1123
|
+
* The example below triggers all pending timers immediately,
|
|
1124
|
+
* causing them to execute without any delay.
|
|
1125
|
+
*
|
|
1126
|
+
* ```js
|
|
1127
|
+
* import assert from 'node:assert';
|
|
1128
|
+
* import { test } from 'node:test';
|
|
1129
|
+
*
|
|
1130
|
+
* test('runAll functions following the given order', (context) => {
|
|
1131
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1132
|
+
* const results = [];
|
|
1133
|
+
* setTimeout(() => results.push(1), 9999);
|
|
1134
|
+
*
|
|
1135
|
+
* // Notice that if both timers have the same timeout,
|
|
1136
|
+
* // the order of execution is guaranteed
|
|
1137
|
+
* setTimeout(() => results.push(3), 8888);
|
|
1138
|
+
* setTimeout(() => results.push(2), 8888);
|
|
1139
|
+
*
|
|
1140
|
+
* assert.deepStrictEqual(results, []);
|
|
1141
|
+
*
|
|
1142
|
+
* context.mock.timers.runAll();
|
|
1143
|
+
*
|
|
1144
|
+
* assert.deepStrictEqual(results, [3, 2, 1]);
|
|
1145
|
+
* });
|
|
1146
|
+
* ```
|
|
1147
|
+
*
|
|
1148
|
+
* ```js
|
|
1149
|
+
* const assert = require('node:assert');
|
|
1150
|
+
* const { test } = require('node:test');
|
|
1151
|
+
*
|
|
1152
|
+
* test('runAll functions following the given order', (context) => {
|
|
1153
|
+
* context.mock.timers.enable(['setTimeout']);
|
|
1154
|
+
* const results = [];
|
|
1155
|
+
* setTimeout(() => results.push(1), 9999);
|
|
1156
|
+
*
|
|
1157
|
+
* // Notice that if both timers have the same timeout,
|
|
1158
|
+
* // the order of execution is guaranteed
|
|
1159
|
+
* setTimeout(() => results.push(3), 8888);
|
|
1160
|
+
* setTimeout(() => results.push(2), 8888);
|
|
1161
|
+
*
|
|
1162
|
+
* assert.deepStrictEqual(results, []);
|
|
1163
|
+
*
|
|
1164
|
+
* context.mock.timers.runAll();
|
|
1165
|
+
*
|
|
1166
|
+
* assert.deepStrictEqual(results, [3, 2, 1]);
|
|
1167
|
+
* });
|
|
1168
|
+
* ```
|
|
1169
|
+
*
|
|
1170
|
+
* **Note:** The `runAll()` function is specifically designed for
|
|
1171
|
+
* triggering timers in the context of timer mocking.
|
|
1172
|
+
* It does not have any effect on real-time system
|
|
1173
|
+
* clocks or actual timers outside of the mocking environment.
|
|
1174
|
+
* @since v20.4.0
|
|
1175
|
+
*/
|
|
1176
|
+
runAll(): void;
|
|
1177
|
+
}
|
|
967
1178
|
export { test as default, run, test, describe, it, before, after, beforeEach, afterEach, mock, skip, only, todo };
|
|
968
1179
|
}
|
|
969
1180
|
|
|
@@ -1139,7 +1350,7 @@ declare module 'node:test/reporters' {
|
|
|
1139
1350
|
* where each passing test is represented by a `.`,
|
|
1140
1351
|
* and each failing test is represented by a `X`.
|
|
1141
1352
|
*/
|
|
1142
|
-
function dot(source: TestEventGenerator): AsyncGenerator<
|
|
1353
|
+
function dot(source: TestEventGenerator): AsyncGenerator<'\n' | '.' | 'X', void>;
|
|
1143
1354
|
/**
|
|
1144
1355
|
* The `tap` reporter outputs the test results in the [TAP](https://testanything.org/) format.
|
|
1145
1356
|
*/
|
node/ts4.8/tls.d.ts
CHANGED
|
@@ -728,6 +728,17 @@ declare module 'tls' {
|
|
|
728
728
|
}
|
|
729
729
|
type SecureVersion = 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1';
|
|
730
730
|
interface SecureContextOptions {
|
|
731
|
+
/**
|
|
732
|
+
* If set, this will be called when a client opens a connection using the ALPN extension.
|
|
733
|
+
* One argument will be passed to the callback: an object containing `servername` and `protocols` fields,
|
|
734
|
+
* respectively containing the server name from the SNI extension (if any) and an array of
|
|
735
|
+
* ALPN protocol name strings. The callback must return either one of the strings listed in `protocols`,
|
|
736
|
+
* which will be returned to the client as the selected ALPN protocol, or `undefined`,
|
|
737
|
+
* to reject the connection with a fatal alert. If a string is returned that does not match one of
|
|
738
|
+
* the client's ALPN protocols, an error will be thrown.
|
|
739
|
+
* This option cannot be used with the `ALPNProtocols` option, and setting both options will throw an error.
|
|
740
|
+
*/
|
|
741
|
+
ALPNCallback?: ((arg: { servername: string; protocols: string[] }) => string | undefined) | undefined;
|
|
731
742
|
/**
|
|
732
743
|
* Optionally override the trusted CA certificates. Default is to trust
|
|
733
744
|
* the well-known CAs curated by Mozilla. Mozilla's CAs are completely
|
node/ts4.8/util.d.ts
CHANGED
|
@@ -1460,32 +1460,72 @@ declare module 'util' {
|
|
|
1460
1460
|
|
|
1461
1461
|
/**
|
|
1462
1462
|
* Gets and sets the type portion of the MIME.
|
|
1463
|
+
*
|
|
1464
|
+
* ```js
|
|
1465
|
+
* import { MIMEType } from 'node:util';
|
|
1466
|
+
*
|
|
1467
|
+
* const myMIME = new MIMEType('text/javascript');
|
|
1468
|
+
* console.log(myMIME.type);
|
|
1469
|
+
* // Prints: text
|
|
1470
|
+
* myMIME.type = 'application';
|
|
1471
|
+
* console.log(myMIME.type);
|
|
1472
|
+
* // Prints: application
|
|
1473
|
+
* console.log(String(myMIME));
|
|
1474
|
+
* // Prints: application/javascript
|
|
1475
|
+
* ```
|
|
1463
1476
|
*/
|
|
1464
1477
|
type: string;
|
|
1465
1478
|
/**
|
|
1466
1479
|
* Gets and sets the subtype portion of the MIME.
|
|
1480
|
+
*
|
|
1481
|
+
* ```js
|
|
1482
|
+
* import { MIMEType } from 'node:util';
|
|
1483
|
+
*
|
|
1484
|
+
* const myMIME = new MIMEType('text/ecmascript');
|
|
1485
|
+
* console.log(myMIME.subtype);
|
|
1486
|
+
* // Prints: ecmascript
|
|
1487
|
+
* myMIME.subtype = 'javascript';
|
|
1488
|
+
* console.log(myMIME.subtype);
|
|
1489
|
+
* // Prints: javascript
|
|
1490
|
+
* console.log(String(myMIME));
|
|
1491
|
+
* // Prints: text/javascript
|
|
1492
|
+
* ```
|
|
1467
1493
|
*/
|
|
1468
1494
|
subtype: string;
|
|
1469
1495
|
/**
|
|
1470
|
-
* Gets the essence of the MIME.
|
|
1471
|
-
*
|
|
1496
|
+
* Gets the essence of the MIME. This property is read only.
|
|
1472
1497
|
* Use `mime.type` or `mime.subtype` to alter the MIME.
|
|
1498
|
+
*
|
|
1499
|
+
* ```js
|
|
1500
|
+
* import { MIMEType } from 'node:util';
|
|
1501
|
+
*
|
|
1502
|
+
* const myMIME = new MIMEType('text/javascript;key=value');
|
|
1503
|
+
* console.log(myMIME.essence);
|
|
1504
|
+
* // Prints: text/javascript
|
|
1505
|
+
* myMIME.type = 'application';
|
|
1506
|
+
* console.log(myMIME.essence);
|
|
1507
|
+
* // Prints: application/javascript
|
|
1508
|
+
* console.log(String(myMIME));
|
|
1509
|
+
* // Prints: application/javascript;key=value
|
|
1510
|
+
* ```
|
|
1473
1511
|
*/
|
|
1474
1512
|
readonly essence: string;
|
|
1475
1513
|
/**
|
|
1476
|
-
* Gets the `MIMEParams` object representing the
|
|
1514
|
+
* Gets the `MIMEParams` object representing the
|
|
1515
|
+
* parameters of the MIME. This property is read-only. See `MIMEParams` documentation for details.
|
|
1477
1516
|
*/
|
|
1478
1517
|
readonly params: MIMEParams;
|
|
1479
1518
|
/**
|
|
1480
|
-
*
|
|
1519
|
+
* The `toString()` method on the `MIMEType` object returns the serialized MIME.
|
|
1481
1520
|
*
|
|
1482
|
-
* Because of the need for standard compliance, this method
|
|
1483
|
-
*
|
|
1521
|
+
* Because of the need for standard compliance, this method does not allow users
|
|
1522
|
+
* to customize the serialization process of the MIME.
|
|
1484
1523
|
*/
|
|
1485
1524
|
toString(): string;
|
|
1486
1525
|
}
|
|
1487
1526
|
/**
|
|
1488
|
-
*
|
|
1527
|
+
* The `MIMEParams` API provides read and write access to the parameters of a`MIMEType`.
|
|
1528
|
+
* @since v19.1.0, v18.13.0
|
|
1489
1529
|
*/
|
|
1490
1530
|
export class MIMEParams {
|
|
1491
1531
|
/**
|
|
@@ -1494,11 +1534,14 @@ declare module 'util' {
|
|
|
1494
1534
|
delete(name: string): void;
|
|
1495
1535
|
/**
|
|
1496
1536
|
* Returns an iterator over each of the name-value pairs in the parameters.
|
|
1537
|
+
* Each item of the iterator is a JavaScript `Array`. The first item of the array
|
|
1538
|
+
* is the `name`, the second item of the array is the `value`.
|
|
1497
1539
|
*/
|
|
1498
1540
|
entries(): IterableIterator<[string, string]>;
|
|
1499
1541
|
/**
|
|
1500
|
-
* Returns the value of the first name-value pair whose name is `name`.
|
|
1501
|
-
*
|
|
1542
|
+
* Returns the value of the first name-value pair whose name is `name`. If there
|
|
1543
|
+
* are no such pairs, `null` is returned.
|
|
1544
|
+
* @return or `null` if there is no name-value pair with the given `name`.
|
|
1502
1545
|
*/
|
|
1503
1546
|
get(name: string): string | null;
|
|
1504
1547
|
/**
|
|
@@ -1507,12 +1550,33 @@ declare module 'util' {
|
|
|
1507
1550
|
has(name: string): boolean;
|
|
1508
1551
|
/**
|
|
1509
1552
|
* Returns an iterator over the names of each name-value pair.
|
|
1553
|
+
*
|
|
1554
|
+
* ```js
|
|
1555
|
+
* import { MIMEType } from 'node:util';
|
|
1556
|
+
*
|
|
1557
|
+
* const { params } = new MIMEType('text/plain;foo=0;bar=1');
|
|
1558
|
+
* for (const name of params.keys()) {
|
|
1559
|
+
* console.log(name);
|
|
1560
|
+
* }
|
|
1561
|
+
* // Prints:
|
|
1562
|
+
* // foo
|
|
1563
|
+
* // bar
|
|
1564
|
+
* ```
|
|
1510
1565
|
*/
|
|
1511
1566
|
keys(): IterableIterator<string>;
|
|
1512
1567
|
/**
|
|
1513
|
-
* Sets the value in the `MIMEParams` object associated with `name` to
|
|
1514
|
-
* If there are any pre-existing name-value pairs whose names are `name`,
|
|
1568
|
+
* 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`,
|
|
1515
1569
|
* set the first such pair's value to `value`.
|
|
1570
|
+
*
|
|
1571
|
+
* ```js
|
|
1572
|
+
* import { MIMEType } from 'node:util';
|
|
1573
|
+
*
|
|
1574
|
+
* const { params } = new MIMEType('text/plain;foo=0;bar=1');
|
|
1575
|
+
* params.set('foo', 'def');
|
|
1576
|
+
* params.set('baz', 'xyz');
|
|
1577
|
+
* console.log(params.toString());
|
|
1578
|
+
* // Prints: foo=def&bar=1&baz=xyz
|
|
1579
|
+
* ```
|
|
1516
1580
|
*/
|
|
1517
1581
|
set(name: string, value: string): void;
|
|
1518
1582
|
/**
|
node/util.d.ts
CHANGED
|
@@ -1460,32 +1460,72 @@ declare module 'util' {
|
|
|
1460
1460
|
|
|
1461
1461
|
/**
|
|
1462
1462
|
* Gets and sets the type portion of the MIME.
|
|
1463
|
+
*
|
|
1464
|
+
* ```js
|
|
1465
|
+
* import { MIMEType } from 'node:util';
|
|
1466
|
+
*
|
|
1467
|
+
* const myMIME = new MIMEType('text/javascript');
|
|
1468
|
+
* console.log(myMIME.type);
|
|
1469
|
+
* // Prints: text
|
|
1470
|
+
* myMIME.type = 'application';
|
|
1471
|
+
* console.log(myMIME.type);
|
|
1472
|
+
* // Prints: application
|
|
1473
|
+
* console.log(String(myMIME));
|
|
1474
|
+
* // Prints: application/javascript
|
|
1475
|
+
* ```
|
|
1463
1476
|
*/
|
|
1464
1477
|
type: string;
|
|
1465
1478
|
/**
|
|
1466
1479
|
* Gets and sets the subtype portion of the MIME.
|
|
1480
|
+
*
|
|
1481
|
+
* ```js
|
|
1482
|
+
* import { MIMEType } from 'node:util';
|
|
1483
|
+
*
|
|
1484
|
+
* const myMIME = new MIMEType('text/ecmascript');
|
|
1485
|
+
* console.log(myMIME.subtype);
|
|
1486
|
+
* // Prints: ecmascript
|
|
1487
|
+
* myMIME.subtype = 'javascript';
|
|
1488
|
+
* console.log(myMIME.subtype);
|
|
1489
|
+
* // Prints: javascript
|
|
1490
|
+
* console.log(String(myMIME));
|
|
1491
|
+
* // Prints: text/javascript
|
|
1492
|
+
* ```
|
|
1467
1493
|
*/
|
|
1468
1494
|
subtype: string;
|
|
1469
1495
|
/**
|
|
1470
|
-
* Gets the essence of the MIME.
|
|
1471
|
-
*
|
|
1496
|
+
* Gets the essence of the MIME. This property is read only.
|
|
1472
1497
|
* Use `mime.type` or `mime.subtype` to alter the MIME.
|
|
1498
|
+
*
|
|
1499
|
+
* ```js
|
|
1500
|
+
* import { MIMEType } from 'node:util';
|
|
1501
|
+
*
|
|
1502
|
+
* const myMIME = new MIMEType('text/javascript;key=value');
|
|
1503
|
+
* console.log(myMIME.essence);
|
|
1504
|
+
* // Prints: text/javascript
|
|
1505
|
+
* myMIME.type = 'application';
|
|
1506
|
+
* console.log(myMIME.essence);
|
|
1507
|
+
* // Prints: application/javascript
|
|
1508
|
+
* console.log(String(myMIME));
|
|
1509
|
+
* // Prints: application/javascript;key=value
|
|
1510
|
+
* ```
|
|
1473
1511
|
*/
|
|
1474
1512
|
readonly essence: string;
|
|
1475
1513
|
/**
|
|
1476
|
-
* Gets the `MIMEParams` object representing the
|
|
1514
|
+
* Gets the `MIMEParams` object representing the
|
|
1515
|
+
* parameters of the MIME. This property is read-only. See `MIMEParams` documentation for details.
|
|
1477
1516
|
*/
|
|
1478
1517
|
readonly params: MIMEParams;
|
|
1479
1518
|
/**
|
|
1480
|
-
*
|
|
1519
|
+
* The `toString()` method on the `MIMEType` object returns the serialized MIME.
|
|
1481
1520
|
*
|
|
1482
|
-
* Because of the need for standard compliance, this method
|
|
1483
|
-
*
|
|
1521
|
+
* Because of the need for standard compliance, this method does not allow users
|
|
1522
|
+
* to customize the serialization process of the MIME.
|
|
1484
1523
|
*/
|
|
1485
1524
|
toString(): string;
|
|
1486
1525
|
}
|
|
1487
1526
|
/**
|
|
1488
|
-
*
|
|
1527
|
+
* The `MIMEParams` API provides read and write access to the parameters of a`MIMEType`.
|
|
1528
|
+
* @since v19.1.0, v18.13.0
|
|
1489
1529
|
*/
|
|
1490
1530
|
export class MIMEParams {
|
|
1491
1531
|
/**
|
|
@@ -1494,11 +1534,14 @@ declare module 'util' {
|
|
|
1494
1534
|
delete(name: string): void;
|
|
1495
1535
|
/**
|
|
1496
1536
|
* Returns an iterator over each of the name-value pairs in the parameters.
|
|
1537
|
+
* Each item of the iterator is a JavaScript `Array`. The first item of the array
|
|
1538
|
+
* is the `name`, the second item of the array is the `value`.
|
|
1497
1539
|
*/
|
|
1498
1540
|
entries(): IterableIterator<[name: string, value: string]>;
|
|
1499
1541
|
/**
|
|
1500
|
-
* Returns the value of the first name-value pair whose name is `name`.
|
|
1501
|
-
*
|
|
1542
|
+
* Returns the value of the first name-value pair whose name is `name`. If there
|
|
1543
|
+
* are no such pairs, `null` is returned.
|
|
1544
|
+
* @return or `null` if there is no name-value pair with the given `name`.
|
|
1502
1545
|
*/
|
|
1503
1546
|
get(name: string): string | null;
|
|
1504
1547
|
/**
|
|
@@ -1507,12 +1550,33 @@ declare module 'util' {
|
|
|
1507
1550
|
has(name: string): boolean;
|
|
1508
1551
|
/**
|
|
1509
1552
|
* Returns an iterator over the names of each name-value pair.
|
|
1553
|
+
*
|
|
1554
|
+
* ```js
|
|
1555
|
+
* import { MIMEType } from 'node:util';
|
|
1556
|
+
*
|
|
1557
|
+
* const { params } = new MIMEType('text/plain;foo=0;bar=1');
|
|
1558
|
+
* for (const name of params.keys()) {
|
|
1559
|
+
* console.log(name);
|
|
1560
|
+
* }
|
|
1561
|
+
* // Prints:
|
|
1562
|
+
* // foo
|
|
1563
|
+
* // bar
|
|
1564
|
+
* ```
|
|
1510
1565
|
*/
|
|
1511
1566
|
keys(): IterableIterator<string>;
|
|
1512
1567
|
/**
|
|
1513
|
-
* Sets the value in the `MIMEParams` object associated with `name` to
|
|
1514
|
-
* If there are any pre-existing name-value pairs whose names are `name`,
|
|
1568
|
+
* 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`,
|
|
1515
1569
|
* set the first such pair's value to `value`.
|
|
1570
|
+
*
|
|
1571
|
+
* ```js
|
|
1572
|
+
* import { MIMEType } from 'node:util';
|
|
1573
|
+
*
|
|
1574
|
+
* const { params } = new MIMEType('text/plain;foo=0;bar=1');
|
|
1575
|
+
* params.set('foo', 'def');
|
|
1576
|
+
* params.set('baz', 'xyz');
|
|
1577
|
+
* console.log(params.toString());
|
|
1578
|
+
* // Prints: foo=def&bar=1&baz=xyz
|
|
1579
|
+
* ```
|
|
1516
1580
|
*/
|
|
1517
1581
|
set(name: string, value: string): void;
|
|
1518
1582
|
/**
|