{"id":20745276,"url":"https://github.com/techins-software/parse-bool","last_synced_at":"2026-01-11T13:10:50.211Z","repository":{"id":257791836,"uuid":"861728238","full_name":"TechIns-Software/parse-bool","owner":"TechIns-Software","description":"Library Utility for Checking Boolean Values","archived":false,"fork":false,"pushed_at":"2024-09-23T13:09:08.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-11T04:31:53.346Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/TechIns-Software.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,"publiccode":null,"codemeta":null}},"created_at":"2024-09-23T12:19:45.000Z","updated_at":"2024-09-23T12:41:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"465fc5b6-146c-49b4-a0b1-79b1a4061785","html_url":"https://github.com/TechIns-Software/parse-bool","commit_stats":null,"previous_names":["techins-software/parse-bool"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/TechIns-Software/parse-bool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechIns-Software%2Fparse-bool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechIns-Software%2Fparse-bool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechIns-Software%2Fparse-bool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechIns-Software%2Fparse-bool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TechIns-Software","download_url":"https://codeload.github.com/TechIns-Software/parse-bool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechIns-Software%2Fparse-bool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28304264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T11:18:18.743Z","status":"ssl_error","status_checked_at":"2026-01-11T11:07:56.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-17T07:19:27.431Z","updated_at":"2026-01-11T13:10:50.196Z","avatar_url":"https://github.com/TechIns-Software.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ParseBool\n\n`ParseBool` is a PHP class designed to facilitate the parsing and validation of boolean values from various input types. It simplifies the process of interpreting values that can be represented as true or false, making your code cleaner and more reliable.\n\n## Purpose\n\nThe primary purpose of the `ParseBool` class is to convert different data types—such as strings, numbers, and booleans—into a consistent boolean output (`true` or `false`). This is particularly useful when dealing with user input or data from external sources, where the representation of boolean values can vary.\n\n## Installation\n\nYou can include the `ParseBool` class in your project by copying the `ParseBool.php` file into your desired directory. \n\n## Usage\n\n### Parsing and Casting value into Boolean\n\nTo use the `ParseBool` class, simply call the `parseBool` method with your value as an argument. \n\n### Example\n\n```php\nuse Techins\\ParseBool\\ParseBool;\n\n$value1 = ParseBool::parseBool('yes');  // Returns true\n$value2 = ParseBool::parseBool(0);       // Returns false\n$value3 = ParseBool::parseBool(true);    // Returns true\n$value4 = ParseBool::parseBool('off');    // Returns false\n\n$value4 = ParseBool::parseBool('dfsafsdfsdfds');    // Returns false\n$value4 = ParseBool::parseBool('dfsafsdfsdfds',true);    // Throws exception look bellow\n\n```\n\n### Strict checking\nUpon strinct checking if the provided value cannot be interpreted as a boolean, a `ValueNotBooleanOneException` will be thrown. You should wrap your calls in a try-catch block to handle this exception gracefully:\n\n```php\ntry {\n    // Checklbox Value\n    $input = $_POST['checkbox_val'];\n    $result = ParseBool::parseBool($input,true);\n} catch (ValueNotBooleanOneException $e) {\n    // Handle the exception\n}\n```\n\n\n\n#### Input validation\nYou can also validate a boolean value (for example if value is a checked checkbox)\n\n```\n$value1 = ParseBool::validateBooleableValue('yes');  // Returns true\n$value2 = ParseBool::validateBooleableValue(0);       // Returns true\n$value3 = ParseBool::validateBooleableValue(true);    // Returns true\n$value4 = ParseBool::validateBooleableValue('off');    // Returns true\n$value3 = ParseBool::validateBooleableValue(false);    // Returns true\n$value3 = ParseBool::validateBooleableValue('true');    // Returns true\n\n\n$value5 = ParseBool::validateBooleableValue('ddsasadsa');  // Returns false\n$value6 = ParseBool::validateBooleableValue(-1);       // Returns false\n$value6 = ParseBool::validateBooleableValue(\"\");       // Returns false\n\n```\n\n## Valid Boolean Values\n\nThe following values are considered valid and will be converted to `true`:\n\n- `1`\n- `true`\n- `'on'`\n- `'yes'`\n- `'true'`\n\nThe following values are considered valid and will be converted to `false`:\n\n- `0`\n- `false`\n- `'off'`\n- `'no'`\n- `'false'`\n- `f`\n\nAny other values will result in a `ValueNotBooleanOneException`.\n\n\n## Usage upon checkboxes\n\nAssuming we have thius form\n\n```\n\u003cform method = \"POST\" action=\"/myscript.php\"\u003e\n    \u003cinput type=\"checkbox\" name=\"check\"\u003e\n\u003c/form\u003e\n\n```\n\nYou can use `validateBooleableValue` to validate whether checkbox is checked.\n\n```\n\n$checked = ParseBool::parseBool($_POST['check']??false);\n\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Please submit a pull request or open an issue for any enhancements or bug fixes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechins-software%2Fparse-bool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechins-software%2Fparse-bool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechins-software%2Fparse-bool/lists"}