Skip to content

Function: encodeText() ​

ts
function encodeText(data): Uint8Array<ArrayBuffer>;

Defined in: encodeText.ts:13

Converts a string to UTF-8 bytes in a Uint8Array. The function calls TextEncoder.encode. The environment must have TextEncoder.

Parameters ​

data ​

string

The string to encode.

Returns ​

Uint8Array<ArrayBuffer>

The Uint8Array representation of the string.

Example ​

ts
const str = 'hello world'
const encoded = new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])

deepEqual(encodeText(str), encoded)

A Streaming Video Technology Alliance project.