FORMATTER - Formatação de Texto e Dados
O que é este Node?
O FORMATTER é o node responsável por formatar texto e números automaticamente aplicando transformações padrão (uppercase, lowercase, capitalize) e formatações específicas (moeda, telefone, CPF, datas).
Por que este Node existe?
Dados capturados do usuário precisam padronização e formatação. O FORMATTER existe para:
- Padronizar entrada: Converter texto para formato consistente (UPPERCASE, lowercase, Capitalize)
- Formatar números: Aplicar formatação de moeda, números com separadores de milhar
- Formatar documentos: Aplicar máscara em CPF, telefone mantendo padrão brasileiro
- Formatar datas: Converter datas para formato legível em português
- Customização: Aplicar padrões customizados com regex
- Apresentação: Preparar dados para exibição ao usuário de forma profissional
Como funciona internamente?
Quando o FORMATTER é executado, o sistema:
- Recebe input (texto, número ou data)
- Identifica formatType escolhido
- Aplica transformação baseado no tipo:
- Texto: uppercase, lowercase, capitalize
- Números: formatação com locale (pt-BR)
- Moeda: adiciona símbolo R$ e casas decimais
- Telefone/CPF: aplica máscara brasileira
- Datas: converte para formato local
- Custom: aplica pattern regex customizado
- Valida resultado da formatação
- Retorna texto formatado pronto para uso
Código interno (ai-processing-executor.service.ts:529-601):
private async executeFormatter(parameters: any, context: any): Promise<any> {
const { input, formatType, pattern, locale } = parameters;
this.logger.log(`📝 FORMATTER - Formatting ${formatType}: ${input}`);
if (input === undefined || input === null) {
throw new Error('Input is required for formatting');
}
let result;
switch (formatType) {
case 'uppercase':
result = String(input).toUpperCase();
break;
case 'lowercase':
result = String(input).toLowerCase();
break;
case 'capitalize':
result = String(input).replace(/\w\S*/g, (txt) =>
txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
);
break;
case 'currency':
result = new Intl.NumberFormat(locale || 'pt-BR', {
style: 'currency',
currency: 'BRL'
}).format(Number(input));
break;
case 'number':
result = new Intl.NumberFormat(locale || 'pt-BR').format(Number(input));
break;
case 'date':
result = new Date(input).toLocaleDateString(locale || 'pt-BR');
break;
case 'phone':
const cleanPhone = String(input).replace(/\D/g, '');
if (cleanPhone.length === 11) {
result = `(${cleanPhone.slice(0, 2)}) ${cleanPhone.slice(2, 7)}-${cleanPhone.slice(7)}`;
} else {
result = input;
}
break;
case 'cpf':
const cleanCPF = String(input).replace(/\D/g, '');
if (cleanCPF.length === 11) {
result = `${cleanCPF.slice(0, 3)}.${cleanCPF.slice(3, 6)}.${cleanCPF.slice(6, 9)}-${cleanCPF.slice(9)}`;
} else {
result = input;
}
break;
case 'custom':
if (pattern) {
result = String(input).replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, pattern);
} else {
result = input;
}
break;
default:
result = input;
}
return {
success: true,
action: 'text_formatted',
input: input,
formatType: formatType,
pattern: pattern || null,
locale: locale || 'pt-BR',
result: result,
timestamp: new Date().toISOString()
};
}
Quando você DEVE usar este Node?
Use FORMATTER sempre que precisar transformar e formatar dados:
Casos de uso
- Padronizar nomes: Converter "MARIA SILVA" para "Maria Silva"
- Formatar moeda: Converter 1500.50 para "R$ 1.500,50"
- Formatar telefone: Converter "11999887766" para "(11) 99988-7766"
- Formatar CPF: Converter "12345678900" para "123.456.789-00"
- Formatar datas: Converter "2025-01-15" para "15/01/2025"
- Normalizar texto: Converter entrada do usuário para UPPERCASE antes de comparar
- Apresentar valores: Formatar números com separadores de milhar
Quando NÃO usar FORMATTER
- Validação de dados: Use VALIDATOR para validar formato
- Cálculos matemáticos: Use CALCULATOR para operações
- Manipulação complexa: Para regex avançado, considere processamento customizado
Parâmetros Detalhados
input (string/number, obrigatório)
O que é: O valor que será formatado. Pode ser texto, número ou data.
Flow completo para testar:
{
"name": "Teste FORMATTER - Input Básico",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "input_1",
"type": "input",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Pedir Nome",
"parameters": {
"message": "Digite seu nome completo:",
"variable": "nome_raw"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Formatar Nome",
"parameters": {
"input": "{{nome_raw}}",
"formatType": "capitalize"
}
}
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Salvar Formatado",
"parameters": {
"name": "nome_formatado",
"value": "{{formatter_result}}"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 900, "y": 100 },
"data": {
"label": "Confirmar",
"parameters": {
"message": "Nome formatado: {{nome_formatado}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 1100, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "input_1" },
{ "source": "input_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "variable_1" },
{ "source": "variable_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: Digite "maria silva santos" - sistema retorna "Maria Silva Santos"
formatType (string, obrigatório)
O que é: Tipo de formatação a ser aplicada.
Valores aceitos:
uppercase- TEXTO EM MAIÚSCULASlowercase- texto em minúsculascapitalize- Primeira Letra De Cada Palavracurrency- R$ 1.500,50number- 1.500date- 15/01/2025phone- (11) 99988-7766cpf- 123.456.789-00custom- Padrão customizado com regex
Flow completo para testar uppercase:
{
"name": "Teste FORMATTER - Uppercase",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir Texto",
"parameters": {
"name": "texto",
"value": "Maria da Silva"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "UPPERCASE",
"parameters": {
"input": "{{texto}}",
"formatType": "uppercase"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Mostrar",
"parameters": {
"message": "Original: {{texto}}\nFormatado: {{formatter_result}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: "Maria da Silva" vira "MARIA DA SILVA"
Flow completo para testar lowercase:
{
"name": "Teste FORMATTER - Lowercase",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir Texto",
"parameters": {
"name": "texto",
"value": "PRODUTOS EM PROMOÇÃO"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "lowercase",
"parameters": {
"input": "{{texto}}",
"formatType": "lowercase"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Mostrar",
"parameters": {
"message": "Original: {{texto}}\nFormatado: {{formatter_result}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: "PRODUTOS EM PROMOÇÃO" vira "produtos em promoção"
Flow completo para testar capitalize:
{
"name": "Teste FORMATTER - Capitalize",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir Texto",
"parameters": {
"name": "nome",
"value": "josé roberto da silva"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Capitalize",
"parameters": {
"input": "{{nome}}",
"formatType": "capitalize"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Mostrar",
"parameters": {
"message": "Original: {{nome}}\nFormatado: {{formatter_result}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: "josé roberto da silva" vira "José Roberto Da Silva"
Flow completo para testar currency:
{
"name": "Teste FORMATTER - Currency",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir Valor",
"parameters": {
"name": "preco",
"value": "1500.50"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Formatar Moeda",
"parameters": {
"input": "{{preco}}",
"formatType": "currency",
"locale": "pt-BR"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Mostrar Preço",
"parameters": {
"message": "Valor: {{formatter_result}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: 1500.50 vira "R$ 1.500,50"
Flow completo para testar phone:
{
"name": "Teste FORMATTER - Phone",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir Telefone",
"parameters": {
"name": "tel",
"value": "11999887766"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Formatar Telefone",
"parameters": {
"input": "{{tel}}",
"formatType": "phone"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Mostrar",
"parameters": {
"message": "Original: {{tel}}\nFormatado: {{formatter_result}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: "11999887766" vira "(11) 99988-7766"
Flow completo para testar cpf:
{
"name": "Teste FORMATTER - CPF",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir CPF",
"parameters": {
"name": "cpf_raw",
"value": "12345678900"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Formatar CPF",
"parameters": {
"input": "{{cpf_raw}}",
"formatType": "cpf"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Mostrar",
"parameters": {
"message": "CPF: {{formatter_result}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: "12345678900" vira "123.456.789-00"
Flow completo para testar date:
{
"name": "Teste FORMATTER - Date",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir Data",
"parameters": {
"name": "data_iso",
"value": "2025-01-15"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Formatar Data",
"parameters": {
"input": "{{data_iso}}",
"formatType": "date",
"locale": "pt-BR"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Mostrar",
"parameters": {
"message": "Data formatada: {{formatter_result}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: "2025-01-15" vira "15/01/2025"
pattern (string, opcional)
O que é: Padrão regex customizado para formatação. Usado apenas com formatType: "custom".
Flow completo para testar pattern:
{
"name": "Teste FORMATTER - Custom Pattern",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir Código",
"parameters": {
"name": "codigo",
"value": "12345678900"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Pattern Customizado",
"parameters": {
"input": "{{codigo}}",
"formatType": "custom",
"pattern": "$1-$2-$3-$4"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Mostrar",
"parameters": {
"message": "Código formatado: {{formatter_result}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: "12345678900" com pattern "$1-$2-$3-$4" vira "123-456-789-00"
locale (string, opcional)
O que é: Locale para formatação de números, moeda e datas.
Padrão: "pt-BR" (Português do Brasil)
Valores comuns:
pt-BR- Português Brasil (R$ 1.500,50 / 15/01/2025)en-US- Inglês EUA ($1,500.50 / 1/15/2025)es-ES- Espanhol (1.500,50 € / 15/01/2025)
Flow completo para testar locale:
{
"name": "Teste FORMATTER - Locale",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Definir Valor",
"parameters": {
"name": "valor",
"value": "1500.50"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Formato Brasil",
"parameters": {
"input": "{{valor}}",
"formatType": "currency",
"locale": "pt-BR"
}
}
},
{
"id": "formatter_2",
"type": "formatter",
"position": { "x": 500, "y": 200 },
"data": {
"label": "Formato EUA",
"parameters": {
"input": "{{valor}}",
"formatType": "number",
"locale": "en-US"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 150 },
"data": {
"label": "Mostrar Ambos",
"parameters": {
"message": "Brasil (pt-BR): {{formatter_1_result}}\nEUA (en-US): {{formatter_2_result}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 150 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "variable_1" },
{ "source": "variable_1", "target": "formatter_1" },
{ "source": "variable_1", "target": "formatter_2" },
{ "source": "formatter_1", "target": "message_1" },
{ "source": "formatter_2", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: 1500.50 vira "R$ 1.500,50" (pt-BR) e "1,500.5" (en-US)
Parâmetros
| Campo | Tipo | Obrigatório | Descrição |
|---|---|---|---|
| input | string/number | Sim | Valor a ser formatado |
| formatType | string | Sim | Tipo de formatação (uppercase, lowercase, capitalize, currency, number, date, phone, cpf, custom) |
| pattern | string | Não | Padrão regex customizado (apenas para formatType: custom) |
| locale | string | Não | Locale para formatação (padrão: pt-BR) |
Exemplo 1: Cadastro com Formatação
Objetivo: Capturar dados do usuário e formatar tudo antes de salvar
JSON para Importar
{
"name": "Cadastro com Formatação Completa",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "input_1",
"type": "input",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Pedir Nome",
"parameters": {
"message": "Digite seu nome completo:",
"variable": "nome_raw"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Formatar Nome",
"parameters": {
"input": "{{nome_raw}}",
"formatType": "capitalize"
}
}
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Salvar Nome",
"parameters": {
"name": "nome",
"value": "{{formatter_result}}"
}
}
},
{
"id": "input_2",
"type": "input",
"position": { "x": 900, "y": 100 },
"data": {
"label": "Pedir CPF",
"parameters": {
"message": "Digite seu CPF (apenas números):",
"variable": "cpf_raw"
}
}
},
{
"id": "formatter_2",
"type": "formatter",
"position": { "x": 1100, "y": 100 },
"data": {
"label": "Formatar CPF",
"parameters": {
"input": "{{cpf_raw}}",
"formatType": "cpf"
}
}
},
{
"id": "variable_2",
"type": "variable",
"position": { "x": 1300, "y": 100 },
"data": {
"label": "Salvar CPF",
"parameters": {
"name": "cpf",
"value": "{{formatter_result}}"
}
}
},
{
"id": "input_3",
"type": "input",
"position": { "x": 1500, "y": 100 },
"data": {
"label": "Pedir Telefone",
"parameters": {
"message": "Digite seu telefone (apenas números):",
"variable": "tel_raw"
}
}
},
{
"id": "formatter_3",
"type": "formatter",
"position": { "x": 1700, "y": 100 },
"data": {
"label": "Formatar Telefone",
"parameters": {
"input": "{{tel_raw}}",
"formatType": "phone"
}
}
},
{
"id": "variable_3",
"type": "variable",
"position": { "x": 1900, "y": 100 },
"data": {
"label": "Salvar Telefone",
"parameters": {
"name": "telefone",
"value": "{{formatter_result}}"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 2100, "y": 100 },
"data": {
"label": "Resumo",
"parameters": {
"message": "CADASTRO COMPLETO\n\nNome: {{nome}}\nCPF: {{cpf}}\nTelefone: {{telefone}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 2300, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "input_1" },
{ "source": "input_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "variable_1" },
{ "source": "variable_1", "target": "input_2" },
{ "source": "input_2", "target": "formatter_2" },
{ "source": "formatter_2", "target": "variable_2" },
{ "source": "variable_2", "target": "input_3" },
{ "source": "input_3", "target": "formatter_3" },
{ "source": "formatter_3", "target": "variable_3" },
{ "source": "variable_3", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Saída esperada:
Sistema: Digite seu nome completo:
Usuário: maria silva santos
Sistema: Digite seu CPF (apenas números):
Usuário: 12345678900
Sistema: Digite seu telefone (apenas números):
Usuário: 11999887766
Sistema: CADASTRO COMPLETO
Nome: Maria Silva Santos
CPF: 123.456.789-00
Telefone: (11) 99988-7766
Exemplo 2: Orçamento com Formatação de Moeda
Objetivo: Calcular valor e apresentar formatado em reais
JSON para Importar
{
"name": "Orçamento com Formatação de Valores",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "number_1",
"type": "number",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Pedir Quantidade",
"parameters": {
"message": "Quantas unidades você deseja?",
"variable": "quantidade",
"min": 1
}
}
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Preço Unitário",
"parameters": {
"name": "preco_unit",
"value": "150.50"
}
}
},
{
"id": "calculator_1",
"type": "calculator",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Calcular Total",
"parameters": {
"expression": "{{quantidade}} * {{preco_unit}}"
}
}
},
{
"id": "variable_2",
"type": "variable",
"position": { "x": 900, "y": 100 },
"data": {
"label": "Salvar Total",
"parameters": {
"name": "total",
"value": "{{calculator_result}}"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 1100, "y": 100 },
"data": {
"label": "Formatar Preço Unit",
"parameters": {
"input": "{{preco_unit}}",
"formatType": "currency",
"locale": "pt-BR"
}
}
},
{
"id": "variable_3",
"type": "variable",
"position": { "x": 1300, "y": 100 },
"data": {
"label": "Salvar Preço Formatado",
"parameters": {
"name": "preco_formatado",
"value": "{{formatter_result}}"
}
}
},
{
"id": "formatter_2",
"type": "formatter",
"position": { "x": 1500, "y": 100 },
"data": {
"label": "Formatar Total",
"parameters": {
"input": "{{total}}",
"formatType": "currency",
"locale": "pt-BR"
}
}
},
{
"id": "variable_4",
"type": "variable",
"position": { "x": 1700, "y": 100 },
"data": {
"label": "Salvar Total Formatado",
"parameters": {
"name": "total_formatado",
"value": "{{formatter_result}}"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 1900, "y": 100 },
"data": {
"label": "Mostrar Orçamento",
"parameters": {
"message": "ORÇAMENTO\n\nQuantidade: {{quantidade}} unidades\nPreço unitário: {{preco_formatado}}\nTOTAL: {{total_formatado}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 2100, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "number_1" },
{ "source": "number_1", "target": "variable_1" },
{ "source": "variable_1", "target": "calculator_1" },
{ "source": "calculator_1", "target": "variable_2" },
{ "source": "variable_2", "target": "formatter_1" },
{ "source": "formatter_1", "target": "variable_3" },
{ "source": "variable_3", "target": "formatter_2" },
{ "source": "formatter_2", "target": "variable_4" },
{ "source": "variable_4", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Saída esperada:
Sistema: Quantas unidades você deseja?
Usuário: 10
Sistema: ORÇAMENTO
Quantidade: 10 unidades
Preço unitário: R$ 150,50
TOTAL: R$ 1.505,00
Exemplo 3: Normalizar Texto para Comparação
Objetivo: Normalizar resposta do usuário para UPPERCASE antes de comparar
JSON para Importar
{
"name": "Menu com Normalização de Texto",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "message_1",
"type": "message",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Menu",
"parameters": {
"message": "Escolha uma opção:\n\nA - Vendas\nB - Suporte\nC - Cancelamento"
}
}
},
{
"id": "input_1",
"type": "input",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Capturar Opção",
"parameters": {
"message": "Digite A, B ou C:",
"variable": "opcao_raw"
}
}
},
{
"id": "formatter_1",
"type": "formatter",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Normalizar UPPERCASE",
"parameters": {
"input": "{{opcao_raw}}",
"formatType": "uppercase"
}
}
},
{
"id": "variable_1",
"type": "variable",
"position": { "x": 900, "y": 100 },
"data": {
"label": "Salvar Normalizado",
"parameters": {
"name": "opcao",
"value": "{{formatter_result}}"
}
}
},
{
"id": "switch_1",
"type": "switch",
"position": { "x": 1100, "y": 100 },
"data": {
"label": "Verificar Opção",
"parameters": {
"variable": "opcao",
"cases": [
{ "value": "A", "label": "Vendas" },
{ "value": "B", "label": "Suporte" },
{ "value": "C", "label": "Cancelamento" }
]
}
}
},
{
"id": "message_2",
"type": "message",
"position": { "x": 1300, "y": 0 },
"data": {
"label": "Vendas",
"parameters": {
"message": "Você será direcionado para VENDAS"
}
}
},
{
"id": "message_3",
"type": "message",
"position": { "x": 1300, "y": 100 },
"data": {
"label": "Suporte",
"parameters": {
"message": "Você será direcionado para SUPORTE"
}
}
},
{
"id": "message_4",
"type": "message",
"position": { "x": 1300, "y": 200 },
"data": {
"label": "Cancelamento",
"parameters": {
"message": "Você será direcionado para CANCELAMENTO"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 1500, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "message_1" },
{ "source": "message_1", "target": "input_1" },
{ "source": "input_1", "target": "formatter_1" },
{ "source": "formatter_1", "target": "variable_1" },
{ "source": "variable_1", "target": "switch_1" },
{ "source": "switch_1", "target": "message_2", "label": "A" },
{ "source": "switch_1", "target": "message_3", "label": "B" },
{ "source": "switch_1", "target": "message_4", "label": "C" },
{ "source": "message_2", "target": "end_1" },
{ "source": "message_3", "target": "end_1" },
{ "source": "message_4", "target": "end_1" }
]
}
Saída esperada:
Sistema: Escolha uma opção:
A - Vendas
B - Suporte
C - Cancelamento
Sistema: Digite A, B ou C:
Usuário: a (minúsculo - mas funciona!)
Sistema: Você será direcionado para VENDAS
Resposta do Node
{
"success": true,
"action": "text_formatted",
"input": "maria silva santos",
"formatType": "capitalize",
"pattern": null,
"locale": "pt-BR",
"result": "Maria Silva Santos",
"timestamp": "2025-01-15T10:30:00.000Z"
}
Tipos de Formatação Suportados
| formatType | Entrada | Saída | Uso |
|---|---|---|---|
| uppercase | "Maria Silva" | "MARIA SILVA" | Normalizar para comparação |
| lowercase | "PRODUTOS" | "produtos" | URLs, slugs |
| capitalize | "josé roberto" | "José Roberto" | Nomes próprios |
| currency | 1500.50 | "R$ 1.500,50" | Preços, valores monetários |
| number | 1500.50 | "1.500,5" | Números com separadores |
| date | "2025-01-15" | "15/01/2025" | Datas legíveis |
| phone | "11999887766" | "(11) 99988-7766" | Telefones brasileiros (11 dígitos) |
| cpf | "12345678900" | "123.456.789-00" | CPF brasileiro |
| custom | "12345678900" | "(pattern definido)" | Formatação customizada |
Boas Práticas
SIM:
- Sempre formatar nomes com capitalize antes de salvar
- Formatar moeda para exibição ao usuário
- Normalizar com uppercase/lowercase antes de comparações
- Formatar CPF/telefone para melhor legibilidade
- Usar locale apropriado para o público-alvo
- Salvar dados formatados em variáveis separadas
NÃO:
- Não use FORMATTER para validação (use VALIDATOR)
- Não formate valores que serão usados em cálculos (formato depois)
- Não aplique formatação múltiplas vezes no mesmo valor
- Não use custom pattern sem testar antes
Dicas
Normalização: Use uppercase/lowercase antes de comparar strings para evitar problemas com case-sensitive
Apresentação profissional: Sempre formate valores monetários com currency antes de mostrar ao usuário
Pipeline de formatação: Capture → Valide → Formate → Salve → Exiba
Telefone: O formatType "phone" só funciona para números brasileiros de 11 dígitos (DDD + 9 + número)
CPF: O formatType "cpf" só funciona para CPF de 11 dígitos. Para validar CPF, use VALIDATOR
Custom patterns: Teste seu pattern regex antes de usar em produção
Locale: Use pt-BR para Brasil, en-US para EUA, es-ES para Espanha
Próximo Node
→ CALCULATOR - Fazer cálculos matemáticos → VALIDATOR - Validar formatos de dados → VARIABLE - Salvar valores formatados