@@ -79,17 +79,21 @@ console.log(Buffer.from('fhqwhgads', 'utf16le'));
79
79
// Prints: <Buffer 66 00 68 00 71 00 77 00 68 00 67 00 61 00 64 00 73 00>
80
80
```
81
81
82
+ Node.js buffers accept all case variations of encoding strings that they
83
+ receive. For example, UTF-8 can be specified as ` 'utf8' ` , ` 'UTF8' ` or ` 'uTf8' ` .
84
+
82
85
The character encodings currently supported by Node.js are the following:
83
86
84
- * ` 'utf8' ` : Multi-byte encoded Unicode characters. Many web pages and other
85
- document formats use [ UTF-8] [ ] . This is the default character encoding.
86
- When decoding a ` Buffer ` into a string that does not exclusively contain
87
- valid UTF-8 data, the Unicode replacement character ` U+FFFD ` � will be used
88
- to represent those errors.
87
+ * ` 'utf8' ` (alias: ` 'utf-8' ` ): Multi-byte encoded Unicode characters. Many web
88
+ pages and other document formats use [ UTF-8] [ ] . This is the default character
89
+ encoding. When decoding a ` Buffer ` into a string that does not exclusively
90
+ contain valid UTF-8 data, the Unicode replacement character ` U+FFFD ` � will be
91
+ used to represent those errors.
89
92
90
- * ` 'utf16le' ` : Multi-byte encoded Unicode characters. Unlike ` 'utf8' ` , each
91
- character in the string will be encoded using either 2 or 4 bytes.
92
- Node.js only supports the [ little-endian] [ endianness ] variant of [ UTF-16] [ ] .
93
+ * ` 'utf16le' ` (alias: ` 'utf-16le' ` ): Multi-byte encoded Unicode characters.
94
+ Unlike ` 'utf8' ` , each character in the string will be encoded using either 2
95
+ or 4 bytes. Node.js only supports the [ little-endian] [ endianness ] variant of
96
+ [ UTF-16] [ ] .
93
97
94
98
* ` 'latin1' ` : Latin-1 stands for [ ISO-8859-1] [ ] . This character encoding only
95
99
supports the Unicode characters from ` U+0000 ` to ` U+00FF ` . Each character is
@@ -132,11 +136,11 @@ The following legacy character encodings are also supported:
132
136
* ` 'binary' ` : Alias for ` 'latin1' ` . See [ binary strings] [ ] for more background
133
137
on this topic. The name of this encoding can be very misleading, as all of the
134
138
encodings listed here convert between strings and binary data. For converting
135
- between strings and ` Buffer ` s, typically ` 'utf-8 ' ` is the right choice.
139
+ between strings and ` Buffer ` s, typically ` 'utf8 ' ` is the right choice.
136
140
137
- * ` 'ucs2' ` : Alias of ` 'utf16le' ` . UCS-2 used to refer to a variant of UTF-16
138
- that did not support characters that had code points larger than U+FFFF.
139
- In Node.js, these code points are always supported.
141
+ * ` 'ucs2' ` , ` 'ucs-2' ` : Aliases of ` 'utf16le' ` . UCS-2 used to refer to a variant
142
+ of UTF-16 that did not support characters that had code points larger than
143
+ U+FFFF. In Node.js, these code points are always supported.
140
144
141
145
``` js
142
146
Buffer .from (' 1ag' , ' hex' );
@@ -900,7 +904,7 @@ Returns `true` if `encoding` is the name of a supported character encoding,
900
904
or ` false ` otherwise.
901
905
902
906
``` js
903
- console .log (Buffer .isEncoding (' utf-8 ' ));
907
+ console .log (Buffer .isEncoding (' utf8 ' ));
904
908
// Prints: true
905
909
906
910
console .log (Buffer .isEncoding (' hex' ));
0 commit comments