@tormentalabs/floyd-validators
v1.0.4
Published
Brazilian document validators (CPF/CNPJ) for Floyd SDK
Downloads
520
Maintainers
Readme
@tormentalabs/floyd-validators
Brazilian document validators (CPF/CNPJ) and Ethereum address validation for the Floyd SDK.
Installation
npm install @tormentalabs/floyd-validatorsUsage
CPF Validation
import { cpf } from '@tormentalabs/floyd-validators';
// Validate
cpf.validate('529.982.247-25'); // true
cpf.validate('12345678901'); // false
// Format
cpf.format('52998224725'); // '529.982.247-25'
// Unformat
cpf.unformat('529.982.247-25'); // '52998224725'
// Generate valid CPF (for testing)
const testCpf = cpf.generate(); // '52998224725'CNPJ Validation
import { cnpj } from '@tormentalabs/floyd-validators';
// Validate
cnpj.validate('11.222.333/0001-81'); // true
// Format
cnpj.format('11222333000181'); // '11.222.333/0001-81'
// Generate valid CNPJ (for testing)
const testCnpj = cnpj.generate();Auto-detect Document Type
import { validateDocument, detectDocumentType } from '@tormentalabs/floyd-validators';
// Validate with explicit type
validateDocument('52998224725', 'PF'); // true (CPF)
validateDocument('11222333000181', 'PJ'); // true (CNPJ)
// Auto-detect based on length
validateDocument('52998224725'); // true (detects CPF)
validateDocument('11222333000181'); // true (detects CNPJ)
// Detect type
detectDocumentType('52998224725'); // 'PF'
detectDocumentType('11222333000181'); // 'PJ'
detectDocumentType('invalid'); // nullEthereum Address Validation
import { validateEthereumAddress } from '@tormentalabs/floyd-validators';
validateEthereumAddress('0x742d35Cc6634C0532925a3b844Bc9e7595f7aaEf'); // true
validateEthereumAddress('invalid'); // falseAll Validators
import { validators } from '@tormentalabs/floyd-validators';
validators.cpf.validate('...');
validators.cnpj.validate('...');
validators.document.validate('...', 'PF');
validators.document.detect('...');
validators.ethereum.validate('0x...');Related Packages
- @tormentalabs/floyd-sdk - Main API client
- @tormentalabs/floyd-types - TypeScript definitions
License
MIT
