// Generated by bynkc — do not edit by hand.
// commons demo

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "./runtime.js";

export type Username = string & { readonly __brand: "Username" };

export const Username = {
  of(value: string): Result<Username, ValidationError> {
    if (!(value.length >= 3)) {
      return Err({ field: "Username", message: "length must be at least 3", value });
    }
    if (!(value.length <= 20)) {
      return Err({ field: "Username", message: "length must be at most 20", value });
    }
    if (!new RegExp("^" + "[a-z0-9_]+" + "$").test(value)) {
      return Err({ field: "Username", message: "must match /[a-z0-9_]+/", value });
    }
    return Ok(value as Username);
  },
  unsafe(value: string): Username {
    return value as Username;
  },
};

