TextDecoder: TextDecoder() コンストラクター
TextDecoder()
コンストラクターは、引数で指定されたエンコーディング用に新しく作成された TextDecoder
オブジェクトを返します。
構文
new TextDecoder()
new TextDecoder(label)
new TextDecoder(label, options)
引数
label
省略可-
文字列で、既定値は
"utf-8"
です。 これは何れかの有効なラベルです。 options
省略可-
次のプロパティを持つオブジェクトです。
fatal
-
論理値で、無効なデータをデコードした場合に
TextDecoder.decode()
メソッドがTypeError
を発生させるかどうかを示します。 既定値ではfalse
であり、これはデコードする際に不正なデータを置換文字で置き換えることを意味します。 ignoreBOM
-
論理値で、バイトオーダーマークを無視するか否かを示します。 既定値は
false
です。
例外
RangeError
-
label
の値が未知の場合、または'replacement'
デコードアルゴリズムにつながる値のいずれか("iso-2022-cn"
または"iso-2022-cn-ext"
)になっている場合に発生します。
例
const textDecoder1 = new TextDecoder("iso-8859-2");
const textDecoder2 = new TextDecoder();
const textDecoder3 = new TextDecoder("csiso2022kr", { fatal: true }); // TypeError 例外を発生できるようにします。
const textDecoder4 = new TextDecoder("iso-2022-cn"); // RangeError 例外が発生します。
仕様書
Specification |
---|
Encoding Standard # ref-for-dom-textdecoder① |
ブラウザーの互換性
BCD tables only load in the browser
関連情報
- 所属先の
TextDecoder
インターフェイス。