@types/node 16.4.2 → 16.4.6

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/string_decoder.d.ts CHANGED
@@ -1,11 +1,67 @@
1
+ /**
2
+ * The `string_decoder` module provides an API for decoding `Buffer` objects into
3
+ * strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16
4
+ * characters. It can be accessed using:
5
+ *
6
+ * ```js
7
+ * const { StringDecoder } = require('string_decoder');
8
+ * ```
9
+ *
10
+ * The following example shows the basic use of the `StringDecoder` class.
11
+ *
12
+ * ```js
13
+ * const { StringDecoder } = require('string_decoder');
14
+ * const decoder = new StringDecoder('utf8');
15
+ *
16
+ * const cent = Buffer.from([0xC2, 0xA2]);
17
+ * console.log(decoder.write(cent));
18
+ *
19
+ * const euro = Buffer.from([0xE2, 0x82, 0xAC]);
20
+ * console.log(decoder.write(euro));
21
+ * ```
22
+ *
23
+ * When a `Buffer` instance is written to the `StringDecoder` instance, an
24
+ * internal buffer is used to ensure that the decoded string does not contain
25
+ * any incomplete multibyte characters. These are held in the buffer until the
26
+ * next call to `stringDecoder.write()` or until `stringDecoder.end()` is called.
27
+ *
28
+ * In the following example, the three UTF-8 encoded bytes of the European Euro
29
+ * symbol (`€`) are written over three separate operations:
30
+ *
31
+ * ```js
32
+ * const { StringDecoder } = require('string_decoder');
33
+ * const decoder = new StringDecoder('utf8');
34
+ *
35
+ * decoder.write(Buffer.from([0xE2]));
36
+ * decoder.write(Buffer.from([0x82]));
37
+ * console.log(decoder.end(Buffer.from([0xAC])));
38
+ * ```
39
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/string_decoder.js)
40
+ */
1
41
  declare module 'string_decoder' {
2
42
  class StringDecoder {
3
43
  constructor(encoding?: BufferEncoding);
44
+ /**
45
+ * Returns a decoded string, ensuring that any incomplete multibyte characters at
46
+ * the end of the `Buffer`, or `TypedArray`, or `DataView` are omitted from the
47
+ * returned string and stored in an internal buffer for the next call to`stringDecoder.write()` or `stringDecoder.end()`.
48
+ * @since v0.1.99
49
+ * @param buffer A `Buffer`, or `TypedArray`, or `DataView` containing the bytes to decode.
50
+ */
4
51
  write(buffer: Buffer): string;
52
+ /**
53
+ * Returns any remaining input stored in the internal buffer as a string. Bytes
54
+ * representing incomplete UTF-8 and UTF-16 characters will be replaced with
55
+ * substitution characters appropriate for the character encoding.
56
+ *
57
+ * If the `buffer` argument is provided, one final call to `stringDecoder.write()`is performed before returning the remaining input.
58
+ * After `end()` is called, the `stringDecoder` object can be reused for new input.
59
+ * @since v0.9.3
60
+ * @param buffer A `Buffer`, or `TypedArray`, or `DataView` containing the bytes to decode.
61
+ */
5
62
  end(buffer?: Buffer): string;
6
63
  }
7
64
  }
8
-
9
65
  declare module 'node:string_decoder' {
10
66
  export * from 'string_decoder';
11
67
  }
