@@ -544,7 +544,7 @@ added: v8.0.0
544
544
A Symbol that can be used to declare custom promisified variants of functions,
545
545
see [ Custom promisified functions] [ ] .
546
546
547
- ### Class: util.TextDecoder
547
+ ## Class: util.TextDecoder
548
548
<!-- YAML
549
549
added: v8.3.0
550
550
-->
@@ -563,23 +563,33 @@ while (buffer = getNextChunkSomehow()) {
563
563
string += decoder .decode (); // end-of-stream
564
564
```
565
565
566
- #### WHATWG Supported Encodings
566
+ ### WHATWG Supported Encodings
567
567
568
568
Per the [ WHATWG Encoding Standard] [ ] , the encodings supported by the
569
569
` TextDecoder ` API are outlined in the tables below. For each encoding,
570
- one or more aliases may be used. Support for some encodings is enabled
571
- only when Node.js is using the full ICU data (see [ Internationalization] [ ] ).
572
- ` util.TextDecoder ` is ` undefined ` when ICU is not enabled during build.
570
+ one or more aliases may be used.
573
571
574
- ##### Encodings Supported By Default
572
+ Different Node.js build configurations support different sets of encodings.
573
+ While a very basic set of encodings is supported even on Node.js builds without
574
+ ICU enabled, support for some encodings is provided only when Node.js is built
575
+ with ICU and using the full ICU data (see [ Internationalization] [ ] ).
576
+
577
+ #### Encodings Supported Without ICU
575
578
576
579
| Encoding | Aliases |
577
580
| ----------- | --------------------------------- |
578
- | ` 'utf8' ` | ` 'unicode-1-1-utf-8' ` , ` 'utf-8' ` |
579
- | ` 'utf-16be' ` | |
581
+ | ` 'utf-8' ` | ` 'unicode-1-1-utf-8' ` , ` 'utf8' ` |
580
582
| ` 'utf-16le' ` | ` 'utf-16' ` |
581
583
582
- ##### Encodings Requiring Full-ICU
584
+ #### Encodings Supported by Default (With ICU)
585
+
586
+ | Encoding | Aliases |
587
+ | ----------- | --------------------------------- |
588
+ | ` 'utf-8' ` | ` 'unicode-1-1-utf-8' ` , ` 'utf8' ` |
589
+ | ` 'utf-16le' ` | ` 'utf-16' ` |
590
+ | ` 'utf-16be' ` | |
591
+
592
+ #### Encodings Requiring Full ICU Data
583
593
584
594
| Encoding | Aliases |
585
595
| ----------------- | -------------------------------- |
@@ -621,13 +631,14 @@ only when Node.js is using the full ICU data (see [Internationalization][]).
621
631
* Note* : The ` 'iso-8859-16' ` encoding listed in the [ WHATWG Encoding Standard] [ ]
622
632
is not supported.
623
633
624
- #### new TextDecoder([ encoding[ , options]] )
634
+ ### new TextDecoder([ encoding[ , options]] )
625
635
626
636
* ` encoding ` {string} Identifies the ` encoding ` that this ` TextDecoder ` instance
627
637
supports. Defaults to ` 'utf-8' ` .
628
638
* ` options ` {Object}
629
639
* ` fatal ` {boolean} ` true ` if decoding failures are fatal. Defaults to
630
- ` false ` .
640
+ ` false ` . This option is only supported when ICU is enabled (see
641
+ [ Internationalization] [ ] ).
631
642
* ` ignoreBOM ` {boolean} When ` true ` , the ` TextDecoder ` will include the byte
632
643
order mark in the decoded result. When ` false ` , the byte order mark will
633
644
be removed from the output. This option is only used when ` encoding ` is
@@ -636,7 +647,7 @@ is not supported.
636
647
Creates an new ` TextDecoder ` instance. The ` encoding ` may specify one of the
637
648
supported encodings or an alias.
638
649
639
- #### textDecoder.decode([ input[ , options]] )
650
+ ### textDecoder.decode([ input[ , options]] )
640
651
641
652
* ` input ` {ArrayBuffer|DataView|TypedArray} An ` ArrayBuffer ` , ` DataView ` or
642
653
Typed Array instance containing the encoded data.
@@ -652,49 +663,55 @@ internally and emitted after the next call to `textDecoder.decode()`.
652
663
If ` textDecoder.fatal ` is ` true ` , decoding errors that occur will result in a
653
664
` TypeError ` being thrown.
654
665
655
- #### textDecoder.encoding
666
+ ### textDecoder.encoding
656
667
657
- * Value: {string}
668
+ * {string}
658
669
659
670
The encoding supported by the ` TextDecoder ` instance.
660
671
661
- #### textDecoder.fatal
672
+ ### textDecoder.fatal
662
673
663
- * Value: {boolean}
674
+ * {boolean}
664
675
665
676
The value will be ` true ` if decoding errors result in a ` TypeError ` being
666
677
thrown.
667
678
668
- #### textDecoder.ignoreBOM
679
+ ### textDecoder.ignoreBOM
669
680
670
- * Value: {boolean}
681
+ * {boolean}
671
682
672
683
The value will be ` true ` if the decoding result will include the byte order
673
684
mark.
674
685
675
- ### Class: util.TextEncoder
686
+ ## Class: util.TextEncoder
676
687
<!-- YAML
677
688
added: v8.3.0
678
689
-->
679
690
680
691
> Stability: 1 - Experimental
681
692
682
693
An implementation of the [ WHATWG Encoding Standard] [ ] ` TextEncoder ` API. All
683
- instances of ` TextEncoder ` only support ` UTF-8 ` encoding.
694
+ instances of ` TextEncoder ` only support UTF-8 encoding.
684
695
685
696
``` js
686
697
const encoder = new TextEncoder ();
687
698
const uint8array = encoder .encode (' this is some data' );
688
699
```
689
700
690
- #### textEncoder.encode([ input] )
701
+ ### textEncoder.encode([ input] )
691
702
692
703
* ` input ` {string} The text to encode. Defaults to an empty string.
693
704
* Returns: {Uint8Array}
694
705
695
- UTF-8 Encodes the ` input ` string and returns a ` Uint8Array ` containing the
706
+ UTF-8 encodes the ` input ` string and returns a ` Uint8Array ` containing the
696
707
encoded bytes.
697
708
709
+ ### textDecoder.encoding
710
+
711
+ * {string}
712
+
713
+ The encoding supported by the ` TextEncoder ` instance. Always set to ` 'utf-8' ` .
714
+
698
715
## Deprecated APIs
699
716
700
717
The following APIs have been deprecated and should no longer be used. Existing
0 commit comments