API reference › @evolu/common › Bytes › utf8ToBytes
function utf8ToBytes(text: string): Uint8Array<ArrayBuffer>;
Defined in: packages/common/src/Bytes.ts:120
Encodes a string as UTF-8 bytes.
A lone surrogate, which UTF-8 cannot represent, becomes U+FFFD.
Example
import { assertEqual, utf8ToBytes } from "@evolu/common";
assertEqual(utf8ToBytes("é"), new Uint8Array([0xc3, 0xa9]));
assertEqual(utf8ToBytes("\uD800"), new Uint8Array([0xef, 0xbf, 0xbd]));