You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UnitMath is a small Rust library and dependency-free CLI for unit conversions, parsing, and package math.
3
+
UnitMath is a small Rust library and dependency-free CLI for unit conversions, parsing, and package math. The library focuses on core typed conversions and parsers; the CLI adds convenient one-shot commands, package math commands, and batch processing for CSV and JSON Lines data.
4
4
5
-
Version 1.4.0 is focused on:
5
+
## Current Scope
6
6
7
-
- Weight conversions
8
-
- US liquid volume conversions
9
-
- Potency conversions
7
+
UnitMath currently supports:
8
+
9
+
- Weight conversions and parsing
10
+
- US liquid volume conversions and parsing
11
+
- Potency conversions and parsing
10
12
- Simple package math helpers
11
-
- Basic string parsing for weight, volume, and potency quantities
12
-
- Parsed conversion helpers
13
-
- A minimal CLI
14
-
- Optional JSON CLI output
15
-
- Optional CSV CLI output
16
-
- Universal CLI conversion with category inference
17
-
- Batch CSV input mode with CSV or JSON Lines output
13
+
- One-shot CLI conversion commands
14
+
- Batch CLI processing from CSV, JSON Lines, files, and stdin
15
+
- Machine-readable CLI output as JSON, CSV-style rows, JSON Lines, or JSON arrays
18
16
19
-
UnitMath intentionally does not include universal library conversion, package parsing, or trait-based quantity abstractions yet.
17
+
UnitMath intentionally keeps the public library API focused and lightweight. Higher-level features such as universal conversion, package expression parsing, batch processing, CSV/JSON formatting, and input-format handling are currently CLI-layer features, while trait-based quantity abstractions are intentionally deferred.
Parsing trims whitespace, is case-insensitive, and returns `UnitMathError` for empty input, missing numbers, invalid numbers, missing units, and unknown units.
Package helpers only multiply counts by per-unit quantities. They do not parse package strings or perform unit conversion.
139
-
140
-
## CLI Usage
99
+
## CLI Examples
141
100
142
101
Default CLI output is numeric-only:
143
102
@@ -153,90 +112,199 @@ unitmath convert "1 gallon" ml
153
112
unitmath convert "22.4%" mg/g
154
113
```
155
114
156
-
Add `--json` at the end to emit structured output:
115
+
Package CLI commands perform simple multiplication without unit conversion:
157
116
158
117
```sh
159
-
unitmath weight "3.5g" oz --json
160
-
unitmath volume "8 fl oz" cup --json
161
-
unitmath potency "22.4%" mg/g --json
162
-
unitmath convert "3.5g" oz --json
118
+
unitmath package total-units "2 x 12"
119
+
unitmath package total-units "2,12"
120
+
unitmath package total-quantity "10 x 3.5"
121
+
unitmath package total-quantity "24 * 100" mg
163
122
```
164
123
165
-
Example JSON output:
124
+
Add `--precision <digits>` to format output values with exactly that many digits after the decimal point. Precision supports values from `0` through `12` and affects output formatting only:
CSV-style output uses commas by default. Use `--delimiter comma`, `--delimiter tab`, or `--delimiter pipe` with `--csv` to choose the output separator. Delimiter control affects output only; batch CSV input remains comma-separated.
182
+
183
+
## Batch Examples
184
+
185
+
Batch CSV input uses these headers:
194
186
195
187
```csv
196
188
category,input,target_unit
197
189
weight,1000mg,g
198
190
volume,1 gallon,ml
199
191
potency,22.4%,mg/g
200
192
convert,8 fl oz,cup
193
+
total_units,2 x 12,units
194
+
total_quantity,24 * 100,mg
201
195
```
202
196
203
-
Supported batch categories are `weight`, `volume`, `potency`, and `convert`. Surrounding whitespace in header names and category values is ignored.
197
+
Supported batch categories are `weight`, `volume`, `potency`, `convert`, `total_units`, and `total_quantity`. Surrounding whitespace in header names and category values is ignored. Package rows do simple multiplication without unit conversion; `target_unit` is preserved as an output label.
204
198
205
-
Batch mode requires an explicit output format:
199
+
JSON Lines batch input uses one flat object per non-empty line with string fields for `category`, `input`, and `target_unit`:
Rows with conversion errors are included in batch output with `status` set to `error`; batch processing continues after row-level failures. Use filters and summaries to triage mixed-quality files:
0 commit comments