API reference › @evolu/common › Bytes › bytesToUtf8

function bytesToUtf8(bytes: Uint8Array): string;

Defined in: packages/common/src/Bytes.ts:141

Decodes UTF-8 bytes into a string.

Invalid UTF-8 decodes as U+FFFD instead of throwing, and a leading byte order mark is dropped.

Example

import { assertEqual, bytesToUtf8 } from "@evolu/common";

assertEqual(bytesToUtf8(new Uint8Array([0xc3, 0xa9])), "é");
assertEqual(bytesToUtf8(new Uint8Array([0xff])), "\uFFFD");
assertEqual(bytesToUtf8(new Uint8Array([0xef, 0xbb, 0xbf, 0x61])), "a");