Compute weighted averages from the command line. Zero dependencies.
npm i -g @kszongic/weighted-avg-cli# From arguments (value:weight pairs)
weighted-avg 90:3 80:2 70:1
# => 83.33333333333333
# With precision
weighted-avg -p 2 90:3 80:2 70:1
# => 83.33
# Custom delimiter
weighted-avg -d , 90,3 80,2 70,1
# => 83.33333333333333
# From stdin
echo -e "90:3\n80:2\n70:1" | weighted-avg
# => 83.33333333333333
# Pipe from a file
cat grades.txt | weighted-avg -p 1- GPA calculation:
weighted-avg 4.0:3 3.7:4 3.3:3 - Portfolio returns:
weighted-avg 0.12:50000 0.08:30000 -0.02:20000 - Sensor fusion: combine readings with confidence weights
| Flag | Description |
|---|---|
-p, --precision <n> |
Decimal places (default: auto) |
-d, --delimiter <d> |
Value/weight separator (default: :) |
-h, --help |
Show help |
-v, --version |
Show version |
MIT © 2026 kszongic