energizr 1.0.0 energizr: ^1.0.0 copied to clipboard
Energizr -- Energy for The Visionary Software Solutions Measurement & me_sure_meant API
Visionary Software Solutions Measurement API: fluent, joyful measurement...FOR SCIENCE! #
Meant to fight the odious practice witnessed in many code bases of using only integers/doubles for measurements/units and "knowing contextually" that a number corresponds to a measurement in joules... (which may be converted in the body of a method).
The goal of this API is to enable code written about measurements to be clear, expressive, and straightforward to reason about and understand by baking behaviors (such as well known conversion factors and arithmetic) directly into types.
Features #
- Builds on me_sure_meant, providing support for common
Energy
. - Common SI units.
- Fluent definition, unit conversion, and addition/subtraction.
- Uncertainty in measurement with propagation through calculations.
- Framework pieces to easily extend and evolve, replacing implementations or adding new features
- Full SI prefix support for all your yottajoule and quectjoule needs
- Extension Methods to make defining a quantity as easy as writing
250.kiloCalories() + 25.kiloCalories()
First Class (No, really, they're dedicated classes!) support for measurements in Energy: #
- SI :
Joules
andKiloCalories
Getting started #
Dependency: me_sure_meant library. It should work in any Dart 3+ runtime environment.
Usage #
Check out the demos in example/energizr_example.dart
Here's a teaser #
final calories = 250.kiloCalories();
var added = calories + 25.kiloCalories();
/// + supported
assert(added.magnitude.toNum() == 275);
assert(added.unit == Calorie.kilocalorie);
/// Objects are immutable: calculations yield new objects.
assert(calories.magnitude.toNum() == 250);
assert(calories.unit == Calorie.kilocalorie);
/// - supported
var subtracted = calories - 100.kiloCalories();
assert(subtracted.magnitude.toNum() == 150);
assert(subtracted.unit == Calorie.kilocalorie);
/// Unit conversion between units of same type (e.g. [Energy])
var asKJ = calories.toUnit(Joule.kilojoule);
assert(asKJ.magnitude.toNum() == 1046);
assert(asKJ.unit == Joule.kilojoule);
Additional information #
This package is Free and Open Source Software by Visionary Software Solutions. Alternative licensing is available, on a sliding scale case-by-case basis. (Contact nico at visionary.software)