{"id":32708042,"url":"https://github.com/lacussolutions/br-utils-php_cnpj-gen","last_synced_at":"2026-01-20T16:59:32.862Z","repository":{"id":313142080,"uuid":"1049981850","full_name":"LacusSolutions/br-utils-php_cnpj-gen","owner":"LacusSolutions","description":"Utility function to generate valid CNPJ (Brazilian employer ID).","archived":false,"fork":false,"pushed_at":"2025-10-17T23:30:26.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-19T00:03:38.332Z","etag":null,"topics":["br","cnpj","composer","generator","helpers","packagist","php","utils"],"latest_commit_sha":null,"homepage":"https://github.com/LacusSolutions/br-utils-php","language":"PHP","has_issues":false,"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/LacusSolutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-03T19:21:29.000Z","updated_at":"2025-10-17T23:30:29.000Z","dependencies_parsed_at":"2025-09-04T06:49:04.957Z","dependency_job_id":"f67c4b9d-e78f-4d77-8bf4-be6f5f849aca","html_url":"https://github.com/LacusSolutions/br-utils-php_cnpj-gen","commit_stats":null,"previous_names":["lacussolutions/br-utils-php_cnpj-gen"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/LacusSolutions/br-utils-php_cnpj-gen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LacusSolutions","download_url":"https://codeload.github.com/LacusSolutions/br-utils-php_cnpj-gen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-gen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282234691,"owners_count":26636392,"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","status":"online","status_checked_at":"2025-11-02T02:00:06.609Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["br","cnpj","composer","generator","helpers","packagist","php","utils"],"created_at":"2025-11-02T03:01:36.880Z","updated_at":"2026-01-20T16:59:32.856Z","avatar_url":"https://github.com/LacusSolutions.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![cnpj-gen for PHP](https://br-utils.vercel.app/img/cover_cnpj-gen.jpg)\n\n[![Packagist Version](https://img.shields.io/packagist/v/lacus/cnpj-gen)](https://packagist.org/packages/lacus/cnpj-gen)\n[![Packagist Downloads](https://img.shields.io/packagist/dm/lacus/cnpj-gen)](https://packagist.org/packages/lacus/cnpj-gen)\n[![PHP Version](https://img.shields.io/packagist/php-v/lacus/cnpj-gen)](https://www.php.net/)\n[![Test Status](https://img.shields.io/github/actions/workflow/status/LacusSolutions/br-utils-php/ci.yml?label=ci/cd)](https://github.com/LacusSolutions/br-utils-php/actions)\n[![Last Update Date](https://img.shields.io/github/last-commit/LacusSolutions/br-utils-php)](https://github.com/LacusSolutions/br-utils-php)\n[![Project License](https://img.shields.io/github/license/LacusSolutions/br-utils-php)](https://github.com/LacusSolutions/br-utils-php/blob/main/LICENSE)\n\nUtility function/class to generate valid CNPJ (Brazilian employer ID).\n\n\n\n| ![PHP 8.1](https://img.shields.io/badge/PHP-8.1-777BB4?logo=php\u0026logoColor=white) | ![PHP 8.2](https://img.shields.io/badge/PHP-8.2-777BB4?logo=php\u0026logoColor=white) | ![PHP 8.3](https://img.shields.io/badge/PHP-8.3-777BB4?logo=php\u0026logoColor=white) | ![PHP 8.4](https://img.shields.io/badge/PHP-8.4-777BB4?logo=php\u0026logoColor=white) |\n|--- | --- | --- | --- |\n| Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |\n\n## Installation\n\n```bash\n# using Composer\n$ composer require lacus/cnpj-gen\n```\n\n## Import\n\n```php\n\u003c?php\n// Using class-based resource\nuse Lacus\\CnpjGen\\CnpjGenerator;\n\n// Or using function-based one\nuse function Lacus\\CnpjGen\\cnpj_gen;\n```\n\n## Usage\n\n### Object-Oriented Usage\n\n```php\n$generator = new CnpjGenerator();\n$cnpj = $generator-\u003egenerate(); // returns '65453043000178'\n\n// With options\n$cnpj = $generator-\u003egenerate(\n    format: true\n); // returns '65.453.043/0001-78'\n\n$cnpj = $generator-\u003egenerate(\n    prefix: '45623767'\n); // returns '45623767000296'\n\n$cnpj = $generator-\u003egenerate(\n    prefix: '456237670002',\n    format: true\n); // returns '45.623.767/0002-96'\n```\n\nThe options can be provided to the constructor or the `generate()` method. If passed to the constructor, the options will be attached to the `CnpjGenerator` instance. When passed to the `generate()` method, it only applies the options to that specific call.\n\n```php\n$generator = new CnpjGenerator(format: true);\n\n$cnpj1 = $generator-\u003egenerate(); // '65.453.043/0001-78' (uses instance options)\n$cnpj2 = $generator-\u003egenerate(format: false); // '65453043000178' (overrides instance options)\n$cnpj3 = $generator-\u003egenerate(); // '12.345.678/0001-95' (uses instance options again)\n```\n\n### Imperative programming\n\nThe helper function `cnpj_gen()` is just a functional abstraction. Internally it creates an instance of `CnpjGenerator` and calls the `generate()` method right away.\n\n```php\n$cnpj = cnpj_gen(); // returns '65453043000178'\n\n$cnpj = cnpj_gen(format: true); // returns '65.453.043/0001-78'\n\n$cnpj = cnpj_gen(prefix: '45623767'); // returns '45623767000296'\n\n$cnpj = cnpj_gen(prefix: '456237670002', format: true); // returns '45.623.767/0002-96'\n```\n\n### Generator Options\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `format` | `?bool` | `false` | Whether to format the output with dots, slash, and dash |\n| `prefix` | `?string` | `''` | If you have CNPJ initials and want to complete it with valid digits. The string provided must contain between 0 and 12 digits. The branch ID (characters 8 to 11) cannot be \"0000\". |\n\n## Contribution \u0026 Support\n\nWe welcome contributions! Please see our [Contributing Guidelines](https://github.com/LacusSolutions/br-utils-php/blob/main/CONTRIBUTING.md) for details. But if you find this project helpful, please consider:\n\n- ⭐ Starring the repository\n- 🤝 Contributing to the codebase\n- 💡 [Suggesting new features](https://github.com/LacusSolutions/br-utils-php/issues)\n- 🐛 [Reporting bugs](https://github.com/LacusSolutions/br-utils-php/issues)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/LacusSolutions/br-utils-php/blob/main/LICENSE) file for details.\n\n## Changelog\n\nSee [CHANGELOG](https://github.com/LacusSolutions/br-utils-php/blob/main/packages/cnpj-gen/CHANGELOG.md) for a list of changes and version history.\n\n---\n\nMade with ❤️ by [Lacus Solutions](https://github.com/LacusSolutions)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flacussolutions%2Fbr-utils-php_cnpj-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flacussolutions%2Fbr-utils-php_cnpj-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flacussolutions%2Fbr-utils-php_cnpj-gen/lists"}