Skip to content

Commit 5f4377a

Browse files
aduh95targos
authored andcommitted
doc: make MDN links to global classes more consistent in buffer.md
PR-URL: #56921 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent a473d3f commit 5f4377a

File tree

1 file changed

+35
-42
lines changed

1 file changed

+35
-42
lines changed

doc/api/buffer.md

+35-42
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
`Buffer` objects are used to represent a fixed-length sequence of bytes. Many
1010
Node.js APIs support `Buffer`s.
1111

12-
The `Buffer` class is a subclass of JavaScript's [`Uint8Array`][] class and
12+
The `Buffer` class is a subclass of JavaScript's {Uint8Array} class and
1313
extends it with methods that cover additional use cases. Node.js APIs accept
14-
plain [`Uint8Array`][]s wherever `Buffer`s are supported as well.
14+
plain {Uint8Array}s wherever `Buffer`s are supported as well.
1515

1616
While the `Buffer` class is available within the global scope, it is still
1717
recommended to explicitly reference it via an import or require statement.
@@ -242,10 +242,10 @@ changes:
242242
description: The `Buffer`s class now inherits from `Uint8Array`.
243243
-->
244244

245-
`Buffer` instances are also JavaScript [`Uint8Array`][] and [`TypedArray`][]
246-
instances. All [`TypedArray`][] methods are available on `Buffer`s. There are,
245+
`Buffer` instances are also JavaScript {Uint8Array} and {TypedArray}
246+
instances. All {TypedArray} methods are available on `Buffer`s. There are,
247247
however, subtle incompatibilities between the `Buffer` API and the
248-
[`TypedArray`][] API.
248+
{TypedArray} API.
249249

250250
In particular:
251251

@@ -258,9 +258,9 @@ In particular:
258258
* [`buf.toString()`][] is incompatible with its `TypedArray` equivalent.
259259
* A number of methods, e.g. [`buf.indexOf()`][], support additional arguments.
260260

261-
There are two ways to create new [`TypedArray`][] instances from a `Buffer`:
261+
There are two ways to create new {TypedArray} instances from a `Buffer`:
262262

263-
* Passing a `Buffer` to a [`TypedArray`][] constructor will copy the `Buffer`s
263+
* Passing a `Buffer` to a {TypedArray} constructor will copy the `Buffer`s
264264
contents, interpreted as an array of integers, and not as a byte sequence
265265
of the target type.
266266

@@ -286,8 +286,8 @@ console.log(uint32array);
286286
// Prints: Uint32Array(4) [ 1, 2, 3, 4 ]
287287
```
288288

289-
* Passing the `Buffer`s underlying [`ArrayBuffer`][] will create a
290-
[`TypedArray`][] that shares its memory with the `Buffer`.
289+
* Passing the `Buffer`s underlying {ArrayBuffer} will create a
290+
{TypedArray} that shares its memory with the `Buffer`.
291291

292292
```mjs
293293
import { Buffer } from 'node:buffer';
@@ -318,7 +318,7 @@ console.log(uint16array);
318318
```
319319

320320
It is possible to create a new `Buffer` that shares the same allocated
321-
memory as a [`TypedArray`][] instance by using the `TypedArray` object's
321+
memory as a {TypedArray} instance by using the `TypedArray` object's
322322
`.buffer` property in the same way. [`Buffer.from()`][`Buffer.from(arrayBuf)`]
323323
behaves like `new Uint8Array()` in this context.
324324

@@ -376,8 +376,8 @@ console.log(buf2);
376376
// Prints: <Buffer 88 13 70 17>
377377
```
378378

379-
When creating a `Buffer` using a [`TypedArray`][]'s `.buffer`, it is
380-
possible to use only a portion of the underlying [`ArrayBuffer`][] by passing in
379+
When creating a `Buffer` using a {TypedArray}'s `.buffer`, it is
380+
possible to use only a portion of the underlying {ArrayBuffer} by passing in
381381
`byteOffset` and `length` parameters.
382382

383383
```mjs
@@ -401,7 +401,7 @@ console.log(buf.length);
401401
```
402402

403403
The `Buffer.from()` and [`TypedArray.from()`][] have different signatures and
404-
implementations. Specifically, the [`TypedArray`][] variants accept a second
404+
implementations. Specifically, the {TypedArray} variants accept a second
405405
argument that is a mapping function that is invoked on every element of the
406406
typed array:
407407

