Libraries
    Preparing search index...
    • Creates a string schema constrained to the given literal values.

      Convenience factory equivalent to string().oneOf(...values). Mirrors Zod's z.enum(['admin', 'user', 'guest']) API.

      Rest-params form (no custom error message):

      const Role = enumOf('admin', 'user', 'guest');
      

      Array form (with optional custom error message):

      const Role = enumOf(['admin', 'user', 'guest'], 'Invalid role');
      const Role2 = enumOf(['admin', 'user'], (val) => `"${val}" is not a valid role`);

      Type Parameters

      • const T extends string

      Parameters

      • ...values: [T, ...T[]]

        the allowed string literals (at least one required)

      Returns ExtendedString<T>

      a typed StringSchemaBuilder that only accepts the given values

      import { enumOf, InferType } from '@cleverbrush/schema';

      const Role = enumOf('admin', 'user', 'guest');
      type Role = InferType<typeof Role>; // 'admin' | 'user' | 'guest'

      Role.validate('admin'); // valid
      Role.validate('other'); // invalid
    • Creates a string schema constrained to the given literal values.

      Convenience factory equivalent to string().oneOf(...values). Mirrors Zod's z.enum(['admin', 'user', 'guest']) API.

      Rest-params form (no custom error message):

      const Role = enumOf('admin', 'user', 'guest');
      

      Array form (with optional custom error message):

      const Role = enumOf(['admin', 'user', 'guest'], 'Invalid role');
      const Role2 = enumOf(['admin', 'user'], (val) => `"${val}" is not a valid role`);

      Type Parameters

      • const T extends string

      Parameters

      Returns ExtendedString<T>

      a typed StringSchemaBuilder that only accepts the given values

      import { enumOf, InferType } from '@cleverbrush/schema';

      const Role = enumOf('admin', 'user', 'guest');
      type Role = InferType<typeof Role>; // 'admin' | 'user' | 'guest'

      Role.validate('admin'); // valid
      Role.validate('other'); // invalid