🇧🇷 Directus Brazilian Standards
Complete Brazilian formatting extensions for Directus - Currency (BRL), Postal Codes (CEP), and Tax IDs (CPF) with interfaces and displays.
✨ Features
🇧🇷 Brazilian Currency (BRL)
- Live formatting while typing (e.g., 215 → R$ 2,15)
- Smart input handling for different amounts
- Validation with min/max value support
- API returns numbers, not strings
- Examples:
- Type
215
→ showsR$ 2,15
- Type
21578
→ showsR$ 215,78
- Type
2156789
→ showsR$ 21.567,89
- Type
📮 Brazilian CEP (Postal Code)
- Automatic formatting (12345678 → 12.345-678)
- Real-time validation (8 digits required)
- Visual feedback with success/error indicators
- Stores clean numbers in database
👤 Brazilian CPF (Tax ID)
- Live formatting (12345678901 → 123.456.789-01)
- Full CPF validation using official algorithm
- Prevents invalid patterns (like 111.111.111-11)
- Visual validation feedback
- Privacy masking option for displays
🆔 CNPJ (Brazilian Company Tax ID)
- Interface:
brazilian-cnpj
- Display:
brazilian-cnpj
- Features:
- Automatic formatting (XX.XXX.XXX/XXXX-XX)
- Real-time validation using official algorithm
- 🆕 Smart paste: Automatically cleans formatted CNPJs when pasted
- 🆕 API Lookup: Automatic company data lookup via CNPJ.ws API
- 🆕 Auto-fill mapping: Automatically populate other form fields
- 🆕 Manual search trigger: Search button for user-controlled API calls
CNPJ API Lookup Configuration
The CNPJ interface now supports automatic company data lookup using the publica.cnpj.ws API:
- Enable API Lookup: Toggle to enable CNPJ.ws API integration
- API Token (Optional): For future commercial features (not required for public API)
- Auto-fill Field Mapping: JSON mapping of API fields to form fields
- Search Button: Manual trigger for API lookup (appears when API lookup is enabled)
How it works:
- User types CNPJ with automatic formatting and validation
- Smart paste: Copy formatted CNPJs (e.g., "33.000.167/0001-01") and paste directly - formatting is automatically cleaned and reapplied
- When API lookup is enabled, a search button (🔍) appears next to the input
- User clicks the search button to trigger company data lookup
- Mapped fields are automatically populated with company information
Example mapping:
{
"company_name": "razao_social",
"trade_name": "estabelecimento.nome_fantasia",
"complete_address": "estabelecimento.tipo_logradouro + ' ' + estabelecimento.logradouro + ', ' + estabelecimento.numero + ' - ' + estabelecimento.complemento",
"city": "estabelecimento.cidade.nome",
"state": "estabelecimento.estado.sigla",
"phone": "estabelecimento.telefone1",
"email": "estabelecimento.email"
}
Mapping Format:
- Simple mapping:
"form_field": "api_field"
- Concatenation:
"form_field": "api_field1 + ' separator ' + api_field2"
- String literals: Use single or double quotes for static text
- Multiple fields: Combine any number of API fields with separators
Concatenation Examples:
{
"full_address": "estabelecimento.tipo_logradouro + ' ' + estabelecimento.logradouro + ', ' + estabelecimento.numero",
"contact_info": "estabelecimento.telefone1 + ' - ' + estabelecimento.email",
"company_info": "razao_social + ' (' + estabelecimento.nome_fantasia + ')'"
}
Available API fields:
razao_social
- Company legal namecapital_social
- Share capitalnatureza_juridica.descricao
- Legal nature descriptionporte.descricao
- Company size descriptionestabelecimento.nome_fantasia
- Trade nameestabelecimento.email
- Email addressestabelecimento.telefone1
- Primary phoneestabelecimento.telefone2
- Secondary phoneestabelecimento.logradouro
- Street addressestabelecimento.numero
- Street numberestabelecimento.complemento
- Address complementestabelecimento.bairro
- Neighborhoodestabelecimento.cidade.nome
- City nameestabelecimento.estado.nome
- State nameestabelecimento.estado.sigla
- State abbreviationestabelecimento.cep
- ZIP codeestabelecimento.situacao_cadastral
- Registration statusestabelecimento.data_inicio_atividade
- Activity start dateestabelecimento.atividade_principal.descricao
- Main activity description
📦 Installation
Via NPM
npm install directus-brazilian-standards
🐛 v1.4.1 Bug Fix: Fixed critical currency formatting issue where typing
10000
displayed asR$ 100,00
instead ofR$ 10.000,00
Via Directus Marketplace
- Go to Settings → Extensions → Marketplace
- Search for "Brazilian Standards"
- Click Install
🚀 Usage
Currency Fields
1. Create field → Type: Decimal → Precision: 12,2
2. Interface: Brazilian Currency (BRL)
3. Display: Brazilian Currency (BRL)
4. Configure options as needed
CEP Fields
1. Create field → Type: String → Max Length: 8
2. Interface: Brazilian CEP
3. Display: Brazilian CEP
4. Enable validation as needed
CPF Fields
1. Create field → Type: String → Max Length: 11
2. Interface: Brazilian CPF
3. Display: Brazilian CPF
4. Enable CPF validation as needed
CNPJ with API Lookup
- Configure the field with
Brazilian CNPJ
interface - Enable "Enable API Lookup" option
- (Optional) Add CNPJ.ws API token for commercial features
- Configure "Auto-fill Field Mapping" with your desired field mappings
- When users type a valid CNPJ, the extension will:
- Validate the CNPJ format
- Query CNPJ.ws API for company data
- Automatically fill mapped fields with company information
📊 API Response Examples
Currency Field
{
"price": 1299.99, // Number, perfect for calculations
"total": 25000.50 // No string conversion needed
}
CEP Field
{
"postal_code": "77360016" // Clean numbers for integrations
}
CPF Field
{
"tax_id": "01958284106" // Clean numbers for validation
}
⚙️ Configuration Options
Currency Interface
- Placeholder: Custom placeholder text (default: "R$ 0,00")
- Min Value: Minimum allowed value in BRL
- Max Value: Maximum allowed value in BRL
- Disabled: Disable input
Currency Display
- Show Currency Symbol: Toggle R$ symbol display
- Decimal Places: Number of decimal places (default: 2)
CEP Interface
- Placeholder: Custom placeholder text (default: "12.345-678")
- Required: Make field required
- Validate CEP: Enable format validation (8 digits)
- Disabled: Disable input
CEP Display
- Show Placeholder for Empty: Show placeholder for empty values
CPF Interface
- Placeholder: Custom placeholder text (default: "123.456.789-01")
- Required: Make field required
- Validate CPF: Enable full CPF validation with algorithm
- Disabled: Disable input
CPF Display
- Show Placeholder for Empty: Show placeholder for empty values
- Mask Digits for Privacy: Show as ..*- for privacy
🛠️ Development
This package includes both interfaces (for input/editing) and displays (for read-only views).
Interfaces Included:
brazilian-currency
- Currency input with live formattingbrazilian-cep
- CEP input with validationbrazilian-cpf
- CPF input with validationbrazilian-cnpj
- CNPJ input with validation and API lookup
Displays Included:
brazilian-currency-display
- Currency display with Brazilian formattingbrazilian-cep-display
- CEP display with formattingbrazilian-cpf-display
- CPF display with formatting and privacy optionsbrazilian-cnpj-display
- CNPJ display with formatting and API lookup
🌟 Why Use This Extension?
✅ Professional UX
Brazilian users see familiar formatting they expect
✅ Data Integrity
Proper validation prevents invalid entries
✅ API Efficiency
Clean data storage, no string parsing needed
✅ Developer Friendly
Easy to use, well-documented, TypeScript support
✅ Production Ready
Thoroughly tested, used in production systems
🔧 Requirements
- Directus: ^10.10.0
- Node.js: >=18.0.0
📝 Examples in Action
Currency Input
User types: 1000
Display shows: R$ 10,00
Database stores: 10.00
CEP Input
User types: 77360016
Display shows: 77.360-016
Database stores: "77360016"
CPF Input
User types: 01958284106
Display shows: 019.582.841-06
Database stores: "01958284106"
CNPJ Input
User types: 33.000.167/0001-01
Display shows: 33.000.167/0001-01
Database stores: "33.000.167/0001-01"
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
👨💻 Author
Bruno Ribeiro
- GitHub: @brunribeiro
- Project: Directus Renovando
🙏 Acknowledgments
- Built for the Brazilian Directus community
- Follows official Brazilian formatting standards
- Uses proper pt-BR locale formatting
- Implements official CPF validation algorithm
Made with ❤️ for the Brazilian developer community 🇧🇷