{"id":20388554,"url":"https://github.com/efureev/php-type-normalizer","last_synced_at":"2026-01-27T22:17:49.544Z","repository":{"id":152592150,"uuid":"626444086","full_name":"efureev/php-type-normalizer","owner":"efureev","description":"Type Normalizer","archived":false,"fork":false,"pushed_at":"2024-10-15T12:39:58.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T12:42:27.750Z","etag":null,"topics":["normalize","type-normalizer","types"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/efureev.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2023-04-11T13:34:22.000Z","updated_at":"2024-10-15T12:39:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"77770615-2666-4f1d-9e87-d1722113f725","html_url":"https://github.com/efureev/php-type-normalizer","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Fphp-type-normalizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Fphp-type-normalizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Fphp-type-normalizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efureev%2Fphp-type-normalizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/efureev","download_url":"https://codeload.github.com/efureev/php-type-normalizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248556965,"owners_count":21124156,"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":["normalize","type-normalizer","types"],"created_at":"2024-11-15T03:11:23.995Z","updated_at":"2026-01-27T22:17:49.518Z","avatar_url":"https://github.com/efureev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Type Normalizer\n\n![](https://img.shields.io/badge/php-8.1-blue.svg)\n![PHP Package](https://github.com/efureev/php-type-normalizer/workflows/PHP%20Package/badge.svg?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/efureev/php-type-normalizer/v/stable?format=flat)](https://packagist.org/packages/efureev/php-type-normalizer)\n[![Total Downloads](https://poser.pugx.org/efureev/php-type-normalizer/downloads)](https://packagist.org/packages/efureev/php-type-normalizer)\n\n## Description\n\nIt transforms mixed types into you need.\n\n## Install\n\nFor php \u003e= 8.2\n\n```bash\ncomposer require efureev/php-type-normalizer \"^1.0\"\n```\n\n## Basic Using\n\n```php\nTypeNormalizer::toInt('1') // 1\nTypeNormalizer::toBool('1') // true\nTypeNormalizer::toFloat('1.2') // 1.2\nTypeNormalizer::toString(true) // 'true'\n```\n\n## Using with Middleware\n\nMiddleware may be any `callable` variable.\n\n```php\nTypeNormalizer::toInt('  -132323  ', 'abs'); // 132323\nTypeNormalizer::toInt('  -2  ', 'abs', ['pow', 2]); // 4\nTypeNormalizer::toString('  test   ', 'trim', 'mb_strtoupper'); // 'TEST'\nTypeNormalizer::toString(null, static fn(string $item) =\u003e '\u003cnone\u003e'); // '\u003cnone\u003e'\n```\n\nMiddleware may be defined with params:\n\n```php\nTypeNormalizer::toInt('  -2  ', 'abs', ['pow', 2]); // 4\nTypeNormalizer::toInt('  -2  ', 'abs', [fn(int $item, int $plus) =\u003e pow($item, 2) + $plus, 1]); // 5\n```\n\n## Transformation Map\n\n### Integer\n\n```php\nTypeNormalizer::toInt(1) // 1 \nTypeNormalizer::toInt(211) // 211 \nTypeNormalizer::toInt('211') // 211 \nTypeNormalizer::toInt('    211 ') // 211 \nTypeNormalizer::toInt('1') // 1 \nTypeNormalizer::toInt('true') // 1\nTypeNormalizer::toInt('  true  ') // 1\nTypeNormalizer::toInt(true) // 1\nTypeNormalizer::toInt(1.00) // 1\nTypeNormalizer::toInt('1.00') // 1\n\nTypeNormalizer::toInt(false) // 0\nTypeNormalizer::toInt('  false  ') // 0\nTypeNormalizer::toInt('     0  ') // 0\nTypeNormalizer::toInt(0) // 0\nTypeNormalizer::toInt('') // 0\nTypeNormalizer::toInt('   ') // 0\nTypeNormalizer::toInt(null) // 0\n\nTypeNormalizer::toInt('hello') // exception\nTypeNormalizer::toInt('1.2') // exception\nTypeNormalizer::toInt(1.2) // exception\n```\n\n### Boolean\n\n```php\nTypeNormalizer::toBool(1) // true\nTypeNormalizer::toBool(' 1  ') // true\nTypeNormalizer::toBool(true) // true\nTypeNormalizer::toBool('  true ') // true\nTypeNormalizer::toBool(' 1.00  ') // true\nTypeNormalizer::toBool(1.00) // true\n\nTypeNormalizer::toBool(0) // false\nTypeNormalizer::toBool(false) // false\nTypeNormalizer::toBool('  false  ') // false\nTypeNormalizer::toBool('   0 ') // false\nTypeNormalizer::toBool('   0.0 ') // false\nTypeNormalizer::toBool('') // false\nTypeNormalizer::toBool('   ') // false\nTypeNormalizer::toBool(null) // false\n\nTypeNormalizer::toBool('hello') // exception\nTypeNormalizer::toBool(1.2) // exception\nTypeNormalizer::toBool(22) // exception\nTypeNormalizer::toBool('22') // exception\nTypeNormalizer::toBool(' 0. 00') // exception\n```\n\n### Float\n\n```php\nTypeNormalizer::toFloat(1) // 1\nTypeNormalizer::toFloat(' 1  ') // 1\nTypeNormalizer::toFloat(' -132323  ') // -1\nTypeNormalizer::toFloat(true) // 1\nTypeNormalizer::toFloat('  true ') // 1\nTypeNormalizer::toFloat(' 1.00  ') // 1\nTypeNormalizer::toFloat(' 21.21  ') // 21.21\nTypeNormalizer::toFloat(1.00) // 1\n\nTypeNormalizer::toFloat(0) // 0\nTypeNormalizer::toFloat(false) // 0\nTypeNormalizer::toFloat('  false  ') // 0\nTypeNormalizer::toFloat('   0 ') // 0\nTypeNormalizer::toFloat('   0.0 ') // 0\nTypeNormalizer::toFloat('') // 0\nTypeNormalizer::toFloat('   ') // 0\nTypeNormalizer::toFloat(null) // 0\n\nTypeNormalizer::toFloat('hello') // exception\n```\n\n## Test\n\n```bash\ncomposer test\ncomposer test-cover # with coverage\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefureev%2Fphp-type-normalizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fefureev%2Fphp-type-normalizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefureev%2Fphp-type-normalizer/lists"}