API reference › @evolu/common › Type › normalized

function normalized<Form extends UnicodeNormalizationForm>(
  form: Form & ValidateLiteral<Form>,
): BrandFactory<`Normalized${Form}`, string, NormalizedError<Form>>;

Defined in: packages/common/src/Type.ts:7727

String Brand for text already in a Unicode normalization form.

Unicode can encode the same text in more than one way: é is either one precomposed code point or e followed by a combining accent. Both look the same but are different strings, so equality checks, lookups, and unique constraints treat them as different values. Validation leaves the text unchanged; use normalize to convert text before validating it.

Prefer NFC for text. NFKC also replaces compatibility characters, such as the fi ligature with fi, so prefer it for identifiers compared for equality. The form must be one concrete string literal so different forms have distinct brands. A normalized string is not necessarily wellFormed, because normalization leaves lone surrogates unchanged.

Unicode's stability policy keeps the result for assigned characters the same across engine versions, but text with characters that an older engine does not know yet can be judged differently there.

Example

import { assertErr, assertOk, normalized, String } from "@evolu/common";

const Text = normalized("NFC")(String);

assertOk(Text.fromUnknown("caf\u00E9"), "caf\u00E9");
assertErr(Text.fromUnknown("cafe\u0301"));