@@ -968,9 +968,8 @@ console.log(`${str}: ${str.length} characters, ` +
968968
// Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
969969
```
970970

971-
When `string` is a `Buffer`/[`DataView`][]/[`TypedArray`][]/[`ArrayBuffer`][]/
972-
[`SharedArrayBuffer`][], the byte length as reported by `.byteLength`
973-
is returned.
971+
When `string` is a {Buffer|DataView|TypedArray|ArrayBuffer|SharedArrayBuffer},
972+
the byte length as reported by `.byteLength` is returned.
974973

975974
### Static method: `Buffer.compare(buf1, buf2)`
976975

@@ -1025,7 +1024,7 @@ changes:
10251024
description: The elements of `list` can now be `Uint8Array`s.
10261025
-->
10271026

1028-
* `list` {Buffer\[] | Uint8Array\[]} List of `Buffer` or [`Uint8Array`][]
1027+
* `list` {Buffer\[] | Uint8Array\[]} List of `Buffer` or {Uint8Array}
10291028
instances to concatenate.
10301029
* `totalLength` {integer} Total length of the `Buffer` instances in `list`
10311030
when concatenated.
@@ -1159,18 +1158,18 @@ appropriate for `Buffer.from()` variants.
11591158
added: v5.10.0
11601159
-->
11611160

1162-
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`][],
1163-
[`SharedArrayBuffer`][], for example the `.buffer` property of a
1164-
[`TypedArray`][].
1161+
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An {ArrayBuffer},
1162+
{SharedArrayBuffer}, for example the `.buffer` property of a
1163+
{TypedArray}.
11651164
* `byteOffset` {integer} Index of first byte to expose. **Default:** `0`.
11661165
* `length` {integer} Number of bytes to expose.
11671166
**Default:** `arrayBuffer.byteLength - byteOffset`.
11681167
* Returns: {Buffer}
11691168

1170-
This creates a view of the [`ArrayBuffer`][] without copying the underlying
1169+
This creates a view of the {ArrayBuffer} without copying the underlying
11711170
memory. For example, when passed a reference to the `.buffer` property of a
1172-
[`TypedArray`][] instance, the newly created `Buffer` will share the same
1173-
allocated memory as the [`TypedArray`][]'s underlying `ArrayBuffer`.
1171+
{TypedArray} instance, the newly created `Buffer` will share the same
1172+
allocated memory as the {TypedArray}'s underlying `ArrayBuffer`.
11741173

11751174
```mjs
11761175
import { Buffer } from 'node:buffer';
@@ -1237,8 +1236,8 @@ console.log(buf.length);
12371236
// Prints: 2
12381237
```
12391238

1240-
A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`][] or a
1241-
[`SharedArrayBuffer`][] or another type appropriate for `Buffer.from()`
1239+
A `TypeError` will be thrown if `arrayBuffer` is not an {ArrayBuffer} or a
1240+
{SharedArrayBuffer} or another type appropriate for `Buffer.from()`
12421241
variants.
12431242

12441243
It is important to remember that a backing `ArrayBuffer` can cover a range
@@ -1276,7 +1275,7 @@ console.log(buf);
12761275
added: v5.10.0
12771276
-->
12781277

1279-
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`][] from
1278+
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or {Uint8Array} from
12801279
which to copy data.
12811280
* Returns: {Buffer}
12821281

@@ -1636,7 +1635,7 @@ changes:
16361635
description: Additional parameters for specifying offsets are supported now.
16371636
-->
16381637

1639-
* `target` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`][] with which to
1638+
* `target` {Buffer|Uint8Array} A `Buffer` or {Uint8Array} with which to
16401639
compare `buf`.
16411640
* `targetStart` {integer} The offset within `target` at which to begin
16421641
comparison. **Default:** `0`.
@@ -1741,7 +1740,7 @@ console.log(buf1.compare(buf2, 5, 6, 5));
17411740
added: v0.1.90
17421741
-->
17431742

1744-
* `target` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`][] to copy into.
1743+
* `target` {Buffer|Uint8Array} A `Buffer` or {Uint8Array} to copy into.
17451744
* `targetStart` {integer} The offset within `target` at which to begin
17461745
writing. **Default:** `0`.
17471746
* `sourceStart` {integer} The offset within `buf` from which to begin copying.
@@ -1896,7 +1895,7 @@ changes:
18961895
description: The arguments can now be `Uint8Array`s.
18971896
-->
18981897

