API reference › @evolu/common › Type › startsWith
function startsWith<Prefix>(
prefix: Prefix & ValidateLiteral<Prefix>,
): BrandFactory<`StartsWith${Prefix}`, string, StartsWithError<Prefix>>;
Defined in: packages/common/src/Type.ts:6634
String Brand requiring an exact, case-sensitive prefix.
Validation preserves the complete string, including the prefix. An empty prefix accepts every string allowed by the parent Type. The prefix must be one concrete string literal so different prefixes have distinct brands.
Example
import {
assertEqual,
assertErr,
assertOk,
assertType,
maxLength,
startsWith,
String,
type Brand,
} from "@evolu/common";
const EnvName = startsWith("APP_")(maxLength(64)(String));
const name = EnvName.fromUnknown("APP_PORT");
assertOk(name, "APP_PORT");
assertType<
typeof name.value,
string & Brand<"MaxLength64"> & Brand<"StartsWithAPP_">
>();
assertEqual(EnvName.to(name.value), "APP_PORT");
assertErr(EnvName.fromUnknown("app_PORT"));
assertErr(EnvName.fromUnknown("APP_" + "X".repeat(61)));