Download the PHP package kolaybi/unit-converter without Composer

On this page you can find all versions of the php package kolaybi/unit-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package unit-converter

Unit Converter

A PHP 8.4+ framework-agnostic package for converting between 2,216 units of measurement based on UN/CEFACT Recommendation 20, Recommendation 21 (package types), and the GS1 unit conversion model.

Uses arbitrary-precision math (bcmath) with the GS1 multiplier + offset formula to handle both linear conversions (mass, length, volume, etc.) and non-linear ones (temperature).

Requirements

Installation

Quick Start

API

Converter::convert(int|float|string $value = 1): PendingConversion

Entry point. Accepts any numeric value. Defaults to 1, useful for looking up conversion factors.

PendingConversion::from(Unit|string $unit): self

Set the source unit. Accepts an enum case, UN/CEFACT code, symbol, or label.

PendingConversion::to(Unit|string $unit): ConversionResult

Convert to the target unit and return the result.

Converter::unit(string $input): Unit

Resolve a unit by UN/CEFACT code, symbol, or label. Returns the Unit enum case.

PendingConversion::toAll(): array<string, string>

Convert to all other units in the same category. Returns an array keyed by UN/CEFACT code.

ConversionResult

Unit Categories

58 categories covering 2,216 units (780 convertible + 1,436 non-convertible):

Category Units Category Units
Absorbed Dose 4 Kinematic Viscosity 7
Absorbed Dose Rate 11 Length 34
Acceleration 11 Luminous Intensity 3
Amount of Substance 4 Magnetic Flux 3
Angle 9 Magnetic Flux Density 6
Angular Impulse 3 Magnetic Vector Potential 3
Angular Velocity 4 Mass 34
Area 20 Memory Capacity 15
Capacitance 7 Molar Concentration 5
Charge 13 Molar Mass 2
Conductance 7 Molar Thermodynamic Energy 2
Counting 14 Molar Volume 4
Current 9 Package Type ⊘ 406
Data Rate 12 Packaging ⊘ 52
Density 28 Power 44
Dimensionless Concentration 24 Pressure 42
Dynamic Viscosity 19 Radioactivity 9
Effective Dose 4 Resistance 8
Effective Dose Rate 13 Signal Rate 3
Energy 34 Specific Volume 7
Energy Density 7 Speed 23
Exposure 2 Temperature 4
Flow Rate 93 Textile Density 3
Force 15 Time 18
Frequency 10 Torque 16
Illuminance 6 Trade ⊘ 978
Impulse 6 Voltage 6
Inductance 6 Volume 66
Irradiance 14 Wavenumber 4

⊘ = non-convertible (code resolution only)

Package Types (Rec 21)

406 package types from UNECE Recommendation 21 (Rev. 12) are available via the PackageType enum.

Per Rec 20 guidance, each 2-character Rec 21 code is prefixed with X to form a 3-character unit-of-measure code (reserved range X00–XZZ). The native Rec 21 code is also available as an alias.

Resolution priority: When a Rec 21 native code conflicts with a Rec 20 code (23 shared codes like BG, DR, TU), Rec 20 takes priority. Use the X-prefixed code to explicitly target the Rec 21 entry.

Unit Resolution

Units can be resolved by:

Error Handling

How It Works

All convertible units use the GS1 multiplier + offset model relative to a base unit per category:

For most categories (mass, length, volume, etc.), the offset is 0, making it a simple ratio. Temperature uses non-zero offsets to handle Celsius (offset 273.15) and Fahrenheit (multiplier 5/9, offset 255.37).

All math uses bcmath with a scale of 20 decimal places.

Code Generation

The convertible unit enums are generated from the GS1 datatable:

Development

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

Please see License File for more information.


All versions of unit-converter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-bcmath Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kolaybi/unit-converter contains the following files

Loading the files please wait ...