1899-
* `otherBuffer` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`][] with which to
1898+
* `otherBuffer` {Buffer|Uint8Array} A `Buffer` or {Uint8Array} with which to
19001899
compare `buf`.
19011900
* Returns: {boolean}
19021901

@@ -2141,7 +2140,7 @@ If `value` is:
21412140

21422141
* a string, `value` is interpreted according to the character encoding in
21432142
`encoding`.
2144-
* a `Buffer` or [`Uint8Array`][], `value` will be used in its entirety.
2143+
* a `Buffer` or {Uint8Array}, `value` will be used in its entirety.
21452144
To compare a partial `Buffer`, use [`buf.subarray`][].
21462145
* a number, `value` will be interpreted as an unsigned 8-bit integer
21472146
value between `0` and `255`.
@@ -5010,8 +5009,8 @@ changes:
50105009
> [`Buffer.from(arrayBuffer[, byteOffset[, length]])`][`Buffer.from(arrayBuf)`]
50115010
> instead.
50125011
5013-
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`][],
5014-
[`SharedArrayBuffer`][] or the `.buffer` property of a [`TypedArray`][].
5012+
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An {ArrayBuffer},
5013+
{SharedArrayBuffer} or the `.buffer` property of a {TypedArray}.
50155014
* `byteOffset` {integer} Index of first byte to expose. **Default:** `0`.
50165015
* `length` {integer} Number of bytes to expose.
50175016
**Default:** `arrayBuffer.byteLength - byteOffset`.
@@ -5038,7 +5037,7 @@ changes:
50385037

50395038
> Stability: 0 - Deprecated: Use [`Buffer.from(buffer)`][] instead.
50405039
5041-
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`][] from
5040+
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or {Uint8Array} from
50425041
which to copy data.
50435042

50445043
See [`Buffer.from(buffer)`][].
@@ -5114,7 +5113,7 @@ changes:
51145113

51155114
* Extends: {Blob}
51165115

5117-
A [`File`][] provides information about files.
5116+
A {File} provides information about files.
51185117

51195118
### `new buffer.File(sources, fileName[, options])`
51205119

@@ -5431,7 +5430,7 @@ differently based on what arguments are provided:
54315430
Buffer(num)` return a `Buffer` with initialized memory.
54325431
* Passing a string, array, or `Buffer` as the first argument copies the
54335432
passed object's data into the `Buffer`.
5434-
* Passing an [`ArrayBuffer`][] or a [`SharedArrayBuffer`][] returns a `Buffer`
5433+
* Passing an {ArrayBuffer} or a {SharedArrayBuffer} returns a `Buffer`
54355434
that shares allocated memory with the given array buffer.
54365435

54375436
Because the behavior of `new Buffer()` is different depending on the type of the
@@ -5465,7 +5464,7 @@ to one of these new APIs._
54655464
provided octets.
54665465
* [`Buffer.from(arrayBuffer[, byteOffset[, length]])`][`Buffer.from(arrayBuf)`]
54675466
returns a new `Buffer` that _shares the same allocated memory_ as the given
5468-
[`ArrayBuffer`][].
5467+
{ArrayBuffer}.
54695468
* [`Buffer.from(buffer)`][] returns a new `Buffer` that _contains a copy_ of the
54705469
contents of the given `Buffer`.
54715470
* [`Buffer.from(string[, encoding])`][`Buffer.from(string)`] returns a new
@@ -5527,7 +5526,6 @@ introducing security vulnerabilities into an application.
55275526
[UTF-16]: https://en.wikipedia.org/wiki/UTF-16
55285527
[UTF-8]: https://en.wikipedia.org/wiki/UTF-8
55295528
[WHATWG Encoding Standard]: https://encoding.spec.whatwg.org/
5530-
[`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
55315529
[`Blob`]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
55325530
[`Buffer.alloc()`]: #static-method-bufferallocsize-fill-encoding
55335531
[`Buffer.allocUnsafe()`]: #static-method-bufferallocunsafesize
@@ -5539,21 +5537,16 @@ introducing security vulnerabilities into an application.
55395537
[`Buffer.from(buffer)`]: #static-method-bufferfrombuffer
55405538
[`Buffer.from(string)`]: #static-method-bufferfromstring-encoding
55415539
[`Buffer.poolSize`]: #class-property-bufferpoolsize
5542-
[`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
55435540
[`ERR_INVALID_BUFFER_SIZE`]: errors.md#err_invalid_buffer_size
55445541
[`ERR_OUT_OF_RANGE`]: errors.md#err_out_of_range
5545-
[`File`]: https://developer.mozilla.org/en-US/docs/Web/API/File
55465542
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
5547-
[`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
55485543
[`String.prototype.indexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
55495544
[`String.prototype.lastIndexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
55505545
[`String.prototype.length`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
55515546
[`TypedArray.from()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from
55525547
[`TypedArray.prototype.set()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set
55535548
[`TypedArray.prototype.slice()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice
55545549
[`TypedArray.prototype.subarray()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
5555-
[`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
5556-
[`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
55575550
[`buf.buffer`]: #bufbuffer
55585551
[`buf.compare()`]: #bufcomparetarget-targetstart-targetend-sourcestart-sourceend
55595552
[`buf.entries()`]: #bufentries

0 commit comments

Comments
 (0)