No description
Find a file
Mallne 4c84a04cca Upgrade dependencies and refine Gradle scripts
Updated several dependencies including Kotlin, Ktor, and Maven Publish to newer versions. Improved Gradle scripts by replacing `properties` with `project.findProperty` for enhanced property resolution. Adjusted Gradle wrapper configurations and fixed syntax for better consistency in source set declarations.
2026-07-13 20:23:36 +02:00
gradle Upgrade dependencies and refine Gradle scripts 2026-07-13 20:23:36 +02:00
src/commonMain/kotlin/cloud/mallne/units Remove unused deltaTo function from Angle class 2026-06-01 18:04:06 +02:00
.gitignore Modularize Units Package 2025-09-18 23:51:43 +02:00
AGENTS.md Add Readme and Agents Files 2026-03-19 21:40:11 +01:00
build.gradle.kts Upgrade dependencies and refine Gradle scripts 2026-07-02 15:06:47 +02:00
gradle.properties remove deprecated Property 2026-03-12 16:16:32 +01:00
LICENSE Initial commit 2025-09-18 16:52:07 +02:00
README.md Add Readme and Agents Files 2026-03-19 21:40:11 +01:00
settings.gradle.kts Modularize Units Package 2025-09-18 23:51:43 +02:00

Mallne/Units

Units is a robust, type-safe, and natural-feeling Kotlin Multiplatform library for physical quantities and units of measure.

Kotlin License: MIT Kotlin Multiplatform


🚀 Overview

Handling physical units can be error-prone when using raw numbers. DC-Units eliminates these issues by providing a type-safe system where units are part of the type signature. It's designed to feel like a natural extension of the Kotlin language.

Key Highlights

  • Type Safety: You cannot accidentally add meters to seconds.
  • Natural Syntax: Use operators like * and / to create measures (e.g., 5 * meters).
  • Rich Unit Math: Supports unit products (e.g., Length * Length = Area) and ratios (e.g., Length / Time = Velocity).
  • Multiplatform: Targets JVM, Android, iOS, JS, WasmJS, and Linux.
  • Serialization: Built-in support for kotlinx.serialization.

🛠️ Installation

Add the DiCentra repository and the dependency to your build.gradle.kts:

repositories {
    maven("https://registry.mallne.cloud/repository/DiCentraArtefacts/")
}

dependencies {
    implementation("cloud.mallne:units:1.0.0-SNAPSHOT")
}

📖 Usage Examples

Creating Measures

Creating a measure is as simple as multiplying a number by a unit.

val distance = 500 * meters
val duration = 2 * hours
val weight = 75.5 * kilograms

Conversions

Easily convert between compatible units using the in or as infix functions.

val length = 1 * miles
val inMeters = length in meters    // Returns Double: 1609.344
val asFeet = length `as` feet      // Returns Measure<Length>: 5280.0 ft

Arithmetic

Perform math while maintaining unit integrity.

val speed = (100 * kilometers) / (1 * hours) // Measure<Velocity>
val area = (5 * meters) * (10 * meters)      // Measure<Area>
val totalWeight = (500 * grams) + (1 * kilograms) // Result in grams: 1500.0 g

Formatting

Print measures with their suffixes.

println(5 * meters) // Output: 5.0 m
println((25 * inches).toString(decimals = 1)) // Output: 25.0 in

📏 Supported Unit Categories

DC-Units provides comprehensive support for a wide range of measurements:

  • Length & Area: meters, kilometers, miles, inches, feet, hectares, etc.
  • Time: seconds, minutes, hours, days.
  • Mass: grams, kilograms, pounds, ounces, tons.
  • Volume: liters, milliliters, gallons, cubicMeters.
  • Environment: Temperature, Pressure, Humidity.
  • Computing: BinarySize (bytes, KB, MB, GB, etc.).
  • And more: Angle, Work, Probability, GraphicsLength.

🤝 Contributing

Contributions are welcome! Whether it's adding new units, fixing bugs, or improving documentation, feel free to submit a pull request.


📄 License

This project is licensed under the MIT License. See the LICENSE file for details.