Koala Utils

Integration with @koalarx/utils — delay, CPF/CNPJ, strings, dates, and arrays.

The template ships with @koalarx/utils as an official dependency. The library provides reusable validators, converters, and operators (KlString, KlDelay, KlDate, KlArray, etc.).

It is already listed in the template package.json and installed automatically by kl-nest new ( core module). For existing projects:

bash
bun add @koalarx/utils
Resource Package Usage in Koala Nest
delay(ms) @koalarx/utils/KlDelay JobsBootstrapService, cron job loop, E2E setup
validateCpf / validateCnpj @koalarx/utils/KlString documentNumberSchema in src/core/schemas/
maskCpf / maskCnpj @koalarx/utils/KlString setMaskDocumentNumber in src/core/schemas/
typescript
import { delay } from '@koalarx/utils/KlDelay';

await delay(options.bootstrapDelayMs);

Used in JobsBootstrapService and CronJobHandlerBase to wait between job cycles.

CNPJ now accepts letters and digits in the first 12 positions (format AA.AAA.AAA/AAAA-DV), per RFB Normative Instruction No. 2,229/2024. CPF remains numeric-only. Validation and masking live in @koalarx/utils/KlString; the wrapper strips mask punctuation (., /, -) only, preserving letters in CNPJ:

typescript
import { validateCpf, validateCnpj } from '@koalarx/utils/KlString';
import {
  isCnpjDocument,
  isCpfDocument,
} from '@/core/schemas/document-number.utils';

export function documentNumberSchema(value: string) {
  if (isCpfDocument(value)) return validateCpf(value);
  if (isCnpjDocument(value)) return validateCnpj(value);
  return false;
}

Accepted examples: 529.982.247-25 (CPF), 11.222.333/0001-81 (numeric CNPJ), and SK.CB2.G25/0001-32 (alphanumeric CNPJ).

Re-exported through the @/core/schemas barrel for domain validators.

Import subpaths as needed:

typescript
import { KlArray } from '@koalarx/utils/KlArray';
import { KlDate } from '@koalarx/utils/KlDate';
import { KlCron } from '@koalarx/utils/KlCron';
import { toCamelCase, randomString } from '@koalarx/utils/KlString';

See the package README for the full method list.

  • Prefer @koalarx/utils over reimplementing document validation, delay, or string formatting.
  • Keep thin wrappers in src/core/schemas/ when integrating with Zod or OpenAPI — avoid importing the library directly in controllers.
  • For new generic utilities, consider contributing to koala-utils instead of duplicating logic in the template.

Koala Nest

A facilitator for building NestJS APIs with DDD architecture. Code copied into your repository — readable, adaptable, and under your control.

Creator

igordrangel.com.br

Design, back-end, and product strategy.

Quick Commands

Global CLI and scripts in the generated project

  • bun install -g @koalarx/nest
  • kl-nest new
  • kl-nest add cache
  • bun run migration:run # CRUD template
  • kl-nest --help
© 2026 Koala NestBuilt for NestJS developers and AI-assisted workflows.