API reference / @evolu/common / Type / UrlSafeString

Variable: UrlSafeString

const UrlSafeString: BrandType<
  Type<"String", string, string, StringError, string, StringError>,
  "UrlSafeString",
  RegexError<"UrlSafeString">,
  StringError
>;

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

URL-safe string.

A UrlSafeString uses a limited alphabet that is safe for URLs:

  • Uppercase letters (A-Z)
  • Lowercase letters (a-z)
  • Digits (0-9)
  • Dash (-)
  • Underscore (_)

This is the same character set used by Base64Url encoding, but this type does not validate that the string is actually Base64Url-encoded data.

Example

const result = UrlSafeString.from("abc123_-");
if (result.ok) {
  console.log("Valid URL-safe string:", result.value);
} else {
  console.error("Invalid URL-safe string:", result.error);
}

Was this page helpful?