Converts a string to a Uint8Array. Similar to TextEncoder.encode but with a fallback for environments that don't support TextEncoder.
TextEncoder.encode
TextEncoder
The string to encode.
The Uint8Array representation of the string.
const str = 'hello world'const encoded = new Uint8Array([ 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])deepEqual(encodeText(str), encoded) Copy
const str = 'hello world'const encoded = new Uint8Array([ 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])deepEqual(encodeText(str), encoded)
Converts a string to a Uint8Array. Similar to
TextEncoder.encodebut with a fallback for environments that don't supportTextEncoder.