Skip to content

Commit c3d573d

Browse files
vsemozhetbytBethGriggs
authored andcommitted
doc: fix error notes in Buffer.from() variants
Make notes about `TypeError` conditions in `Buffer.from()` variants more accurate. PR-URL: #27030 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
1 parent e18a0e8 commit c3d573d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

doc/api/buffer.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,8 @@ Allocates a new `Buffer` using an `array` of octets.
787787
const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
788788
```
789789

790-
A `TypeError` will be thrown if `array` is not an `Array`.
790+
A `TypeError` will be thrown if `array` is not an `Array` or other type
791+
appropriate for `Buffer.from()` variants.
791792

792793
### Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
793794
<!-- YAML
@@ -836,7 +837,7 @@ console.log(buf.length);
836837
```
837838

838839
A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`] or a
839-
[`SharedArrayBuffer`].
840+
[`SharedArrayBuffer`] or other type appropriate for `Buffer.from()` variants.
840841

841842
### Class Method: Buffer.from(buffer)
842843
<!-- YAML
@@ -860,7 +861,8 @@ console.log(buf2.toString());
860861
// Prints: buffer
861862
```
862863

863-
A `TypeError` will be thrown if `buffer` is not a `Buffer`.
864+
A `TypeError` will be thrown if `buffer` is not a `Buffer` or other type
865+
appropriate for `Buffer.from()` variants.
864866

865867
### Class Method: Buffer.from(object[, offsetOrEncoding[, length]])
866868
<!-- YAML
@@ -896,6 +898,9 @@ const buf = Buffer.from(new Foo(), 'utf8');
896898
// Prints: <Buffer 74 68 69 73 20 69 73 20 61 20 74 65 73 74>
897899
```
898900

901+
A `TypeError` will be thrown if `object` has not mentioned methods or is not of
902+
other type appropriate for `Buffer.from()` variants.
903+
899904
### Class Method: Buffer.from(string[, encoding])
900905
<!-- YAML
901906
added: v5.10.0
@@ -919,7 +924,8 @@ console.log(buf1.toString('ascii'));
919924
// Prints: this is a tC)st
920925
```
921926

922-
A `TypeError` will be thrown if `string` is not a string.
927+
A `TypeError` will be thrown if `string` is not a string or other type
928+
appropriate for `Buffer.from()` variants.
923929

924930
### Class Method: Buffer.isBuffer(obj)
925931
<!-- YAML

0 commit comments

Comments
 (0)