quantify 0.2.0
quantify: ^0.2.0 copied to clipboard
A type-safe units of measurement library for Dart, providing elegant syntax for unit conversions with good precision, optimal performance, and configurable output formatting.
example/README.md
Quantify Package - CLI Example #
This directory contains a command-line interface (CLI) example demonstrating the features of the quantify
package.
Features Demonstrated #
The quantify_cli_example.dart
script showcases:
- Creating Quantities:
- Using intuitive
num
extensions (e.g.,1500.m
,2.5.km
).
- Using intuitive
- Unit Conversions:
- Retrieving numerical values in different units (e.g.,
pathA.inKm
). - Converting
Quantity
objects to different units (e.g.,pathA.convertTo(LengthUnit.kilometer)
).
- Retrieving numerical values in different units (e.g.,
- String Formatting (
toString()
):- Default formatting.
- Specifying a
targetUnit
for conversion before formatting. - Controlling the number of
fractionDigits
. - Using a
unitSymbolSeparator
. - Locale-specific number formatting using the
locale
parameter (requires theintl
package). - Using a custom
intl.NumberFormat
instance for advanced control over number display.
- Arithmetic Operations:
- Adding (
+
) and subtracting (-
) quantities (automatic unit conversion for the right-hand operand). - Multiplying (
*
) and dividing (/
) quantities by a scalar. - Specific arithmetic for
Temperature
(e.g., difference).
- Adding (
- Comparisons:
- Using
compareTo()
for magnitude comparison. - Using
==
to check for equality in both value and unit. - Sorting lists of
Quantity
objects.
- Using
- Usage of various implemented quantity types:
- Length
- Time
- Temperature
- Pressure
How to Run #
-
Navigate to the root directory of the
quantify
package. -
Ensure dependencies are fetched:
dart pub get
-
Run the example script from the
example
directory:dart run example/quantify_cli_example.dart
Alternatively, if you are already in the
example
directory:dart run quantify_cli_example.dart
Dependencies #
This example depends on:
- The main
quantify
package (referenced viapath: ../
in itspubspec.yaml
). - The
intl
package for locale-specific number formatting features.