{"id":17122276,"url":"https://github.com/jordanbrauer/unit-converter","last_synced_at":"2025-04-04T13:09:21.505Z","repository":{"id":45192811,"uuid":"105950839","full_name":"jordanbrauer/unit-converter","owner":"jordanbrauer","description":"Convert standard units from one to another with this easy to use, lightweight package ","archived":false,"fork":false,"pushed_at":"2023-09-20T00:06:46.000Z","size":21271,"stargazers_count":128,"open_issues_count":13,"forks_count":40,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T12:05:02.188Z","etag":null,"topics":["component","composer","library","measurements","oop","package","php","php7","registry","unit-conversion","unit-converter"],"latest_commit_sha":null,"homepage":"https://jordanbrauer.github.io/unit-converter/","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/jordanbrauer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null}},"created_at":"2017-10-05T23:35:47.000Z","updated_at":"2024-11-26T06:25:00.000Z","dependencies_parsed_at":"2023-12-10T00:09:36.718Z","dependency_job_id":"cb867dd3-5735-4674-a38f-9085a5d6259e","html_url":"https://github.com/jordanbrauer/unit-converter","commit_stats":{"total_commits":481,"total_committers":18,"mean_commits":26.72222222222222,"dds":0.4636174636174636,"last_synced_commit":"a8732503f8e0c6038c805e1449dc498162bfc9a2"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbrauer%2Funit-converter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbrauer%2Funit-converter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbrauer%2Funit-converter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbrauer%2Funit-converter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jordanbrauer","download_url":"https://codeload.github.com/jordanbrauer/unit-converter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247181253,"owners_count":20897368,"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":["component","composer","library","measurements","oop","package","php","php7","registry","unit-conversion","unit-converter"],"created_at":"2024-10-14T18:07:14.310Z","updated_at":"2025-04-04T13:09:21.479Z","avatar_url":"https://github.com/jordanbrauer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unit Converter\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/jordanbrauer/unit-converter?color=257ec2\u0026label=stable\u0026style=flat-square)](https://packagist.org/packages/jordanbrauer/unit-converter)\n[![Latest Unstable Version](https://poser.pugx.org/jordanbrauer/unit-converter/v/unstable?format=flat-square)](//packagist.org/packages/jordanbrauer/unit-converter)\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/jordanbrauer/unit-converter?color=8892be\u0026style=flat-square)](https://secure.php.net/releases/)\n[![composer.lock available](https://poser.pugx.org/jordanbrauer/unit-converter/composerlock?format=flat-square)](https://packagist.org/packages/jordanbrauer/unit-converter)\n[![license](https://img.shields.io/github/license/jordanbrauer/unit-converter.svg?style=flat-square)](https://github.com/jordanbrauer/unit-converter/blob/master/LICENSE)\n\n[![CI Workflow](https://img.shields.io/github/workflow/status/jordanbrauer/unit-converter/CI?style=flat-square\u0026label=tests)](https://github.com/jordanbrauer/unit-converter/actions?query=workflow%3ACI)\n[![Code Maintainability](https://img.shields.io/codeclimate/maintainability/jordanbrauer/unit-converter.svg?style=flat-square)](https://codeclimate.com/github/jordanbrauer/unit-converter)\n[![Code Coverage](https://img.shields.io/codeclimate/coverage/jordanbrauer/unit-converter.svg?style=flat-square)](https://codeclimate.com/github/jordanbrauer/unit-converter)\n[![Technical Debt](https://img.shields.io/codeclimate/tech-debt/jordanbrauer/unit-converter.svg?style=flat-square)](https://codeclimate.com/github/jordanbrauer/unit-converter/issues)\n[![Maintenance](https://img.shields.io/maintenance/yes/2022.svg?style=flat-square)](https://github.com/jordanbrauer/unit-converter)\n[![Packagist](https://img.shields.io/packagist/dt/jordanbrauer/unit-converter.svg?style=flat-square)](https://packagist.org/packages/jordanbrauer/unit-converter)\n\n\u003cbr /\u003e\n\nConvert all kinds of standard units of measurement from one to another with this highly customizable, easy to use, lightweight PHP component.\n\n**Table of Contents:**\n\n1. [About the Component](#1-about-the-component)\n2. [Installing the Component](#2-installing-the-component)\n3. [Basic Usage](#3-basic-usage)\n4. [Documentation](#4-documentation)\n\n## 1. About the Component\n\nThis unit converter component aims to be modern and follow best practices. It also aims to be fully SI compliant (eventually...).\n\nIt supports the following types of measurement by default (support for more measurement types are on the roadmap).\n\n- Area\n- Data Transfer Rates _Coming Soon!_\n- Digital Storage **_New!_**\n- Energy (Power)\n- Frequency\n- Fuel Economy\n- Length\n- Mass (Weight)\n- Plane Angle (Rotation)\n- Pressure\n- Speed\n- Temperature\n- Time\n- Volume\n\nYou also have the ability to override \u0026 customize the default units, as well as [add your own](https://github.com/jordanbrauer/unit-converter/wiki/Unit-Customization-\u0026-Extension#adding-your-own-custom-units)!\n\n## 2. Installing the Component\n\nThe best way to install the component is with Composer. For other supported methods, [see the wiki](https://github.com/jordanbrauer/unit-converter/wiki/Installing-the-Package) artile on installation.\n\n```\n$ composer require jordanbrauer/unit-converter\n```\n\n## 3. Basic Usage\n\nUsing the component is very easy, especially if you have used the Symfony or Laravel frameworks before.\n\n### Quick-Start\n\nIf you'd like to skip the minutiae of this component's setup and get right down to business, you can get started by constructing a pre-configured converter via static constructors or the builder object, like so,\n\n###### Static Constructors\n\n```php\nuse UnitConverter\\UnitConverter;\n\n$converter = UnitConverter::default(); # simple calculator\n$converter = UnitConverter::binary(); # binary calculator (BC math)\n```\n\n###### Builder\n\n```php\nuse UnitConverter\\UnitConverter;\n\n$converter = UnitConverter::createBuilder()\n    -\u003eaddSimpleCalculator()\n    -\u003eaddDefaultRegistry()\n    -\u003ebuild();\n```\n\nand use it like this,\n\n```php\n$converter-\u003econvert(1)-\u003efrom(\"in\")-\u003eto(\"cm\"); # (float) 2.54\n```\n\nand you're done! For a more in-depth setup guide, [**check the wiki**](https://github.com/jordanbrauer/unit-converter/wiki).\n\n### Usage Examples\n\nHere are where some usage examples of something that may fit more along the lines of _\"real-life\"_, are found. Keep in mind that the code examples in each use-case, while working \u0026 valid, do contain **some** pseudo-code in them for demonstration purposes.\n\n#### The Traffic Camera\n\nIn this example, pretend we have a traffic camera that only captures speeds in Imperial measurement of _miles per hour_. The traffic camera records each passing car's speed to determine if they were speeding \u0026 if so, snap a photo of their license plate as proof to serve a ticket. In this case, the camera caught a speed of `59` _miles per hour_.\n\nHere we construct a new unit \u0026 give it a value representing how many of the unit exists,\n\n```php\n$capturedSpeed = new MilePerHour(59);\n```\n\nNext, a conversion of units needs to take place, because this traffic camera model is being used in a country that uses the metric system.\n\nAs you can see in this example, we are leveraging the power of typehints to ensure we only receive units of the desired measurement. Inside of the closure, we are using one of the unit's most convenient \u0026 powerful methods: `as()`. It allows us to convert units without the direct use of the `UnitConverter` \u0026 `UnitRegistry` objects – giving the benefit of even cleaner code \u0026 type safety.\n\n```php\n$isOverSpeedLimit = function (SpeedUnit $speed) {\n    return $speed-\u003eas(new KilometrePerHour) \u003e 50;\n};\n\nif ($isOverSpeedLimit($capturedSpeed)) { # (bool) true\n    TrafficCamera::snapPhoto();\n}\n```\n\n#### Conversion Results as Words\n\nSometimes you might need localization support for values. This component makes that a breeze by making using the `intl` extension. Simply opt for using the `spellout` method in lieu of `to`. You may also provide an optional locale as the second parameter to translate.\n\n```php\n$converter-\u003econvert(1)-\u003efrom('in')-\u003espellout('cm');       # (string) two point five four\n$converter-\u003econvert(1)-\u003efrom('in')-\u003espellout('cm', 'fr'); # (string) deux virgule cinq quatre\n```\n\n## 4. Documentation\n\nThere are two kinds of in-depth documentation for this project: user \u0026 API documentation. Use whichever one you need to help answer your questions!\n\n### User Documentation\n\nSetup guides, in-depth examples, tutorials, and explanations on the component for users who are looking to integrate it into their project, as-is.\n\n[User Documentation](https://github.com/jordanbrauer/unit-converter/wiki)\n\n### API Documentation\n\nIf you are looking to extend and hack on this component for your own project, these pages will give you insight into all about how the component works, through the awesome power of dockblocks!\n\n[API Documentation](https://jordanbrauer.github.io/unit-converter/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordanbrauer%2Funit-converter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjordanbrauer%2Funit-converter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordanbrauer%2Funit-converter/lists"}