PHPackages                             laravel-enso/unit-conversion - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. laravel-enso/unit-conversion

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

laravel-enso/unit-conversion
============================

Unit conversion services for Laravel Enso

2.0.5(2mo ago)04.6k↓43.3%2MITPHPPHP ^8.3

Since Oct 12Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/laravel-enso/unit-conversion)[ Packagist](https://packagist.org/packages/laravel-enso/unit-conversion)[ Docs](https://github.com/laravel-enso/unit-conversion)[ RSS](/packages/laravel-enso-unit-conversion/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (24)Used By (0)

Unit Conversion
===============

[](#unit-conversion)

[![License](https://camo.githubusercontent.com/a05c8765fac80b12460248051c39804ff660d8ed3d074a9e7b58e920e33f8f86/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f756e69742d636f6e76657273696f6e2f6c6963656e7365)](LICENSE)[![Stable](https://camo.githubusercontent.com/60dc937757f61eab90b68209540b776ee7a3b42b2ed003b585ae1c39615b30b8/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f756e69742d636f6e76657273696f6e2f76657273696f6e)](https://packagist.org/packages/laravel-enso/unit-conversion)[![Downloads](https://camo.githubusercontent.com/1d0b77e43a0cbc6842d6ed5b52ecc187e1d5a85daa264589d64a948df87e8d36/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f756e69742d636f6e76657273696f6e2f646f776e6c6f616473)](https://packagist.org/packages/laravel-enso/unit-conversion)[![PHP](https://camo.githubusercontent.com/76d2504e4f304c14866dd7295641dd6812652d93a1848a27fc8e2a08d6732731/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e332532422d3737376262342e737667)](composer.json)[![Issues](https://camo.githubusercontent.com/61b2c646f58ffb756b7f676f850fcd8e10749a777b89e88e922faac0e7c3de40/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c61726176656c2d656e736f2f756e69742d636f6e76657273696f6e2e737667)](https://github.com/laravel-enso/unit-conversion/issues)[![Merge Requests](https://camo.githubusercontent.com/f94ee92d2a438fb35ff8b64bf5048d6e31969ed3343a5fc726cf3f087d881cfe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6c61726176656c2d656e736f2f756e69742d636f6e76657273696f6e2e737667)](https://github.com/laravel-enso/unit-conversion/pulls)

Description
-----------

[](#description)

Unit Conversion provides small, focused services for converting values between related measurement units.

The package organizes conversions by measurement family and supports both object-based and expression-based inputs. It is designed for deterministic numeric conversions such as length, mass, energy, and electrical power.

Internally, each unit declares a label, a symbol, and a conversion factor, while the conversion services discover compatible units automatically from the package structure.

Installation
------------

[](#installation)

Install the package:

```
composer require laravel-enso/unit-conversion
```

No publishing or runtime configuration is required.

Features
--------

[](#features)

- Supports conversion by measurement family through dedicated converter services.
- Supports direct conversion from unit objects.
- Supports conversion from string expressions such as `2 m` or `15 kg`.
- Includes built-in families for length, mass, energy, and power.
- Uses decimal arithmetic helpers for precise multiplication and division.
- Rejects incompatible conversions between different families.
- Validates input expressions and unit symbols before converting.

Usage
-----

[](#usage)

Convert through a converter service:

```
use LaravelEnso\UnitConversion\Length\Length;
use LaravelEnso\UnitConversion\Length\Units\Meter;
use LaravelEnso\UnitConversion\Length\Units\Millimeter;

$result = Length::from(new Meter(2))->to(Millimeter::class);
```

Convert from a string expression:

```
$result = Length::from('2 m')->to(Millimeter::class);
```

Convert directly to a unit class:

```
use LaravelEnso\UnitConversion\Mass\Units\Gram;
use LaravelEnso\UnitConversion\Mass\Units\Kilogram;

$result = Gram::from(new Kilogram(3));
```

You can also convert directly from an expression:

```
$result = Gram::from('3 kg');
```

::: warning Note Expression-based conversions must follow the ` ` format, for example `2 m`, `3 kg`, or `1.5 kcal`.

If the expression is malformed, the symbol is unknown, or the source and destination units belong to different families, the package throws a dedicated exception. :::

API
---

[](#api)

### Converter Services

[](#converter-services)

Available families:

- `LaravelEnso\UnitConversion\Length\Length`
- `LaravelEnso\UnitConversion\Mass\Mass`
- `LaravelEnso\UnitConversion\Energy\Energy`
- `LaravelEnso\UnitConversion\Electricity\Power`

Common entry points:

- `from(Unit|string $from): static`
- `to(string $class): string`

### Units

[](#units)

Every unit class implements:

- `label(): string`
- `symbol(): string`
- `factor(): float`
- `value(): string`
- `from(Unit|string $argument, ?int $precision = 2): string`

Built-in units:

- Length: `Millimeter`, `Centimeter`, `Meter`, `Kilometer`
- Mass: `Gram`, `Kilogram`
- Energy: `Calorie`, `Kilocalorie`, `Joule`
- Power: `Watt`, `KiloWatt`

### Expression Validation

[](#expression-validation)

`LaravelEnso\UnitConversion\Services\Expression`

Expected format:

```

```

Examples:

- `2 m`
- `100 kg`
- `1.5 kcal`

### Exceptions

[](#exceptions)

The package exposes:

- `LaravelEnso\UnitConversion\Exceptions\Unit`
- `LaravelEnso\UnitConversion\Exceptions\Conversion`
- `LaravelEnso\UnitConversion\Exceptions\Expression`

API
---

[](#api-1)

This package exposes its backend integration through the routes, controllers, services, jobs, and configuration points referenced in the usage examples above.

Consumers should rely on the published config keys, documented route groups, and explicit service classes shown in the examples. Internal helper classes, listeners, casts, and background jobs are implementation details unless the README calls them out as extension points.

Depends On
----------

[](#depends-on)

Required Enso packages:

- [`laravel-enso/helpers`](https://docs.laravel-enso.com/backend/helpers.html) [↗](https://github.com/laravel-enso/helpers)

Contributions
-------------

[](#contributions)

are welcome. Pull requests are great, but issues are good too.

Thank you to all the people who already contributed to Enso!

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance87

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~97 days

Recently: every ~2 days

Total

18

Last Release

66d ago

Major Versions

1.5.0 → 2.0.02026-04-09

1.5.1 → 2.0.22026-04-18

PHP version history (3 changes)1.0.0PHP &gt;=8.0

1.3.0PHP ^8.0

2.0.1PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16073274?v=4)[Adrian Ocneanu](/maintainers/aocneanu)[@aocneanu](https://github.com/aocneanu)

---

Top Contributors

[![aocneanu](https://avatars.githubusercontent.com/u/16073274?v=4)](https://github.com/aocneanu "aocneanu (11 commits)")[![gandesc](https://avatars.githubusercontent.com/u/14071925?v=4)](https://github.com/gandesc "gandesc (9 commits)")[![vmcvlad](https://avatars.githubusercontent.com/u/37445394?v=4)](https://github.com/vmcvlad "vmcvlad (4 commits)")[![AbdullahiAbdulkabir](https://avatars.githubusercontent.com/u/33360580?v=4)](https://github.com/AbdullahiAbdulkabir "AbdullahiAbdulkabir (2 commits)")[![GITmanuela](https://avatars.githubusercontent.com/u/44998004?v=4)](https://github.com/GITmanuela "GITmanuela (2 commits)")

---

Tags

unit-conversionlaravel-enso

### Embed Badge

![Health badge](/badges/laravel-enso-unit-conversion/health.svg)

```
[![Health](https://phpackages.com/badges/laravel-enso-unit-conversion/health.svg)](https://phpackages.com/packages/laravel-enso-unit-conversion)
```

###  Alternatives

[laravel-enso/tables

Server-side data tables and export backend for Laravel Enso

63355.1k83](/packages/laravel-enso-tables)[laravel-enso/forms

JSON-based form builder for Laravel Enso

12354.2k84](/packages/laravel-enso-forms)[laravel-enso/data-import

Excel Importer dependency for Laravel Enso

2044.0k6](/packages/laravel-enso-data-import)[laravel-enso/tutorials

Tutorial management backend for Laravel Enso

1140.7k](/packages/laravel-enso-tutorials)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
