@types/node 18.19.76 → 18.19.78

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 v18.19/README.md CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for node (https://nodejs.org/).
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node/v18.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Thu, 13 Feb 2025 22:34:15 GMT
11
+ * Last updated: Fri, 28 Feb 2025 22:02:14 GMT
12
12
  * Dependencies: [undici-types](https://npmjs.com/package/undici-types)
13
13
 
14
14
  # Credits
@@ -1,4 +1,6 @@
1
1
  declare module "buffer" {
2
+ type ImplicitArrayBuffer<T extends WithImplicitCoercion<ArrayBufferLike>> = T extends
3
+ { valueOf(): infer V extends ArrayBufferLike } ? V : T;
2
4
  global {
3
5
  interface BufferConstructor {
4
6
  // see buffer.d.ts for implementation shared with all TypeScript versions
@@ -24,7 +26,7 @@ declare module "buffer" {
24
26
  * @param array The octets to store.
25
27
  * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
26
28
  */
27
- new(array: Uint8Array): Buffer<ArrayBuffer>;
29
+ new(array: ArrayLike<number>): Buffer<ArrayBuffer>;
28
30
  /**
29
31
  * Produces a Buffer backed by the same allocated memory as
30
32
  * the given {ArrayBuffer}/{SharedArrayBuffer}.
@@ -33,20 +35,6 @@ declare module "buffer" {
33
35
  * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead.
34
36
  */
35
37
  new<TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: TArrayBuffer): Buffer<TArrayBuffer>;
36
- /**
37
- * Allocates a new buffer containing the given {array} of octets.
38
- *
39
- * @param array The octets to store.
40
- * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
41
- */
42
- new(array: readonly any[]): Buffer<ArrayBuffer>;
43
- /**
44
- * Copies the passed {buffer} data onto a new {Buffer} instance.
45
- *
46
- * @param buffer The buffer to copy.
47
- * @deprecated since v10.0.0 - Use `Buffer.from(buffer)` instead.
48
- */
49
- new(buffer: Buffer): Buffer<ArrayBuffer>;
50
38
  /**
51
39
  * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`.
52
40
  * Array entries outside that range will be truncated to fit into it.
@@ -57,41 +45,116 @@ declare module "buffer" {
57
45
  * // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
58
46
  * const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
59
47
  * ```
60
- *
61
- * If `array` is an `Array`\-like object (that is, one with a `length` property of
48
+ * If `array` is an `Array`-like object (that is, one with a `length` property of
62
49
  * type `number`), it is treated as if it is an array, unless it is a `Buffer` or
63
- * a `Uint8Array`. This means all other `TypedArray` variants get treated as an`Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use `Buffer.copyBytesFrom()`.
50
+ * a `Uint8Array`. This means all other `TypedArray` variants get treated as an
51
+ * `Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use
52
+ * `Buffer.copyBytesFrom()`.
64
53
  *
65
54
  * A `TypeError` will be thrown if `array` is not an `Array` or another type
66
55
  * appropriate for `Buffer.from()` variants.
67
56
  *
68
- * `Buffer.from(array)` and `Buffer.from(string)` may also use the internal`Buffer` pool like `Buffer.allocUnsafe()` does.
57
+ * `Buffer.from(array)` and `Buffer.from(string)` may also use the internal
58
+ * `Buffer` pool like `Buffer.allocUnsafe()` does.
69
59
  * @since v5.10.0
70
60
  */
71
- from<TArrayBuffer extends ArrayBufferLike>(
72
- arrayBuffer: WithImplicitCoercion<TArrayBuffer>,
73
- byteOffset?: number,
74
- length?: number,
75
- ): Buffer<TArrayBuffer>;
61
+ from(array: WithImplicitCoercion<ArrayLike<number>>): Buffer<ArrayBuffer>;
76
62
  /**
77
- * Creates a new Buffer using the passed {data}
78
- * @param data data to create a new Buffer
63
+ * This creates a view of the `ArrayBuffer` without copying the underlying
64
+ * memory. For example, when passed a reference to the `.buffer` property of a
65
+ * `TypedArray` instance, the newly created `Buffer` will share the same
66
+ * allocated memory as the `TypedArray`'s underlying `ArrayBuffer`.
67
+ *
68
+ * ```js
69
+ * import { Buffer } from 'node:buffer';
70
+ *
71
+ * const arr = new Uint16Array(2);
72
+ *
73
+ * arr[0] = 5000;
74
+ * arr[1] = 4000;
75
+ *
76
+ * // Shares memory with `arr`.
77
+ * const buf = Buffer.from(arr.buffer);
78
+ *
79
+ * console.log(buf);
80
+ * // Prints: <Buffer 88 13 a0 0f>
81
+ *
82
+ * // Changing the original Uint16Array changes the Buffer also.
83
+ * arr[1] = 6000;
84
+ *
85
+ * console.log(buf);
86
+ * // Prints: <Buffer 88 13 70 17>
87
+ * ```
88
+ * The optional `byteOffset` and `length` arguments specify a memory range within
89
+ * the `arrayBuffer` that will be shared by the `Buffer`.
90
+ *
91
+ * ```js
92
+ * import { Buffer } from 'node:buffer';
93
+ *
94
+ * const ab = new ArrayBuffer(10);
95
+ * const buf = Buffer.from(ab, 0, 2);
96
+ *
97
+ * console.log(buf.length);
98
+ * // Prints: 2
99
+ * ```
100
+ *
101
+ * A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer` or a
102
+ * `SharedArrayBuffer` or another type appropriate for `Buffer.from()`
103
+ * variants.
104
+ *
105
+ * It is important to remember that a backing `ArrayBuffer` can cover a range
106
+ * of memory that extends beyond the bounds of a `TypedArray` view. A new
107
+ * `Buffer` created using the `buffer` property of a `TypedArray` may extend
108
+ * beyond the range of the `TypedArray`:
109
+ *
110
+ * ```js
111
+ * import { Buffer } from 'node:buffer';
112
+ *
113
+ * const arrA = Uint8Array.from([0x63, 0x64, 0x65, 0x66]); // 4 elements
114
+ * const arrB = new Uint8Array(arrA.buffer, 1, 2); // 2 elements
115
+ * console.log(arrA.buffer === arrB.buffer); // true
116
+ *
117
+ * const buf = Buffer.from(arrB.buffer);
118
+ * console.log(buf);
119
+ * // Prints: <Buffer 63 64 65 66>
120
+ * ```
121
+ * @since v5.10.0
122
+ * @param arrayBuffer An `ArrayBuffer`, `SharedArrayBuffer`, for example the
123
+ * `.buffer` property of a `TypedArray`.
124
+ * @param byteOffset Index of first byte to expose. **Default:** `0`.
125
+ * @param length Number of bytes to expose. **Default:**
126
+ * `arrayBuffer.byteLength - byteOffset`.
79
127
  */
80
- from(data: Uint8Array | readonly number[]): Buffer<ArrayBuffer>;
81
- from(data: WithImplicitCoercion<Uint8Array | readonly number[] | string>): Buffer<ArrayBuffer>;
128
+ from<TArrayBuffer extends WithImplicitCoercion<ArrayBufferLike>>(
129
+ arrayBuffer: TArrayBuffer,
130
+ byteOffset?: number,
131
+ length?: number,
132
+ ): Buffer<ImplicitArrayBuffer<TArrayBuffer>>;
82
133
  /**
83
- * Creates a new Buffer containing the given JavaScript string {str}.
84
- * If provided, the {encoding} parameter identifies the character encoding.
85
- * If not provided, {encoding} defaults to 'utf8'.
134
+ * Creates a new `Buffer` containing `string`. The `encoding` parameter identifies
135
+ * the character encoding to be used when converting `string` into bytes.
136
+ *
137
+ * ```js
138
+ * import { Buffer } from 'node:buffer';
139
+ *
140
+ * const buf1 = Buffer.from('this is a tést');
141
+ * const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');
142
+ *
143
+ * console.log(buf1.toString());
144
+ * // Prints: this is a tést
145
+ * console.log(buf2.toString());
146
+ * // Prints: this is a tést
147
+ * console.log(buf1.toString('latin1'));
148
+ * // Prints: this is a tést
149
+ * ```
150
+ *
151
+ * A `TypeError` will be thrown if `string` is not a string or another type
152
+ * appropriate for `Buffer.from()` variants.
153
+ * @since v5.10.0
154
+ * @param string A string to encode.
155
+ * @param encoding The encoding of `string`. **Default:** `'utf8'`.
86
156
  */
87
- from(
88
- str:
89
- | WithImplicitCoercion<string>
90
- | {
91
- [Symbol.toPrimitive](hint: "string"): string;
92
- },
93
- encoding?: BufferEncoding,
94
- ): Buffer<ArrayBuffer>;
157
+ from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
95
158
  /**
96
159
  * Creates a new Buffer using the passed {data}
97
160
  * @param values to create a new Buffer
@@ -382,4 +445,10 @@ declare module "buffer" {
382
445
  subarray(start?: number, end?: number): Buffer<TArrayBuffer>;
383
446
  }
384
447
  }
448
+ /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */
449
+ var SlowBuffer: {
450
+ /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */
451
+ new(size: number): Buffer<ArrayBuffer>;
452
+ prototype: Buffer;
453
+ };
385
454
  }
node v18.19/buffer.d.ts CHANGED
@@ -104,11 +104,6 @@ declare module "buffer" {
104
104
  * @param toEnc To target encoding.
105
105
  */
106
106
  export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer;
107
- export const SlowBuffer: {
108
- /** @deprecated since v6.0.0, use `Buffer.allocUnsafeSlow()` */
109
- new(size: number): Buffer;
110
- prototype: Buffer;
111
- };
112
107
  /**
113
108
  * Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using
114
109
  * a prior call to `URL.createObjectURL()`.
@@ -216,7 +211,10 @@ declare module "buffer" {
216
211
  }
217
212
  export import atob = globalThis.atob;
218
213
  export import btoa = globalThis.btoa;
219
-
214
+ export type WithImplicitCoercion<T> =
215
+ | T
216
+ | { valueOf(): T }
217
+ | (T extends string ? { [Symbol.toPrimitive](hint: "string"): T } : never);
220
218
  global {
221
219
  namespace NodeJS {
222
220
  export { BufferEncoding };
@@ -234,11 +232,6 @@ declare module "buffer" {
234
232
  | "latin1"
235
233
  | "binary"
236
234
  | "hex";
237
- type WithImplicitCoercion<T> =
238
- | T
239
- | {
240
- valueOf(): T;
241
- };
242
235
  /**
243
236
  * Raw data is stored in instances of the Buffer class.
244
237
  * A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "18.19.76",
3
+ "version": "18.19.78",
4
4
  "description": "TypeScript definitions for node",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
6
6
  "license": "MIT",
@@ -220,6 +220,6 @@
220
220
  "undici-types": "~5.26.4"
221
221
  },
222
222
  "peerDependencies": {},
223
- "typesPublisherContentHash": "8b84ac7ae7decd715ecc009f000a5d2ef12d25a5771e69a2c02890b57118880d",
223
+ "typesPublisherContentHash": "53c96e56ee2759566e81a31cb23f4874fe03fa92030604a19231d864af73dbcf",
224
224
  "typeScriptVersion": "5.0"
225
225
  }
node v18.19/stream.d.ts CHANGED
@@ -20,12 +20,11 @@ declare module "stream" {
20
20
  import { Abortable, EventEmitter } from "node:events";
21
21
  import { Blob as NodeBlob } from "node:buffer";
22
22
  import * as streamPromises from "node:stream/promises";
23
- import * as streamConsumers from "node:stream/consumers";
24
23
  import * as streamWeb from "node:stream/web";
25
24
 
26
25
  type ComposeFnParam = (source: any) => void;
27
26
 
28
- class internal extends EventEmitter {
27
+ class Stream extends EventEmitter {
29
28
  pipe<T extends NodeJS.WritableStream>(
30
29
  destination: T,
31
30
  options?: {
@@ -37,10 +36,10 @@ declare module "stream" {
37
36
  options?: { signal: AbortSignal },
38
37
  ): T;
39
38
  }
40
- namespace internal {
41
- class Stream extends internal {
42
- constructor(opts?: ReadableOptions);
43
- }
39
+ namespace Stream {
40
+ export { Stream, streamPromises as promises };
41
+ }
42
+ namespace Stream {
44
43
  interface StreamOptions<T extends Stream> extends Abortable {
45
44
  emitClose?: boolean | undefined;
46
45
  highWaterMark?: number | undefined;
@@ -49,9 +48,9 @@ declare module "stream" {
49
48
  destroy?(this: T, error: Error | null, callback: (error?: Error | null) => void): void;
50
49
  autoDestroy?: boolean | undefined;
51
50
  }
52
- interface ReadableOptions extends StreamOptions<Readable> {
51
+ interface ReadableOptions<T extends Readable = Readable> extends StreamOptions<T> {
53
52
  encoding?: BufferEncoding | undefined;
54
- read?(this: Readable, size: number): void;
53
+ read?(this: T, size: number): void;
55
54
  }
56
55
  interface ArrayOptions {
57
56
  /** the maximum concurrent invocations of `fn` to call on the stream at once. **Default: 1**. */
@@ -686,24 +685,24 @@ declare module "stream" {
686
685
  */
687
686
  [Symbol.asyncDispose](): Promise<void>;
688
687
  }
689
- interface WritableOptions extends StreamOptions<Writable> {
688
+ interface WritableOptions<T extends Writable = Writable> extends StreamOptions<T> {
690
689
  decodeStrings?: boolean | undefined;
691
690
  defaultEncoding?: BufferEncoding | undefined;
692
691
  write?(
693
- this: Writable,
692
+ this: T,
694
693
  chunk: any,
695
694
  encoding: BufferEncoding,
696
695
  callback: (error?: Error | null) => void,
697
696
  ): void;
698
697
  writev?(
699
- this: Writable,
698
+ this: T,
700
699
  chunks: Array<{
701
700
  chunk: any;
702
701
  encoding: BufferEncoding;
703
702
  }>,
704
703
  callback: (error?: Error | null) => void,
705
704
  ): void;
706
- final?(this: Writable, callback: (error?: Error | null) => void): void;
705
+ final?(this: T, callback: (error?: Error | null) => void): void;
707
706
  }
708
707
  /**
709
708
  * @since v0.9.4
@@ -1011,26 +1010,13 @@ declare module "stream" {
1011
1010
  removeListener(event: "unpipe", listener: (src: Readable) => void): this;
1012
1011
  removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
1013
1012
  }
1014
- interface DuplexOptions extends ReadableOptions, WritableOptions {
1013
+ interface DuplexOptions<T extends Duplex = Duplex> extends ReadableOptions<T>, WritableOptions<T> {
1015
1014
  allowHalfOpen?: boolean | undefined;
1016
1015
  readableObjectMode?: boolean | undefined;
1017
1016
  writableObjectMode?: boolean | undefined;
1018
1017
  readableHighWaterMark?: number | undefined;
1019
1018
  writableHighWaterMark?: number | undefined;
1020
1019
  writableCorked?: number | undefined;
1021
- construct?(this: Duplex, callback: (error?: Error | null) => void): void;
1022
- read?(this: Duplex, size: number): void;
1023
- write?(this: Duplex, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
1024
- writev?(
1025
- this: Duplex,
1026
- chunks: Array<{
1027
- chunk: any;
1028
- encoding: BufferEncoding;
1029
- }>,
1030
- callback: (error?: Error | null) => void,
1031
- ): void;
1032
- final?(this: Duplex, callback: (error?: Error | null) => void): void;
1033
- destroy?(this: Duplex, error: Error | null, callback: (error?: Error | null) => void): void;
1034
1020
  }
1035
1021
  /**
1036
1022
  * Duplex streams are streams that implement both the `Readable` and `Writable` interfaces.
@@ -1042,17 +1028,7 @@ declare module "stream" {
1042
1028
  * * `crypto streams`
1043
1029
  * @since v0.9.4
1044
1030
  */
1045
- class Duplex extends Readable implements Writable {
1046
- readonly writable: boolean;
1047
- readonly writableEnded: boolean;
1048
- readonly writableFinished: boolean;
1049
- readonly writableHighWaterMark: number;
1050
- readonly writableLength: number;
1051
- readonly writableObjectMode: boolean;
1052
- readonly writableCorked: number;
1053
- readonly writableNeedDrain: boolean;
1054
- readonly closed: boolean;
1055
- readonly errored: Error | null;
1031
+ class Duplex extends Stream implements NodeJS.ReadWriteStream {
1056
1032
  /**
1057
1033
  * If `false` then the stream will automatically end the writable side when the
1058
1034
  * readable side ends. Set initially by the `allowHalfOpen` constructor option,
@@ -1097,24 +1073,6 @@ declare module "stream" {
1097
1073
  | Promise<any>
1098
1074
  | Object,
1099
1075
  ): Duplex;
1100
- _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
1101
- _writev?(
1102
- chunks: Array<{
1103
- chunk: any;
1104
- encoding: BufferEncoding;
1105
- }>,
1106
- callback: (error?: Error | null) => void,
1107
- ): void;
1108
- _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
1109
- _final(callback: (error?: Error | null) => void): void;
1110
- write(chunk: any, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
1111
- write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
1112
- setDefaultEncoding(encoding: BufferEncoding): this;
1113
- end(cb?: () => void): this;
1114
- end(chunk: any, cb?: () => void): this;
1115
- end(chunk: any, encoding?: BufferEncoding, cb?: () => void): this;
1116
- cork(): void;
1117
- uncork(): void;
1118
1076
  /**
1119
1077
  * Event emitter
1120
1078
  * The defined events on documents including:
@@ -1215,28 +1173,11 @@ declare module "stream" {
1215
1173
  removeListener(event: "unpipe", listener: (src: Readable) => void): this;
1216
1174
  removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
1217
1175
  }
1176
+ interface Duplex extends Readable, Writable {}
1218
1177
  type TransformCallback = (error?: Error | null, data?: any) => void;
1219
- interface TransformOptions extends DuplexOptions {
1220
- construct?(this: Transform, callback: (error?: Error | null) => void): void;
1221
- read?(this: Transform, size: number): void;
1222
- write?(
1223
- this: Transform,
1224
- chunk: any,
1225
- encoding: BufferEncoding,
1226
- callback: (error?: Error | null) => void,
1227
- ): void;
1228
- writev?(
1229
- this: Transform,
1230
- chunks: Array<{
1231
- chunk: any;
1232
- encoding: BufferEncoding;
1233
- }>,
1234
- callback: (error?: Error | null) => void,
1235
- ): void;
1236
- final?(this: Transform, callback: (error?: Error | null) => void): void;
1237
- destroy?(this: Transform, error: Error | null, callback: (error?: Error | null) => void): void;
1238
- transform?(this: Transform, chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
1239
- flush?(this: Transform, callback: TransformCallback): void;
1178
+ interface TransformOptions<T extends Transform = Transform> extends DuplexOptions<T> {
1179
+ transform?(this: T, chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
1180
+ flush?(this: T, callback: TransformCallback): void;
1240
1181
  }
1241
1182
  /**
1242
1183
  * Transform streams are `Duplex` streams where the output is in some way
@@ -1724,11 +1665,8 @@ declare module "stream" {
1724
1665
  * @since v17.4.0
1725
1666
  */
1726
1667
  function isReadable(stream: Readable | NodeJS.ReadableStream): boolean;
1727
-
1728
- const promises: typeof streamPromises;
1729
- const consumers: typeof streamConsumers;
1730
1668
  }
1731
- export = internal;
1669
+ export = Stream;
1732
1670
  }
1733
1671
  declare module "node:stream" {
1734
1672
  import stream = require("stream");
@@ -24,7 +24,7 @@ declare module "buffer" {
24
24
  * @param array The octets to store.
25
25
  * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
26
26
  */
27
- new(array: Uint8Array): Buffer;
27
+ new(array: ArrayLike<number>): Buffer;
28
28
  /**
29
29
  * Produces a Buffer backed by the same allocated memory as
30
30
  * the given {ArrayBuffer}/{SharedArrayBuffer}.
@@ -33,20 +33,6 @@ declare module "buffer" {
33
33
  * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead.
34
34
  */
35
35
  new(arrayBuffer: ArrayBuffer | SharedArrayBuffer): Buffer;
36
- /**
37
- * Allocates a new buffer containing the given {array} of octets.
38
- *
39
- * @param array The octets to store.
40
- * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
41
- */
42
- new(array: readonly any[]): Buffer;
43
- /**
44
- * Copies the passed {buffer} data onto a new {Buffer} instance.
45
- *
46
- * @param buffer The buffer to copy.
47
- * @deprecated since v10.0.0 - Use `Buffer.from(buffer)` instead.
48
- */
49
- new(buffer: Buffer): Buffer;
50
36
  /**
51
37
  * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`.
52
38
  * Array entries outside that range will be truncated to fit into it.
@@ -57,16 +43,85 @@ declare module "buffer" {
57
43
  * // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
58
44
  * const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
59
45
  * ```
60
- *
61
- * If `array` is an `Array`\-like object (that is, one with a `length` property of
46
+ * If `array` is an `Array`-like object (that is, one with a `length` property of
62
47
  * type `number`), it is treated as if it is an array, unless it is a `Buffer` or
63
- * a `Uint8Array`. This means all other `TypedArray` variants get treated as an`Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use `Buffer.copyBytesFrom()`.
48
+ * a `Uint8Array`. This means all other `TypedArray` variants get treated as an
49
+ * `Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use
50
+ * `Buffer.copyBytesFrom()`.
64
51
  *
65
52
  * A `TypeError` will be thrown if `array` is not an `Array` or another type
66
53
  * appropriate for `Buffer.from()` variants.
67
54
  *
68
- * `Buffer.from(array)` and `Buffer.from(string)` may also use the internal`Buffer` pool like `Buffer.allocUnsafe()` does.
55
+ * `Buffer.from(array)` and `Buffer.from(string)` may also use the internal
56
+ * `Buffer` pool like `Buffer.allocUnsafe()` does.
57
+ * @since v5.10.0
58
+ */
59
+ from(array: WithImplicitCoercion<ArrayLike<number>>): Buffer;
60
+ /**
61
+ * This creates a view of the `ArrayBuffer` without copying the underlying
62
+ * memory. For example, when passed a reference to the `.buffer` property of a
63
+ * `TypedArray` instance, the newly created `Buffer` will share the same
64
+ * allocated memory as the `TypedArray`'s underlying `ArrayBuffer`.
65
+ *
66
+ * ```js
67
+ * import { Buffer } from 'node:buffer';
68
+ *
69
+ * const arr = new Uint16Array(2);
70
+ *
71
+ * arr[0] = 5000;
72
+ * arr[1] = 4000;
73
+ *
74
+ * // Shares memory with `arr`.
75
+ * const buf = Buffer.from(arr.buffer);
76
+ *
77
+ * console.log(buf);
78
+ * // Prints: <Buffer 88 13 a0 0f>
79
+ *
80
+ * // Changing the original Uint16Array changes the Buffer also.
81
+ * arr[1] = 6000;
82
+ *
83
+ * console.log(buf);
84
+ * // Prints: <Buffer 88 13 70 17>
85
+ * ```
86
+ * The optional `byteOffset` and `length` arguments specify a memory range within
87
+ * the `arrayBuffer` that will be shared by the `Buffer`.
88
+ *
89
+ * ```js
90
+ * import { Buffer } from 'node:buffer';
91
+ *
92
+ * const ab = new ArrayBuffer(10);
93
+ * const buf = Buffer.from(ab, 0, 2);
94
+ *
95
+ * console.log(buf.length);
96
+ * // Prints: 2
97
+ * ```
98
+ *
99
+ * A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer` or a
100
+ * `SharedArrayBuffer` or another type appropriate for `Buffer.from()`
101
+ * variants.
102
+ *
103
+ * It is important to remember that a backing `ArrayBuffer` can cover a range
104
+ * of memory that extends beyond the bounds of a `TypedArray` view. A new
105
+ * `Buffer` created using the `buffer` property of a `TypedArray` may extend
106
+ * beyond the range of the `TypedArray`:
107
+ *
108
+ * ```js
109
+ * import { Buffer } from 'node:buffer';
110
+ *
111
+ * const arrA = Uint8Array.from([0x63, 0x64, 0x65, 0x66]); // 4 elements
112
+ * const arrB = new Uint8Array(arrA.buffer, 1, 2); // 2 elements
113
+ * console.log(arrA.buffer === arrB.buffer); // true
114
+ *
115
+ * const buf = Buffer.from(arrB.buffer);
116
+ * console.log(buf);
117
+ * // Prints: <Buffer 63 64 65 66>
118
+ * ```
69
119
  * @since v5.10.0
120
+ * @param arrayBuffer An `ArrayBuffer`, `SharedArrayBuffer`, for example the
121
+ * `.buffer` property of a `TypedArray`.
122
+ * @param byteOffset Index of first byte to expose. **Default:** `0`.
123
+ * @param length Number of bytes to expose. **Default:**
124
+ * `arrayBuffer.byteLength - byteOffset`.
70
125
  */
71
126
  from(
72
127
  arrayBuffer: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>,
@@ -74,24 +129,30 @@ declare module "buffer" {
74
129
  length?: number,
75
130
  ): Buffer;
76
131
  /**
77
- * Creates a new Buffer using the passed {data}
78
- * @param data data to create a new Buffer
79
- */
80
- from(data: Uint8Array | readonly number[]): Buffer;
81
- from(data: WithImplicitCoercion<Uint8Array | readonly number[] | string>): Buffer;
82
- /**
83
- * Creates a new Buffer containing the given JavaScript string {str}.
84
- * If provided, the {encoding} parameter identifies the character encoding.
85
- * If not provided, {encoding} defaults to 'utf8'.
132
+ * Creates a new `Buffer` containing `string`. The `encoding` parameter identifies
133
+ * the character encoding to be used when converting `string` into bytes.
134
+ *
135
+ * ```js
136
+ * import { Buffer } from 'node:buffer';
137
+ *
138
+ * const buf1 = Buffer.from('this is a tést');
139
+ * const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');
140
+ *
141
+ * console.log(buf1.toString());
142
+ * // Prints: this is a tést
143
+ * console.log(buf2.toString());
144
+ * // Prints: this is a tést
145
+ * console.log(buf1.toString('latin1'));
146
+ * // Prints: this is a tést
147
+ * ```
148
+ *
149
+ * A `TypeError` will be thrown if `string` is not a string or another type
150
+ * appropriate for `Buffer.from()` variants.
151
+ * @since v5.10.0
152
+ * @param string A string to encode.
153
+ * @param encoding The encoding of `string`. **Default:** `'utf8'`.
86
154
  */
87
- from(
88
- str:
89
- | WithImplicitCoercion<string>
90
- | {
91
- [Symbol.toPrimitive](hint: "string"): string;
92
- },
93
- encoding?: BufferEncoding,
94
- ): Buffer;
155
+ from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer;
95
156
  /**
96
157
  * Creates a new Buffer using the passed {data}
97
158
  * @param values to create a new Buffer
@@ -382,4 +443,10 @@ declare module "buffer" {
382
443
  subarray(start?: number, end?: number): Buffer;
383
444
  }
384
445
  }
446
+ /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */
447
+ var SlowBuffer: {
448
+ /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */
449
+ new(size: number): Buffer;
450
+ prototype: Buffer;
451
+ };
385
452
  }