Encodes string data to Uint8Array (UTF-8 encoding).
Uint8Array
Uses native TextEncoder if available, otherwise pure JS fallback.
TextEncoder
The string data to encode.
Encoded Uint8Array.
If the input is not a string.
1.0.0
const encoded = encodeUtf8('你好');console.log(encoded); // Uint8Array [228, 189, 160, 229, 165, 189] Copy
const encoded = encodeUtf8('你好');console.log(encoded); // Uint8Array [228, 189, 160, 229, 165, 189]
Encodes string data to
Uint8Array(UTF-8 encoding).Uses native
TextEncoderif available, otherwise pure JS fallback.