node/timers/promises.d.ts CHANGED
@@ -1,25 +1,113 @@
1
+ /**
2
+ * The `timers/promises` API provides an alternative set of timer functions
3
+ * that return `Promise` objects. The API is accessible via`require('timers/promises')`.
4
+ *
5
+ * ```js
6
+ * import {
7
+ * setTimeout,
8
+ * setImmediate,
9
+ * setInterval,
10
+ * } from 'timers/promises';
11
+ * ```
12
+ *
13
+ * ```js
14
+ * const {
15
+ * setTimeout,
16
+ * setImmediate,
17
+ * setInterval,
18
+ * } = require('timers/promises');
19
+ * ```
20
+ * @since v15.0.0
21
+ */
1
22
  declare module 'timers/promises' {
2
23
  import { TimerOptions } from 'node:timers';
3
-
4
24
  /**
5
- * Returns a promise that resolves after the specified delay in milliseconds.
6
- * @param delay defaults to 1
25
+ * ```js
26
+ * import {
27
+ * setTimeout,
28
+ * } from 'timers/promises';
29
+ *
30
+ * const res = await setTimeout(100, 'result');
31
+ *
32
+ * console.log(res); // Prints 'result'
33
+ * ```
34
+ *
35
+ * ```js
36
+ * const {
37
+ * setTimeout,
38
+ * } = require('timers/promises');
39
+ *
40
+ * setTimeout(100, 'result').then((res) => {
41
+ * console.log(res); // Prints 'result'
42
+ * });
43
+ * ```
44
+ * @since v15.0.0
45
+ * @param delay The number of milliseconds to wait before fulfilling the promise.
46
+ * @param value A value with which the promise is fulfilled.
7
47
  */
8
48
  function setTimeout<T = void>(delay?: number, value?: T, options?: TimerOptions): Promise<T>;
9
-
10
49
  /**
11
- * Returns a promise that resolves in the next tick.
50
+ * ```js
51
+ * import {
52
+ * setImmediate,
53
+ * } from 'timers/promises';
54
+ *
55
+ * const res = await setImmediate('result');
56
+ *
57
+ * console.log(res); // Prints 'result'
58
+ * ```
59
+ *
60
+ * ```js
61
+ * const {
62
+ * setImmediate,
63
+ * } = require('timers/promises');
64
+ *
65
+ * setImmediate('result').then((res) => {
66
+ * console.log(res); // Prints 'result'
67
+ * });
68
+ * ```
69
+ * @since v15.0.0
70
+ * @param value A value with which the promise is fulfilled.
12
71
  */
13
72
  function setImmediate<T = void>(value?: T, options?: TimerOptions): Promise<T>;
14
-
15
73
  /**
74
+ * Returns an async iterator that generates values in an interval of `delay` ms.
75
+ *
76
+ * ```js
77
+ * import {
78
+ * setInterval,
79
+ * } from 'timers/promises';
80
+ *
81
+ * const interval = 100;
82
+ * for await (const startTime of setInterval(interval, Date.now())) {
83
+ * const now = Date.now();
84
+ * console.log(now);
85
+ * if ((now - startTime) > 1000)
86
+ * break;
87
+ * }
88
+ * console.log(Date.now());
89
+ * ```
90
+ *
91
+ * ```js
92
+ * const {
93
+ * setInterval,
94
+ * } = require('timers/promises');
95
+ * const interval = 100;
16
96
  *
17
- * Returns an async iterator that generates values in an interval of delay ms.
18
- * @param delay defaults to 1
97
+ * (async function() {
98
+ * for await (const startTime of setInterval(interval, Date.now())) {
99
+ * const now = Date.now();
100
+ * console.log(now);
101
+ * if ((now - startTime) > 1000)
102
+ * break;
103
+ * }
104
+ * console.log(Date.now());
105
+ * })();
106
+ * ```
107
+ * @since v15.9.0
19
108
  */
20
109
  function setInterval<T = void>(delay?: number, value?: T, options?: TimerOptions): AsyncIterable<T>;
21
110
  }
22
-
23
111
  declare module 'node:timers/promises' {
24
112
  export * from 'timers/promises';
25
113
  }
