Have you ever wanted to convert large numbers into concise, human-readable formats in your JavaScript projects? Say hello to Aveta—a lightweight library that makes formatting numbers effortless!
Aveta helps you turn clunky numbers into simple, human-readable formats like 10K, 1.2M, or 3.45B. It's perfect for dashboards, charts, and anywhere clean data presentation is essential.
|
Output |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
6000 | '6K' | ||||||||||
10000 | '10K' | ||||||||||
42500 | '42.5K' | ||||||||||
1250000 | '1.25M' |
Installation
# With npm npm install aveta # With Yarn yarn add aveta
How to Use Aveta
import aveta from 'aveta'; console.log(aveta(8700)); // '8.7K'
Advanced Options
import aveta from 'aveta'; // Customize digits and lowercase units console.log( aveta(123456, { digits: 3, lowercase: true, }) ); // '123k' // Adjust precision and add a separator console.log( aveta(2048000, { precision: 2, separator: ',', }) ); // '2,048M' // Use custom units console.log( aveta(1440000, { units: ['B', 'KB', 'MB', 'GB', 'TB'], space: true, }) ); // '1.44 MB'
Reverse Formatting with AvetaReverse
import { avetaReverse } from 'aveta'; console.log(avetaReverse('8.7K')); // 8700 console.log(avetaReverse('4.57k')); // 4570 console.log(avetaReverse('2.48m')); // 2480000
Command-Line Interface
$ aveta 234000 234K # Or use npx $ npx aveta 1234567 1.23M
aveta --help
Both forward and reverse formatting options.
This library is crafted with ❤️ by Me.
The above is the detailed content of Simplify Numbers with Aveta: A Handy JavaScript Library. For more information, please follow other related articles on the PHP Chinese website!