TextDecoder class

WHATWG Encoding StandardTextDecoder API の実装。

const decoder = new TextDecoder();
const u8arr = new Uint8Array([72, 101, 108, 108, 111]);
console.log(decoder.decode(u8arr)); // Hello

コンストラクター

TextDecoder(string, { fatal?: boolean, ignoreBOM?: boolean })

プロパティ

encoding

TextDecoder インスタンスでサポートされるエンコード。

fatal

デコード エラーによって TypeError がスローされた場合、値は true されます。

ignoreBOM

デコード結果にバイトオーダーマークが含まれる場合、値は true されます。

メソッド

decode(null | ArrayBuffer | ArrayBufferView, { stream?: boolean })

input をデコードし、文字列を返します。 options.streamtrueされている場合、input の最後に発生する不完全なバイト シーケンスは内部的にバッファリングされ、次の textDecoder.decode()呼び出しの後に出力されます。

textDecoder.fataltrue場合、発生したエラーをデコードすると、TypeError がスローされます。

コンストラクターの詳細

TextDecoder(string, { fatal?: boolean, ignoreBOM?: boolean })

new TextDecoder(encoding?: string, options?: { fatal?: boolean, ignoreBOM?: boolean })

パラメーター

encoding

string

options

{ fatal?: boolean, ignoreBOM?: boolean }

プロパティの詳細

encoding

TextDecoder インスタンスでサポートされるエンコード。

encoding: string

プロパティ値

string

fatal

デコード エラーによって TypeError がスローされた場合、値は true されます。

fatal: boolean

プロパティ値

boolean

ignoreBOM

デコード結果にバイトオーダーマークが含まれる場合、値は true されます。

ignoreBOM: boolean

プロパティ値

boolean

メソッドの詳細

decode(null | ArrayBuffer | ArrayBufferView, { stream?: boolean })

input をデコードし、文字列を返します。 options.streamtrueされている場合、input の最後に発生する不完全なバイト シーケンスは内部的にバッファリングされ、次の textDecoder.decode()呼び出しの後に出力されます。

textDecoder.fataltrue場合、発生したエラーをデコードすると、TypeError がスローされます。

function decode(input?: null | ArrayBuffer | ArrayBufferView, options?: { stream?: boolean }): string

パラメーター

input

null | ArrayBuffer | ArrayBufferView

エンコードされたデータを含む ArrayBufferDataView、または TypedArray インスタンス。

options

{ stream?: boolean }

戻り値

string