node/timers.d.ts CHANGED
@@ -1,7 +1,16 @@
1
+ /**
2
+ * The `timer` module exposes a global API for scheduling functions to
3
+ * be called at some future period of time. Because the timer functions are
4
+ * globals, there is no need to call `require('timers')` to use the API.
5
+ *
6
+ * The timer functions within Node.js implement a similar API as the timers API
7
+ * provided by Web Browsers but use a different internal implementation that is
8
+ * built around the Node.js [Event Loop](https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#setimmediate-vs-settimeout).
9
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/timers.js)
10
+ */
1
11
  declare module 'timers' {
2
12
  import { Abortable } from 'node:events';
3
13
  import { setTimeout as setTimeoutPromise, setImmediate as setImmediatePromise, setInterval as setIntervalPromise } from 'node:timers/promises';
4
-
5
14
  interface TimerOptions extends Abortable {
6
15
  /**
7
16
  * Set to `false` to indicate that the scheduled `Timeout`
@@ -10,14 +19,12 @@ declare module 'timers' {
10
19
  */
11
20
  ref?: boolean | undefined;
12
21
  }
13
-
14
22
  let setTimeout: typeof global.setTimeout;
15
23
  let clearTimeout: typeof global.clearTimeout;
16
24
  let setInterval: typeof global.setInterval;
17
25
  let clearInterval: typeof global.clearInterval;
18
26
  let setImmediate: typeof global.setImmediate;
19
27
  let clearImmediate: typeof global.clearImmediate;
20
-
21
28
  global {
22
29
  namespace NodeJS {
23
30
  // compatibility with older typings
@@ -26,19 +33,35 @@ declare module 'timers' {
26
33
  refresh(): this;
27
34
  [Symbol.toPrimitive](): number;
28
35
  }
29
-
30
36
  interface Immediate extends RefCounted {
37
+ /**
38
+ * If true, the `Immediate` object will keep the Node.js event loop active.
39
+ * @since v11.0.0
40
+ */
31
41
  hasRef(): boolean;
32
42
  _onImmediate: Function; // to distinguish it from the Timeout class
33
43
  }
34
-
35
44
  interface Timeout extends Timer {
45
+ /**
46
+ * If true, the `Timeout` object will keep the Node.js event loop active.
47
+ * @since v11.0.0
48
+ */
36
49
  hasRef(): boolean;
50
+ /**
51
+ * Sets the timer's start time to the current time, and reschedules the timer to
52
+ * call its callback at the previously specified duration adjusted to the current
53
+ * time. This is useful for refreshing a timer without allocating a new
54
+ * JavaScript object.
55
+ *
56
+ * Using this on a timer that has already called its callback will reactivate the
57
+ * timer.
58
+ * @since v10.2.0
59
+ * @return a reference to `timeout`
60
+ */
37
61
  refresh(): this;
38
62
  [Symbol.toPrimitive](): number;
39
63
  }
40
64
  }
41
-
42
65
  function setTimeout<TArgs extends any[]>(callback: (...args: TArgs) => void, ms?: number, ...args: TArgs): NodeJS.Timeout;
43
66
  // util.promisify no rest args compability
44
67
  // tslint:disable-next-line void-return
@@ -47,7 +70,6 @@ declare module 'timers' {
47
70
  const __promisify__: typeof setTimeoutPromise;
48
71
  }
49
72
  function clearTimeout(timeoutId: NodeJS.Timeout): void;
50
-
51
73
  function setInterval<TArgs extends any[]>(callback: (...args: TArgs) => void, ms?: number, ...args: TArgs): NodeJS.Timer;
52
74
  // util.promisify no rest args compability
53
75
  // tslint:disable-next-line void-return
@@ -56,7 +78,6 @@ declare module 'timers' {
56
78
  const __promisify__: typeof setIntervalPromise;
57
79
  }
58
80
  function clearInterval(intervalId: NodeJS.Timeout): void;
59
-
60
81
  function setImmediate<TArgs extends any[]>(callback: (...args: TArgs) => void, ...args: TArgs): NodeJS.Immediate;
61
82
  // util.promisify no rest args compability
62
83
  // tslint:disable-next-line void-return
@@ -65,11 +86,9 @@ declare module 'timers' {
65
86
  const __promisify__: typeof setImmediatePromise;
66
87
  }
67
88
  function clearImmediate(immediateId: NodeJS.Immediate): void;
68
-
69
89
  function queueMicrotask(callback: () => void): void;
70
90
  }
71
91
  }
72
-
73
92
  declare module 'node:timers' {
74
93
  export * from 'timers';
75
94
  }