### Install zcn Package Source: https://github.com/wesleydmscn/zcn/blob/main/README.md Instructions for installing the 'zcn' package using npm, pnpm, or yarn. This is the first step to integrate the library into your project. ```bash npm install zcn # or pnpm install zcn # or yarn install zcn ``` -------------------------------- ### Infer TypeScript Types from ZCN Schema (TypeScript) Source: https://github.com/wesleydmscn/zcn/wiki/Basic-Usage This snippet illustrates how to infer TypeScript types directly from a ZCN schema definition using ZTypes. It then shows the creation of a typed customer object, ensuring type safety. Requires the 'zcn' library. ```typescript import { z, type ZTypes } from "zcn"; const Customer = z.object({ name: z.string().nonempty(), cpf: z.cpf(), telephone: z.telephone(), }); type Customer = ZTypes.infer; const customer: Customer = { name: "Wesley Damasceno", cpf: "00000000000", telephone: "99999999999" }; ``` -------------------------------- ### Combined Validation Example for E-commerce Flow (TypeScript) Source: https://context7.com/wesleydmscn/zcn/llms.txt Demonstrates combining multiple ZCN validators for user registration, business registration, and application configuration in a TypeScript project. It includes validators for Brazilian document formats (CPF, CNPJ, CEP), telephone numbers, usernames, OTPs, ports, and environment variables. ```typescript import { z } from "zcn"; // Complete user registration schema const UserRegistrationSchema = z.object({ // Account credentials username: z.username({ error: "Username inválido" }), email: z.string().email({ message: "Email inválido" }), password: z.string().min(8, "Senha deve ter no mínimo 8 caracteres"), // Personal information fullName: z.string().min(3), cpf: z.cpf({ error: "CPF inválido" }), telephone: z.telephone({ error: "Telefone inválido" }), // Address address: z.object({ cep: z.cep({ error: "CEP inválido" }), street: z.string(), number: z.string(), complement: z.string().optional(), neighborhood: z.string(), city: z.string(), state: z.string().length(2), }), // Two-factor authentication phoneVerification: z.otp({ length: 6, error: "Código de verificação inválido" }), }); // Register new user const newUser = UserRegistrationSchema.parse({ username: "joao_silva", email: "joao.silva@example.com", password: "SecurePassword123!", fullName: "João da Silva", cpf: "935.411.347-80", telephone: "(11) 98765-4321", address: { cep: "01310-100", street: "Avenida Paulista", number: "1578", complement: "Apto 501", neighborhood: "Bela Vista", city: "São Paulo", state: "SP", }, phoneVerification: "123456", }); // Business registration schema const BusinessRegistrationSchema = z.object({ businessName: z.string().min(3), tradingName: z.string(), cnpj: z.cnpj({ error: "CNPJ inválido" }), contact: z.object({ email: z.string().email(), telephone: z.telephone({ error: "Telefone inválido" }), mobile: z.telephone({ error: "Celular inválido" }), }), address: z.object({ cep: z.cep({ error: "CEP inválido" }), street: z.string(), number: z.string(), city: z.string(), state: z.string().length(2), }), }); const business = BusinessRegistrationSchema.parse({ businessName: "Tech Solutions LTDA", tradingName: "TechSol", cnpj: "11.222.333/0001-81", contact: { email: "contato@techsol.com.br", telephone: "(11) 3456-7890", mobile: "(11) 98765-4321", }, address: { cep: "04571-010", street: "Avenida Brigadeiro Faria Lima", number: "3477", city: "São Paulo", state: "SP", }, }); // Application configuration with environment validation const AppConfigSchema = z.object({ app: z.object({ name: z.string(), env: z.nodeEnv({ error: "Ambiente inválido" }), port: z.coerce.port({ error: "Porta inválida" }), }), database: z.object({ host: z.string(), port: z.coerce.port(), name: z.string(), user: z.username(), }), redis: z.object({ host: z.string(), port: z.coerce.port(), }), security: z.object({ jwtSecret: z.string().min(32), otpLength: z.number().int().min(4).max(8).default(6), }), }); const config = AppConfigSchema.parse({ app: { name: "E-commerce API", env: "production", port: "3000", }, database: { host: "db.example.com", port: "5432", name: "ecommerce", user: "db_admin", }, redis: { host: "cache.example.com", port: "6379", }, security: { jwtSecret: "a".repeat(32), otpLength: 6, }, }); type UserRegistration = z.infer; type BusinessRegistration = z.infer; type AppConfig = z.infer; ``` -------------------------------- ### Define ZCN Object Schema with Custom Validations (TypeScript) Source: https://github.com/wesleydmscn/zcn/wiki/Basic-Usage This snippet shows how to define a ZCN schema for a customer object, including validations for non-empty strings and custom CPF and telephone formats. It utilizes the 'zcn' library for schema definition. ```typescript import { z } from "zcn"; const Customer = z.object({ name: z.string().nonempty(), cpf: z.cpf({ error: "Invalid CPF" }), telephone: z.telephone(), }); ``` -------------------------------- ### Validate Username Format using ZCN Source: https://context7.com/wesleydmscn/zcn/llms.txt Validates username strings with ZCN's z.username() schema. It enforces length (3-20 chars), allows alphanumeric characters with dots and underscores, and prevents consecutive special characters. Usernames must start with a letter and end with a letter or number. ```typescript import { z } from "zcn"; // Basic username validation const usernameSchema = z.username(); // User registration schema const SignUpSchema = z.object({ username: z.username({ error: "Invalid username format" }), email: z.string().email(), password: z.string().min(8), }); // Valid usernames usernameSchema.parse("john_doe"); // Valid usernameSchema.parse("user123"); // Valid usernameSchema.parse("alice.smith"); // Valid usernameSchema.parse("dev_user_01"); // Valid // Complete registration const user = SignUpSchema.parse({ username: "tech_developer", email: "developer@example.com", password: "SecurePass123!", }); // Profile update schema const ProfileSchema = z.object({ username: z.username({ error: "Username must be 3-20 characters" }), displayName: z.string().min(1).max(50), bio: z.string().max(160).optional(), }); const profile = ProfileSchema.parse({ username: "alice.dev", displayName: "Alice Developer", bio: "Full-stack developer passionate about TypeScript", }); // Invalid examples that throw errors try { usernameSchema.parse("ab"); // Too short (< 3 chars) } catch (error) { console.error("Username too short"); } try { usernameSchema.parse("user..name"); // Consecutive dots not allowed } catch (error) { console.error("Invalid format"); } try { usernameSchema.parse("_username"); // Must start with letter } catch (error) { console.error("Must start with letter"); } ``` -------------------------------- ### Validate Brazilian Telephone Numbers with Zod Extensions Source: https://context7.com/wesleydmscn/zcn/llms.txt Validates Brazilian telephone numbers, including mobile and landline formats. It correctly handles DDD area codes (11-99), validates mobile numbers starting with 9, and accepts both 10-digit landlines and 11-digit mobile numbers. This schema can be used standalone or within object schemas, supporting custom error messages and optional fields. ```typescript import { z } from "zcn"; // Basic telephone validation const phoneSchema = z.telephone(); // User contact schema const ContactSchema = z.object({ name: z.string(), mobile: z.telephone({ error: "Invalid phone number" }), landline: z.telephone().optional(), }); // Valid mobile formats phoneSchema.parse("(11) 98765-4321"); // Formatted mobile phoneSchema.parse("11987654321"); // Unformatted 11 digits phoneSchema.parse("(21) 99876-5432"); // Different area code // Valid landline formats phoneSchema.parse("(11) 3456-7890"); // Formatted landline phoneSchema.parse("1134567890"); // Unformatted 10 digits // Complete contact validation const contact = ContactSchema.parse({ name: "Maria Santos", mobile: "(11) 99876-5432", landline: "(11) 3456-7890", }); // API request example const UserRegistrationSchema = z.object({ username: z.string().min(3), telephone: z.telephone({ error: "Telefone inválido" }), cpf: z.cpf({ error: "CPF inválido" }), }); const registration = UserRegistrationSchema.parse({ username: "maria_santos", telephone: "11998765432", cpf: "71460238001", }); ``` -------------------------------- ### Username Validation Source: https://github.com/wesleydmscn/zcn/wiki/Schemas Validates a username with common web app constraints. Ensures format, allowed characters, and length. ```APIDOC ## GET /z/username ### Description Validates a username based on common web application constraints. It enforces a length of 3–20 characters, requires the username to start with a letter, and allows letters, numbers, underscores, and dots. It also prevents ending with `_` or `.`, and disallows consecutive underscores or dots. ### Method GET ### Endpoint /z/username ### Parameters #### Query Parameters - **value** (string) - Required - The username to validate. ### Request Example ``` GET /z/username?value=john_doe123 ``` ### Response #### Success Response (200) - **isValid** (boolean) - True if the username is valid, false otherwise. #### Response Example ```json { "isValid": true } ``` ``` -------------------------------- ### Node Environment Validation Source: https://github.com/wesleydmscn/zcn/wiki/Schemas Validates the `NODE_ENV` environment variable against a set of accepted values. ```APIDOC ## GET /z/nodeEnv ### Description Validates the `NODE_ENV` environment variable against a predefined list of accepted values: `"production"`, `"development"`, `"test"`, or `"staging"`. Any other string value will be rejected. ### Method GET ### Endpoint /z/nodeEnv ### Parameters #### Query Parameters - **value** (string) - Required - The NODE_ENV value to validate. ### Request Example ``` GET /z/nodeEnv?value=development ``` ### Response #### Success Response (200) - **isValid** (boolean) - True if the NODE_ENV value is valid, false otherwise. #### Response Example ```json { "isValid": true } ``` ``` -------------------------------- ### Node Environment Validator with ZCN Source: https://context7.com/wesleydmscn/zcn/llms.txt Validates Node.js environment strings against standard values ('production', 'development', 'test', 'staging'). Provides type-safe environment configuration and integrates with other ZCN validators like port and URL. ```typescript import { z } from "zcn"; // Basic environment validation const envSchema = z.nodeEnv(); // Environment configuration schema const ConfigSchema = z.object({ NODE_ENV: z.nodeEnv({ error: "Invalid environment" }), PORT: z.coerce.port(), DATABASE_URL: z.string().url(), API_KEY: z.string().min(32), }); // Valid environments envSchema.parse("production"); // Valid envSchema.parse("development"); // Valid envSchema.parse("test"); // Valid envSchema.parse("staging"); // Valid // Application configuration const config = ConfigSchema.parse({ NODE_ENV: "production", PORT: "3000", DATABASE_URL: "postgresql://localhost:5432/mydb", API_KEY: "a".repeat(32), }); // Environment-specific settings const AppSettingsSchema = z.object({ environment: z.nodeEnv(), debug: z.boolean(), logLevel: z.enum(["error", "warn", "info", "debug"]), }); const devSettings = AppSettingsSchema.parse({ environment: "development", debug: true, logLevel: "debug", }); const prodSettings = AppSettingsSchema.parse({ environment: "production", debug: false, logLevel: "error", }); // Server initialization with environment validation const ServerConfigSchema = z.object({ env: z.nodeEnv({ error: "Must be production, development, test, or staging" }), host: z.string().default("localhost"), port: z.coerce.port({ error: "Invalid port number" }), corsOrigins: z.array(z.string().url()), }); const serverConfig = ServerConfigSchema.parse({ env: "staging", host: "0.0.0.0", port: "8080", corsOrigins: ["https://staging.example.com"], }); // Invalid examples try { envSchema.parse("prod"); // Not exact match } catch (error) { console.error("Environment must be exactly: production, development, test, or staging"); } try { envSchema.parse("local"); // Not in enum } catch (error) { console.error("Invalid environment value"); } ``` -------------------------------- ### OTP Validation Source: https://github.com/wesleydmscn/zcn/wiki/Schemas Validates an OTP (one-time password) code. Supports configurable length and ensures only digits are accepted. ```APIDOC ## GET /z/otp ### Description Validates a One-Time Password (OTP) code. It accepts only digits and supports a configurable length (default is 6 digits). ### Method GET ### Endpoint /z/otp ### Parameters #### Query Parameters - **value** (string) - Required - The OTP code to validate. - **length** (number) - Optional - The expected length of the OTP code. ### Request Example ``` GET /z/otp?value=123456&length=6 ``` ### Response #### Success Response (200) - **isValid** (boolean) - True if the OTP is valid, false otherwise. #### Response Example ```json { "isValid": true } ``` ``` -------------------------------- ### Brazilian CPF Validation Source: https://github.com/wesleydmscn/zcn/wiki/Schemas Validates a Brazilian CPF (Cadastro de Pessoa Física). Checks format and both verification digits. Supports common formats and rejects invalid patterns. ```APIDOC ## GET /z/cpf ### Description Validates a Brazilian CPF (Cadastro de Pessoa Física), checking its format and both verification digits. ### Method GET ### Endpoint /z/cpf ### Parameters #### Query Parameters - **value** (string) - Required - The CPF value to validate. ### Request Example ``` GET /z/cpf?value=123.456.789-00 ``` ### Response #### Success Response (200) - **isValid** (boolean) - True if the CPF is valid, false otherwise. #### Response Example ```json { "isValid": true } ``` ``` -------------------------------- ### Brazilian CNPJ Validation Source: https://github.com/wesleydmscn/zcn/wiki/Schemas Validates a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica). Checks format and both verification digits. Supports common formats and rejects invalid patterns. ```APIDOC ## GET /z/cnpj ### Description Validates a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica), checking its format and both verification digits. Rejects repeated digits and validates check digits using CNPJ’s weighting algorithm. ### Method GET ### Endpoint /z/cnpj ### Parameters #### Query Parameters - **value** (string) - Required - The CNPJ value to validate. ### Request Example ``` GET /z/cnpj?value=11.222.333/0001-81 ``` ### Response #### Success Response (200) - **isValid** (boolean) - True if the CNPJ is valid, false otherwise. #### Response Example ```json { "isValid": true } ``` ``` -------------------------------- ### Validate Network Port Numbers (TypeScript) Source: https://context7.com/wesleydmscn/zcn/llms.txt Validates network port numbers provided as strings, ensuring they fall within the acceptable range of 0 to 65535. This is useful for validating configuration settings and environment variables. It uses the z.port() schema from the zcn library and handles potential errors for out-of-range or non-numeric inputs. ```typescript import { z } from "zcn"; // Basic port validation (string) const portSchema = z.port(); // Server configuration const ServerSchema = z.object({ host: z.string(), port: z.port({ error: "Invalid port number" }), ssl: z.boolean(), }); // Valid port strings portSchema.parse("3000"); // HTTP default alternative portSchema.parse("8080"); // Common dev port portSchema.parse("443"); // HTTPS portSchema.parse("5432"); // PostgreSQL portSchema.parse("27017"); // MongoDB portSchema.parse("0"); // Minimum valid port portSchema.parse("65535"); // Maximum valid port // Server configuration example const server = ServerSchema.parse({ host: "localhost", port: "3000", ssl: false, }); // Multi-service configuration const MicroservicesSchema = z.object({ api: z.object({ port: z.port(), workers: z.number().int().positive(), }), database: z.object({ port: z.port(), maxConnections: z.number(), }), redis: z.object({ port: z.port(), }), }); const services = MicroservicesSchema.parse({ api: { port: "3000", workers: 4 }, database: { port: "5432", maxConnections: 20 }, redis: { port: "6379" }, }); // Invalid examples try { portSchema.parse("65536"); // Above maximum } catch (error) { console.error("Port must be 0-65535"); } try { portSchema.parse("-1"); // Negative } catch (error) { console.error("Port must be non-negative"); } try { portSchema.parse("abc"); // Non-numeric } catch (error) { console.error("Port must be numeric"); } ``` -------------------------------- ### Port Validation Source: https://github.com/wesleydmscn/zcn/wiki/Schemas Validates a TCP/UDP port number. It accepts numeric strings within the valid port range (0-65535). ```APIDOC ## GET /z/port ### Description Validates a TCP/UDP port number. Accepts only numeric strings between 0 and 65535. For automatic type coercion from numeric inputs (e.g., `3000`), use `z.coerce.port()`. ### Method GET ### Endpoint /z/port ### Parameters #### Query Parameters - **value** (string) - Required - The port number string to validate. ### Request Example ``` GET /z/port?value=3000 ``` ### Response #### Success Response (200) - **isValid** (boolean) - True if the port number is valid, false otherwise. #### Response Example ```json { "isValid": true } ``` ``` -------------------------------- ### OTP Validator Schema with ZCN Source: https://context7.com/wesleydmscn/zcn/llms.txt Validates one-time password codes with configurable length. Defaults to 6 digits but accepts custom length parameter, validates only numeric characters, and commonly used for two-factor authentication. Handles custom error messages for invalid inputs. ```typescript import { z } from "zcn"; // Default 6-digit OTP const otpSchema = z.otp(); otpSchema.parse("123456"); // Valid otpSchema.parse("000000"); // Valid // Custom length OTP const fourDigitOTP = z.otp({ length: 4 }); fourDigitOTP.parse("1234"); // Valid const eightDigitOTP = z.otp({ length: 8, error: "Invalid 8-digit code" }); eightDigitOTP.parse("12345678"); // Valid // Two-factor authentication schema const TwoFactorSchema = z.object({ email: z.string().email(), otp: z.otp({ error: "Invalid verification code" }), }); const verification = TwoFactorSchema.parse({ email: "user@example.com", otp: "847392", }); // SMS verification with 4-digit code const SMSVerificationSchema = z.object({ phoneNumber: z.telephone(), code: z.otp({ length: 4, error: "Invalid SMS code" }), }); const smsVerification = SMSVerificationSchema.parse({ phoneNumber: "11987654321", code: "5678", }); // Banking confirmation with 8-digit token const BankingConfirmationSchema = z.object({ accountNumber: z.string(), transactionId: z.string().uuid(), confirmationToken: z.otp({ length: 8, error: "Invalid token" }), }); const banking = BankingConfirmationSchema.parse({ accountNumber: "12345-6", transactionId: "550e8400-e29b-41d4-a716-446655440000", confirmationToken: "98765432", }); // Invalid examples try { otpSchema.parse("12345"); // Too short } catch (error) { console.error("OTP must be 6 digits"); } try { otpSchema.parse("abc123"); // Non-numeric characters } catch (error) { console.error("OTP must contain only numbers"); } ``` -------------------------------- ### Validate Brazilian CPF with Zod Extensions Source: https://context7.com/wesleydmscn/zcn/llms.txt Validates Brazilian CPF (Cadastro de Pessoas Físicas) documents including check digit verification. It accepts both formatted (XXX.XXX.XXX-XX) and unformatted (11 digits) strings. This validator can be used standalone or within object schemas, and supports custom error messages. ```typescript import { z } from "zcn"; // Basic usage const cpfSchema = z.cpf(); cpfSchema.parse("935.411.347-80"); // Valid formatted CPF cpfSchema.parse("93541134780"); // Valid unformatted CPF // With custom error message const cpfWithError = z.cpf({ error: "Invalid CPF document" }); // In object schemas const CustomerSchema = z.object({ name: z.string(), cpf: z.cpf({ error: "CPF inválido" }), email: z.string().email(), }); type Customer = z.infer; const customer = CustomerSchema.parse({ name: "João Silva", cpf: "714.602.380-01", email: "joao@example.com", }); // Invalid examples that throw errors try { cpfSchema.parse("111.111.111-11"); // Repeated digits } catch (error) { console.error("Validation failed"); } try { cpfSchema.parse("935.411.347-81"); // Invalid check digit } catch (error) { console.error("Validation failed"); } ``` -------------------------------- ### Brazilian Telephone Validation Source: https://github.com/wesleydmscn/zcn/wiki/Schemas Validates a Brazilian phone number (landline or mobile). Checks DDD range, length, and mobile prefix. ```APIDOC ## GET /z/telephone ### Description Validates a Brazilian phone number (landline or mobile). Checks DDD range, length, and mobile prefix. Supports various formats including `(##) 9####-####`, `(##) ####-####`, `##########`, and `###########`. ### Method GET ### Endpoint /z/telephone ### Parameters #### Query Parameters - **value** (string) - Required - The telephone number to validate. ### Request Example ``` GET /z/telephone?value=(11) 98765-4321 ``` ### Response #### Success Response (200) - **isValid** (boolean) - True if the telephone number is valid, false otherwise. #### Response Example ```json { "isValid": true } ``` ``` -------------------------------- ### Coerce and Validate Port Numbers (TypeScript) Source: https://context7.com/wesleydmscn/zcn/llms.txt Coerces input values (strings or numbers) into validated integer port numbers within the range of 0 to 65535. This is achieved using z.coerce.port() from the zcn library, which is particularly useful for processing environment variables or API inputs that might not strictly adhere to the number type. It handles type conversion and range validation automatically. ```typescript import { z } from "zcn"; // Port number coercion (string to number) const portNumberSchema = z.coerce.port(); // Environment variable schema with coercion const EnvSchema = z.object({ PORT: z.coerce.port({ error: "Invalid PORT environment variable" }), DB_PORT: z.coerce.port(), REDIS_PORT: z.coerce.port().default(6379), }); // Coerces string to number const port1: number = portNumberSchema.parse("3000"); // Returns 3000 as number const port2: number = portNumberSchema.parse(8080); // Returns 8080 as number const port3: number = portNumberSchema.parse("443"); // Returns 443 as number // Environment configuration with defaults const env = EnvSchema.parse({ PORT: "3000", // String coerced to number DB_PORT: "5432", // REDIS_PORT uses default 6379 }); console.log(typeof env.PORT); // "number" console.log(env.PORT); // 3000 console.log(env.REDIS_PORT); // 6379 // Docker compose configuration const DockerServiceSchema = z.object({ serviceName: z.string(), image: z.string(), ports: z.object({ internal: z.coerce.port(), external: z.coerce.port(), }), environment: z.record(z.string()), }); const service = DockerServiceSchema.parse({ serviceName: "api", image: "node:18-alpine", ports: { internal: "3000", external: "80", }, environment: { NODE_ENV: "production", }, }); // API server with dynamic port allocation const ServerConfigSchema = z.object({ primaryPort: z.coerce.port(), backupPorts: z.array(z.coerce.port()), adminPort: z.coerce.port().optional(), }); const serverConfig = ServerConfigSchema.parse({ primaryPort: "8080", backupPorts: ["8081", "8082", "8083"], adminPort: "9090", }); // Invalid examples try { portNumberSchema.parse("70000"); // Above maximum } catch (error) { console.error("Port exceeds maximum value"); } try { portNumberSchema.parse("3000.5"); // Decimal not allowed } catch (error) { console.error("Port must be integer"); } ``` -------------------------------- ### Validate Brazilian CEP using ZCN Source: https://context7.com/wesleydmscn/zcn/llms.txt Validates Brazilian postal codes (CEP) using the z.cep() schema. It accepts 8-digit codes with optional hyphens, validates numeric ranges, and rejects repeated digits. Invalid formats or ranges will throw errors. ```typescript import { z } from "zcn"; // Basic CEP validation const cepSchema = z.cep(); // Address schema with CEP const AddressSchema = z.object({ cep: z.cep({ error: "Invalid postal code" }), street: z.string(), number: z.string(), city: z.string(), state: z.string().length(2), }); // Valid formats cepSchema.parse("01310-100"); // São Paulo, formatted cepSchema.parse("01310100"); // Unformatted cepSchema.parse("20040-020"); // Rio de Janeiro // Complete address validation const address = AddressSchema.parse({ cep: "01310-100", street: "Avenida Paulista", number: "1578", city: "São Paulo", state: "SP", }); // E-commerce shipping form const ShippingSchema = z.object({ recipientName: z.string(), cep: z.cep({ error: "CEP inválido" }), address: z.string(), complement: z.string().optional(), }); const shipping = ShippingSchema.parse({ recipientName: "João Silva", cep: "22640100", address: "Rua Jardim Botânico, 1008", complement: "Apto 301", }); // Invalid examples try { cepSchema.parse("11111111"); // Repeated digits rejected } catch (error) { console.error("Invalid CEP"); } try { cepSchema.parse("99999999"); // Out of valid range } catch (error) { console.error("Invalid CEP"); } ``` -------------------------------- ### Validate Brazilian CNPJ with Zod Extensions Source: https://context7.com/wesleydmscn/zcn/llms.txt Validates Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) business registration numbers. It supports both formatted (XX.XXX.XXX/XXXX-XX) and unformatted (14 digits) inputs, ensuring correct check digit verification. The validator can be used independently or as part of more complex Zod object schemas with custom error messages. ```typescript import { z } from "zcn"; // Basic CNPJ validation const cnpjSchema = z.cnpj(); // With custom error const cnpjWithError = z.cnpj({ error: "Invalid business registration" }); // Company registration form const CompanySchema = z.object({ businessName: z.string().min(3), cnpj: z.cnpj({ error: "CNPJ inválido" }), email: z.string().email(), phone: z.telephone(), }); const company = CompanySchema.parse({ businessName: "Tech Solutions LTDA", cnpj: "11.222.333/0001-81", // Formatted email: "contact@techsolutions.com", phone: "(11) 98765-4321", }); // Alternative unformatted const companyAlt = CompanySchema.parse({ businessName: "Another Company", cnpj: "11222333000181", // Unformatted 14 digits email: "info@another.com", phone: "11987654321", }); // Validation errors try { cnpjSchema.parse("11.111.111/1111-11"); // Repeated digits rejected } catch (error) { console.error("Invalid CNPJ format"); } ``` -------------------------------- ### Brazilian CEP Validation Source: https://github.com/wesleydmscn/zcn/wiki/Schemas Validates a Brazilian postal code (CEP). Supports both dashed and undashed formats, rejecting invalid or repeated digits. ```APIDOC ## GET /z/cep ### Description Validates a Brazilian postal code (CEP). Supports both dashed (`#####-###`) and undashed (`########`) formats, rejecting invalid ranges and repeated digits. ### Method GET ### Endpoint /z/cep ### Parameters #### Query Parameters - **value** (string) - Required - The CEP value to validate. ### Request Example ``` GET /z/cep?value=12345-678 ``` ### Response #### Success Response (200) - **isValid** (boolean) - True if the CEP is valid, false otherwise. #### Response Example ```json { "isValid": true } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.