{"id":25234469,"url":"https://github.com/lucasteles/brazilmodels","last_synced_at":"2026-03-05T03:31:32.825Z","repository":{"id":62850815,"uuid":"562990322","full_name":"lucasteles/BrazilModels","owner":"lucasteles","description":"CPF/CNPJ utilities","archived":false,"fork":false,"pushed_at":"2024-10-14T18:40:39.000Z","size":5178,"stargazers_count":15,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T20:19:32.079Z","etag":null,"topics":["brazil","cnpj","cpf","documento","dotnet","validador","validator"],"latest_commit_sha":null,"homepage":"https://lucasteles.github.io/BrazilModels/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucasteles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"lucasteles"}},"created_at":"2022-11-07T17:18:50.000Z","updated_at":"2024-07-18T19:40:37.000Z","dependencies_parsed_at":"2024-07-19T00:19:43.648Z","dependency_job_id":"53efdfc7-4ad5-469c-9744-51ecff1c7591","html_url":"https://github.com/lucasteles/BrazilModels","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"a4287286b5687c3e3cd143d47326e7ecf7464805"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasteles%2FBrazilModels","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasteles%2FBrazilModels/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasteles%2FBrazilModels/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasteles%2FBrazilModels/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucasteles","download_url":"https://codeload.github.com/lucasteles/BrazilModels/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238306452,"owners_count":19450146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brazil","cnpj","cpf","documento","dotnet","validador","validator"],"created_at":"2025-02-11T13:59:39.912Z","updated_at":"2025-10-26T10:30:26.207Z","avatar_url":"https://github.com/lucasteles.png","language":"C#","funding_links":["https://github.com/sponsors/lucasteles"],"categories":[],"sub_categories":[],"readme":"[![Nuget](https://img.shields.io/nuget/v/BrazilModels.svg?style=flat)](https://www.nuget.org/packages/BrazilModels)\n[![CI](https://github.com/lucasteles/BrazilModels/actions/workflows/ci.yml/badge.svg)](https://github.com/lucasteles/BrazilModels/actions/workflows/ci.yml)\n\n![](https://raw.githubusercontent.com/lucasteles/BrazilModels/site/test_report_badge.svg)\n![](https://raw.githubusercontent.com/lucasteles/BrazilModels/site/badge_linecoverage.svg)\n![](https://raw.githubusercontent.com/lucasteles/BrazilModels/site/badge_branchcoverage.svg)\n\n![](https://raw.githubusercontent.com/lucasteles/BrazilModels/site/dotnet_version_badge.svg)\n![](https://img.shields.io/badge/Lang-C%23-green)\n![https://editorconfig.org/](https://img.shields.io/badge/style-EditorConfig-black)\n![](https://raw.githubusercontent.com/lucasteles/BrazilModels/site/lines_badge.svg)\n\n# BrazilModels\n\nThis library contains Models, Formatters and Validator for common Brazilian documents\n\n## Getting started\n\n[NuGet package](https://www.nuget.org/packages/BrazilModels) available:\n\n```ps\n$ dotnet add package BrazilModels\n```\n\n## Validation and Formatting\n\n### Cpf\n\n```cs\nusing BrazilModels;\n\nCpf.Validate(\"00123456797\");    // True\nCpf.Validate(\"99912345606\");    // True\nCpf.Validate(\"999.123.456-06\"); // True\nCpf.Validate(\"00000000000\");    // False\nCpf.Validate(\"invalid\");        // False\n\nCpf.Format(\"99912345606\", withMask: true);    // \"999.123.456-06\"\nCpf.Format(\"319.818.120-83\", withMask: true); // \"319.818.120-83\"\nCpf.Format(\"1234567890\", withMask: true);     // \"012.345.678-90\"\nCpf.Format(\"12345601\", withMask: true);       // \"000.123.456-01\"\n\nCpf.Format(\"319.818.120-83\"); // \"31981812083\"\nCpf.Format(\"085.974.710-77\"); // \"08597471077\"\nCpf.Format(\"08597471077\");    // \"08597471077\"\nCpf.Format(\"12345601\");       // \"00012345601\"\n```\n\n### Cnpj\n\n```cs\nusing BrazilModels;\n\nCnpj.Validate(\"49.020.406/0001-25\");// True\nCnpj.Validate(\"49020406000125\");    // True\nCnpj.Validate(\"invalid\");           // False\n\nCnpj.Format(\"49020406000125\", withMask: true);     // \"49.020.406/0001-25\"\nCnpj.Format(\"49.020.406/0001-25\", withMask: true); // \"49.020.406/0001-25\"\nCnpj.Format(\"1123456000101\", withMask: true);      // \"01.123.456/0001-01\"\n\nCnpj.Format(\"49020406000125\");     // \"49020406000125\"\nCnpj.Format(\"49.020.406/0001-25\"); // \"49020406000125\"\nCnpj.Format(\"01.123.456/0001-01\"); // \"1123456000101\"\n```\n\n### CpfCnpj (can be CPF or CNPJ)\n\n```cs\nusing BrazilModels;\n\nCpfCnpj.Validate(\"49.020.406/0001-25\");// True\nCpfCnpj.Validate(\"49020406000125\");    // True\nCpfCnpj.Validate(\"99912345606\");       // True\nCpfCnpj.Validate(\"999.123.456-06\");    // True\n\nCpfCnpj.Format(\"49020406000125\", withMask: true); // \"49.020.406/0001-25\"\nCpfCnpj.Format(\"99912345606\", withMask: true);    // \"999.123.456-06\"\n\nCpfCnpj.Format(\"085.974.710-77\");         // \"08597471077\"\nCpfCnpj.Format(\"49.020.406/0001-25\");     // \"49020406000125\"\n```\n\n## Models\n\nYou can use some value types defined in this lib to strongly type your domain:\n\n- `Cpf`\n- `Cnpj`\n- `CpfCnpj`\n- `Email`\n\nHow to use it?\n\n```cs\nvar cpf = new Cpf(\"319.818.120-83\");\nvar cnpj = new Cnpj(\"49.020.406/0001-25\");\n\nclass Person {\n    public Guid Id {get;init;}\n    public Cpf Cpf {get;init;}\n    public Email Email {get;init;}\n}\n\nclass Company {\n    public Guid Id {get;init;}\n    public Cnpj Cnpj {get;init;}\n}\n\n```\n\n### Serialization\n\nThis already contain converters for:\n\n- `System.Text.Json`\n- `Swashbuckle.AspNetCore.Annotations`\n- `System.ComponentModel.TypeConverter`\n\n### Using with EntityFramework\n\nYou can easily define a `ValueConverter` for any of the types defined in this library as:\n\n```cs\n\npublic class YourDbContext : DbContext\n{\n    protected override void OnModelCreating(ModelBuilder modelBuilder)\n    {\n        var cliente = modelBuilder.Entity\u003cPerson\u003e();\n        cliente.Property(x =\u003e x.Cpf).HasConversion(t =\u003e t.Value, t =\u003e new(t));\n        cliente.Property(x =\u003e x.Email).HasConversion(t =\u003e t.Value, t =\u003e new(t));\n    }\n}\n\n```\n\n### Culture Info\n\nYou can use  `BrazilCulture.CultureInfo` as a light-weight alternative `pt-BR` culture. It formats as expected dates and\ndecimal values.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasteles%2Fbrazilmodels","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucasteles%2Fbrazilmodels","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasteles%2Fbrazilmodels/lists"}