All Projects → jordanbrauer → unit-converter

jordanbrauer / unit-converter

Licence: MIT License
Convert standard units from one to another with this easy to use, lightweight package

Programming Languages

PHP
23972 projects - #3 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to unit-converter

Laravel Paket
Composer GUI. Manage Laravel dependencies from web interface without switching to command line!
Stars: ✭ 143 (+37.5%)
Mutual labels:  package, composer
Wasm Pack
This tool seeks to be a one-stop shop for building and working with rust- generated WebAssembly that you would like to interop with JavaScript, in the browser or with Node.js. wasm-pack helps you build rust-generated WebAssembly packages that you could publish to the npm registry, or otherwise use alongside any javascript packages in workflows that you already use, such as webpack.
Stars: ✭ 3,848 (+3600%)
Mutual labels:  registry, package
Laravel Messenger
Simple user messaging package for Laravel
Stars: ✭ 2,140 (+1957.69%)
Mutual labels:  package, composer
Package Skeleton
📦 My base for PHP packages.
Stars: ✭ 6 (-94.23%)
Mutual labels:  package, composer
laration
Simple package to see all current configurations being used by your Laravel application
Stars: ✭ 47 (-54.81%)
Mutual labels:  package, composer
Htmlcache
Laravel middleware to cache the rendered html
Stars: ✭ 35 (-66.35%)
Mutual labels:  package, composer
Nest.land
🦕 The nest.land website
Stars: ✭ 294 (+182.69%)
Mutual labels:  registry, package
Novagram
An Object-Oriented PHP library for Telegram Bots
Stars: ✭ 112 (+7.69%)
Mutual labels:  composer, oop
Enseada
A Cloud native multi-package registry
Stars: ✭ 80 (-23.08%)
Mutual labels:  registry, package
Npm Api
Node.js library for getting info from NPM’s API
Stars: ✭ 67 (-35.58%)
Mutual labels:  registry, package
Sleepingowladmin
🦉 Administrative interface builder for Laravel (Laravel admin)
Stars: ✭ 671 (+545.19%)
Mutual labels:  package, composer
package-command
Lists, installs, and removes WP-CLI packages.
Stars: ✭ 16 (-84.62%)
Mutual labels:  package, composer
aplus
Aplus Command Line Tool
Stars: ✭ 71 (-31.73%)
Mutual labels:  package, composer
Pharbuilder
Create Phar of Composer based PHP application
Stars: ✭ 122 (+17.31%)
Mutual labels:  package, composer
video-downloader
Video Downloader for Facebook.
Stars: ✭ 63 (-39.42%)
Mutual labels:  package, composer
Nebula
Nebula is a minimalistic and easy to use administration tool for Laravel applications, made with Laravel, Alpine.js, and Tailwind CSS.
Stars: ✭ 190 (+82.69%)
Mutual labels:  package, composer
Nupdate
A comfortable update solution for .NET-applications.
Stars: ✭ 394 (+278.85%)
Mutual labels:  registry, package
metric.js
ianramosc.github.io/metric.js
Stars: ✭ 29 (-72.12%)
Mutual labels:  package, unit-conversion
devliver
Your private self hosted composer repository with user management
Stars: ✭ 50 (-51.92%)
Mutual labels:  package, composer
secure compare
A secure compare for Elixir.
Stars: ✭ 17 (-83.65%)
Mutual labels:  package

Unit Converter

Latest Stable Version Latest Unstable Version PHP from Packagist composer.lock available license

CI Workflow Code Maintainability Code Coverage Technical Debt Maintenance Packagist


Convert all kinds of standard units of measurement from one to another with this highly customizable, easy to use, lightweight PHP component.

Table of Contents:

  1. About the Component
  2. Installing the Component
  3. Basic Usage
  4. Documentation

1. About the Component

This unit converter component aims to be modern and follow best practices. It also aims to be fully SI compliant (eventually...).

It supports the following types of measurement by default (support for more measurement types are on the roadmap).

  • Area
  • Data Transfer Rates Coming Soon!
  • Digital Storage New!
  • Energy (Power)
  • Frequency
  • Fuel Economy
  • Length
  • Mass (Weight)
  • Plane Angle (Rotation)
  • Pressure
  • Speed
  • Temperature
  • Time
  • Volume

You also have the ability to override & customize the default units, as well as add your own!

2. Installing the Component

The best way to install the component is with Composer. For other supported methods, see the wiki artile on installation.

$ composer require jordanbrauer/unit-converter

3. Basic Usage

Using the component is very easy, especially if you have used the Symfony or Laravel frameworks before.

Quick-Start

If 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,

Static Constructors
use UnitConverter\UnitConverter;

$converter = UnitConverter::default(); # simple calculator
$converter = UnitConverter::binary(); # binary calculator (BC math)
Builder
use UnitConverter\UnitConverter;

$converter = UnitConverter::createBuilder()
    ->addSimpleCalculator()
    ->addDefaultRegistry()
    ->build();

and use it like this,

$converter->convert(1)->from("in")->to("cm"); # (float) 2.54

and you're done! For a more in-depth setup guide, check the wiki.

Usage Examples

Here 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 & valid, do contain some pseudo-code in them for demonstration purposes.

The Traffic Camera

In 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 & 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.

Here we construct a new unit & give it a value representing how many of the unit exists,

$capturedSpeed = new MilePerHour(59);

Next, a conversion of units needs to take place, because this traffic camera model is being used in a country that uses the metric system.

As 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 & powerful methods: as(). It allows us to convert units without the direct use of the UnitConverter & UnitRegistry objects – giving the benefit of even cleaner code & type safety.

$isOverSpeedLimit = function (SpeedUnit $speed) {
    return $speed->as(new KilometrePerHour) > 50;
};

if ($isOverSpeedLimit($capturedSpeed)) { # (bool) true
    TrafficCamera::snapPhoto();
}

Conversion Results as Words

Sometimes 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.

$converter->convert(1)->from('in')->spellout('cm');       # (string) two point five four
$converter->convert(1)->from('in')->spellout('cm', 'fr'); # (string) deux virgule cinq quatre

4. Documentation

There are two kinds of in-depth documentation for this project: user & API documentation. Use whichever one you need to help answer your questions!

User Documentation

Setup guides, in-depth examples, tutorials, and explanations on the component for users who are looking to integrate it into their project, as-is.

User Documentation

API Documentation

If 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!

API Documentation

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].