API reference › @evolu/common › Type › SimplePassword
const SimplePassword: createType<
"SimplePassword",
typeof String,
TrimmedString &
Brand<"MaxLength64"> &
Brand<"MinLength8"> &
Brand<"SimplePassword">,
SimplePasswordError
>(
"SimplePassword",
String,
(value) =>
value !== value.trim()
? err({ type: "SimplePassword", reason: "Untrimmed" })
: value.length > 64
? err({ type: "SimplePassword", reason: "TooLong" })
: value.length < 8
? err({ type: "SimplePassword", reason: "TooShort" })
: ok(
value as TrimmedString &
Brand<"MaxLength64"> &
Brand<"MinLength8"> &
Brand<"SimplePassword">,
),
formatSimplePasswordError,
);
Defined in: packages/common/src/Type.ts:9873
A trimmed password containing between 8 and 64 UTF-16 code units.
A password is a secret, so every rejected string fails with a SimplePasswordError that omits it. A non-string fails with the String error, which keeps the input, so pass only strings.
Only this Type's own error omits the input. Types built around it keep the
input in their own errors: a refinement such as regex applied to it,
or the Null member of nullOr when all errors are collected, as with
{ errors: "all" } and always with Standard Schema validation.
Example
import { assertErr, assertOk, SimplePassword } from "@evolu/common";
assertOk(SimplePassword.fromUnknown("correct horse"), "correct horse");
assertErr(SimplePassword.fromUnknown("short"), {
type: "SimplePassword",
reason: "TooShort",
});