Skip to content
/ maoli Public

Maoli is a C# helper library for common Brazilian business rules (CEP, CPF, CNPJ, and number speller), compatible with .NET Framework 4.0+, .NET Core 1.0+, and .NET 5+.

License

Notifications You must be signed in to change notification settings

aueda/maoli

Repository files navigation

Maoli

Codacy Badge Coverage Status NuGet Version Maoli no fuget.org Join the chat at https://gitter.im/maoli-net/community BuitlWithDot.Net shield

Versão em português: LEIAME.md

Maoli is a C# helper library for common Brazilian business rules (CEP, CPF and CNPJ), compatible with .NET Framework 4.6+, .NET Core 1.0+, and .NET 5+.

Currently implements:

  • CEP validation
  • CPF validation
  • CNPJ validation

For client-side validation of CPF and CNPJ, please see Maoli.js.

Documentation

Cep

Cep.Validate(string value) - checks if a string value is a valid CEP representation. Returns true if CEP string is valid; false otherwise.

if (Cep.Validate("99999-999"))
{
  Console.WriteLine("CEP is valid");
}

Cpf

Cpf.Validate(string value) - checks if a string value is a valid CPF representation. Returns true if CPF string is valid; false otherwise.

if (Cpf.Validate("999.999.99-99"))
{
  Console.WriteLine("CPF is valid");
}

Cpf.Complete(string value) - completes a partial CPF string by appending a valid checksum trailing. Returns a CPF string with a valid checksum trailing.

// outputs "99999999999"
var cpf = Cpf.Complete("99999999"));

Cnpj

Cnpj.Validate(string value) - checks if a string value is a valid CNPJ representation. Returns true if CNPJ string is valid; false otherwise.

if (Cnpj.Validate("99.999.999/9999-99"))
{
  Console.WriteLine("CPNJ is valid");
}

Cnpj.Complete(string value) - completes a partial CNPJ string by appending a valid checksum trailing. Returns a CNPJ string with a valid checksum trailing.

// outputs "99999999999999"
var cnpj = Cnpj.Complete("999999999999"));

Number Speller

NumberSpeller.Spell(int value) - returns the number spelled in Brazilian Portuguese. The maximum value is int.MaxValue.

var speller = new NumberSpeller();

var number = speller.Spell(2022);

// outputs "dois mil duzentos e vinte e dois"
Console.WriteLine(number);

NumberSpeller.Spell(long value) - returns the number spelled in Brazilian Portuguese. The maximum value is long.MaxValue.

var speller = new NumberSpeller();

var number = speller.Spell(2022L);

// outputs "dois mil duzentos e vinte e dois"
Console.WriteLine(number);

NuGet Package

To install Maoli using NuGet, run the following command in the Package Manager Console:

Install-Package Maoli

See the NuGet website.

.NET Fiddles

The following .NET Fiddles are available to test Maoli:

Source Code

Source code is available at GitHub.

License

This project is licensed under the MIT License.

Author

Adriano Ueda @adriueda

About

Maoli is a C# helper library for common Brazilian business rules (CEP, CPF, CNPJ, and number speller), compatible with .NET Framework 4.0+, .NET Core 1.0+, and .NET 5+.

Topics

Resources

License

Stars

Watchers

Forks

Languages