TextEncoder

Classin globals@fastly/js-compute 3.46.0View source

An implementation of the WHATWG Encoding Standard TextEncoder API. All instances of TextEncoder only support UTF-8 encoding.

TextEncoder takes a stream of code points as input and emits a stream of UTF-8 bytes.

See also

const encoder = new TextEncoder();
const uint8array = encoder.encode('a string to encode');

Constructor

new TextEncoder()

Returns a newly constructed TextEncoder that will generate a byte stream with UTF-8 encoding.

Properties

encoding

'utf-8'read-onlyView source

The TextEncoder.encoding read-only property returns a string containing the name of the encoding algorithm used by the specific encoder. It is always set to the value "utf-8".

Methods

encode(input?: string): Uint8Array<ArrayBuffer>

UTF-8 encodes the input string and returns a Uint8Array containing the encoded bytes.

Parameters

input: stringoptional

Returns