Human Readable Formats
A comprehensive pure Dart package to format raw data into human-readable text. From basic numbers and dates to advanced scientific notation, geographic coordinates, network data, and complex data structures - this package provides 60+ specialized formatting functions. Platform-independent with no Flutter dependencies.
Brought to you by SDKWala
This project is an open-source initiative by SDKWala, a company dedicated to creating high-quality, developer-friendly SDKs and open-source projects.
- Website: www.sdkwala.com
- GitHub: https://github.com/sdkwala
Features
π Core Data Formatting
- Numbers: Format numbers with localization, ordinals, compact notation (e.g., "1.2K", "3rd", "1,234.56")
- File Sizes: Format bytes with SI/IEC standards (e.g., "1.5 MB", "2.3 GiB")
- Durations: Format time spans in multiple styles (e.g., "2h 30m", "2 hours and 30 minutes")
- Dates & Times: Friendly date formatting (e.g., "Today at 3:45 PM", "2 days ago")
- Percentages & Ratios: Format numbers as percentages or ratios (e.g., "75%", "3 out of 4")
- Currencies: Format monetary values with proper symbols and localization
π Network & Technical
- Network Data: Bandwidth, latency, data rates, IP addresses, MAC addresses, URLs
- Protocols: HTTP status codes, network protocols, DNS records, SSL certificates
- Performance: Speed tests, packet loss, signal strength, WiFi channels
πΊοΈ Geographic & Mapping
- Coordinates: Decimal degrees, DMS, UTM, What3Words formatting
- Distances & Areas: Smart unit conversion (km/mi, mΒ²/ftΒ², etc.)
- Elevations: Height formatting with appropriate units
- Navigation: Bearings, magnetic declination, GPS accuracy
- Locations: Addresses, bounding boxes, timezones, regions
π¬ Scientific & Technical
- Scientific Notation: Unicode exponents and engineering notation
- Physical Units: Energy, power, voltage, current, resistance, capacitance
- Chemistry: Chemical formulas with proper subscripts (HβO, CβHββOβ)
- Physics: Wavelengths, frequencies, temperatures, pressures
- Mathematics: Mathematical expressions with superscripts and subscripts
π Data Structures
- Structured Data: JSON, XML, CSV with proper formatting and alignment
- Tables: ASCII/Unicode tables with borders and indexing
- Trees & Hierarchies: Visual tree structures and hierarchical data
- Lists & Matrices: Formatted lists (bullet/numbered) and 2D arrays
π Localization & Configuration
- Multi-language: Built-in English and Spanish support
- Global Configuration: Set defaults for locale, decimal places, and standards
- Fluent API: Chainable builder pattern for complex formatting
Installation
Add this to your package's pubspec.yaml file:
dependencies:
human_readable_formats: ^0.1.0 # Check for the latest version
Then, run dart pub get.
Quick Start
import 'package:human_readable_formats/human_readable_formats.dart';
void main() {
// Format file sizes
print(humanizeFileSize(1572864)); // "1.5 MiB"
// Format durations
print(humanizeDuration(const Duration(hours: 2, minutes: 30))); // "2h 30m"
// Format friendly dates
final now = DateTime.now();
print(humanizeFriendlyDate(now)); // "Today"
// Format percentages
print(humanizePercentage(0.75)); // "75%"
// Format ratios
print(humanizeRatio(3, 4)); // "3 out of 4"
}
Comprehensive Usage
Core Data Formatting
Numbers & File Sizes
import 'package:human_readable_formats/human_readable_formats.dart';
// Numbers
print(humanizeNumber(1234567)); // "1,234,567"
print(humanizeCompactNumber(1234567)); // "1.2M"
print(humanizeOrdinal(3)); // "3rd"
// File Sizes
print(humanizeFileSize(1536)); // "1.5 KB"
print(humanizeFileSize(1073741824)); // "1.0 GB"
print(humanizeFileSize(1073741824, standard: FileSizeStandard.iec)); // "1.0 GiB"
Durations & Dates
// Durations
print(humanizeDuration(Duration(hours: 2, minutes: 30))); // "2h 30m"
print(humanizeDuration(Duration(hours: 2, minutes: 30), style: DurationStyle.long)); // "2 hours and 30 minutes"
// Friendly Dates
print(humanizeFriendlyDate(DateTime.now())); // "Today at 3:45 PM"
print(humanizeFriendlyDate(DateTime.now().subtract(Duration(hours: 2)), style: FriendlyDateStyle.relative)); // "2 hours ago"
Percentages & Currencies
// Percentages & Ratios
print(humanizePercentage(0.75)); // "75%"
print(humanizeRatio(3, 4)); // "3 out of 4"
// Currencies
print(humanizeCurrency(1234.56, 'USD')); // "$1,234.56"
print(humanizeCurrency(1234.56, 'EUR')); // "β¬1,234.56"
Network & Technical Formatting
// Network Data
print(humanizeBandwidth(1048576)); // "1.0 Mbps"
print(humanizeLatency(45)); // "45 ms"
print(humanizeDataRate(1073741824)); // "1.0 GB/s"
// IP Addresses & URLs
print(humanizeIPAddress('192.168.1.1')); // "192.168.1.1 (Private)"
print(humanizeMACAddress('00:1B:44:11:3A:B7')); // "00:1B:44:11:3A:B7 (Dell Inc.)"
print(humanizeURL('https://api.example.com/v1/users?page=1')); // "api.example.com/v1/users"
// Network Performance
print(humanizeSpeedTest(downloadSpeed: 50000000, uploadSpeed: 10000000, ping: 25));
// "Download: 50.0 Mbps, Upload: 10.0 Mbps, Ping: 25 ms"
print(humanizeSignalStrength(-65)); // "Good (-65 dBm)"
print(humanizeWiFiChannel(6)); // "Channel 6 (2.437 GHz)"
Geographic & Mapping
// Coordinates
print(humanizeCoordinates(40.7128, -74.0060)); // "40.7128Β°N, 74.0060Β°W"
print(humanizeCoordinatesDMS(40.7128, -74.0060)); // "40Β°42'46\"N, 74Β°0'22\"W"
// Distances & Areas
print(humanizeDistance(1500)); // "1.5 km"
print(humanizeDistance(500, unit: DistanceUnit.feet)); // "1,640 ft"
print(humanizeArea(1000000)); // "1.0 kmΒ²"
// Navigation & Location
print(humanizeBearing(45.5)); // "45.5Β° NE"
print(humanizeElevation(1500)); // "1,500 m"
print(humanizeTimezone('America/New_York')); // "Eastern Time (UTC-5)"
Scientific & Technical
// Scientific Notation
print(humanizeScientificNotation(1234.5)); // "1.235 Γ 10Β³"
print(humanizeEngineeringNotation(1234500)); // "1.235 Γ 10βΆ"
// Chemistry & Physics
print(humanizeChemicalFormula('H2O')); // "HβO"
print(humanizeChemicalFormula('C6H12O6')); // "CβHββOβ"
print(humanizeMathExpression('x^2 + y^2 = z^2')); // "xΒ² + yΒ² = zΒ²"
// Physical Units
print(humanizeEnergy(1000)); // "1.0 kJ"
print(humanizePower(1500)); // "1.5 kW"
print(humanizeTemperature(273.15)); // "273.1 K"
print(humanizePressure(101325)); // "101.33 kPa"
print(humanizeWavelength(550e-9)); // "550 nm"
Data Structures
// JSON & XML
Map<String, dynamic> data = {'name': 'John', 'age': 30, 'city': 'NYC'};
print(humanizeJSON(data));
// {
// "name": "John",
// "age": 30,
// "city": "NYC"
// }
// Tables
List<List<String>> tableData = [
['Name', 'Age', 'City'],
['John', '30', 'NYC'],
['Jane', '25', 'LA']
];
print(humanizeTable(tableData));
// ββββββββ¬ββββββ¬ββββββ
// β Name β Age β Cityβ
// ββββββββΌββββββΌββββββ€
// β John β 30 β NYC β
// β Jane β 25 β LA β
// ββββββββ΄ββββββ΄ββββββ
// Trees & Hierarchies
Map<String, dynamic> tree = {
'root': {
'child1': {},
'child2': {'grandchild': {}}
}
};
print(humanizeTree(tree));
// βββ root
// βββ child1
// βββ child2
// βββ grandchild
// Lists & Matrices
print(humanizeListStructure(['item1', 'item2', 'item3'], style: ListStyle.bullet));
// β’ item1
// β’ item2
// β’ item3
List<List<int>> matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
print(humanizeMatrix(matrix));
// [1, 2, 3]
// [4, 5, 6]
// [7, 8, 9]
Global Configuration
Set default values that apply throughout your app:
void main() {
// Set global defaults
HumanReadableConfig.instance
..locale = 'es' // Default to Spanish
..decimalPlaces = 2
..fileSizeStandard = FileSizeStandard.si;
// Now all formatting functions will use these defaults
print(humanizeFileSize(1000)); // "1.00 KB" (SI units)
print(humanizePercentage(0.5)); // "50.00%"
}
Migration Guide
From v0.0.x to v0.1.0
The package has been significantly updated with new features and improvements. Here are the key changes:
-
New Features:
- Added file size formatting with support for SI and IEC standards
- Added duration formatting with short and long styles
- Added friendly date formatting
- Added percentage and ratio formatting
- Added localization support (English and Spanish)
- Added global configuration
- Added fluent builder API
-
Breaking Changes:
- Removed Flutter widget dependencies (now pure Dart)
- Moved to using
FileSizeStandardenum instead of boolean flags - Changed default decimal places behavior to be more intuitive
-
Migration Steps:
- Update your imports if you were using Flutter-specific widgets
- If you were using custom formatting, update to use the new builder API
- Test your app thoroughly as the behavior of some formatters may have changed slightly
API Reference
Core Data Functions
Numbers
humanizeNumber(num value, {String? locale})- Format numbers with localizationhumanizeCompactNumber(num value, {int? decimalPlaces, String? locale})- Compact notation (1.2K, 3.4M)humanizeOrdinal(int number, {String? locale})- Ordinal numbers (1st, 2nd, 3rd)
File Sizes
humanizeFileSize(int bytes, {int? decimalPlaces, FileSizeStandard? standard, String? locale})FileSizeFormatterclass with fluent API
Durations & Dates
humanizeDuration(Duration duration, {DurationStyle? style, int? maxUnits, String? locale})humanizeFriendlyDate(DateTime date, {FriendlyDateStyle? style, TimeFormat? timeFormat, String? locale})DurationFormatterandFriendlyDateFormatterclasses with fluent APIs
Percentages & Currencies
humanizePercentage(double value, {int? decimalPlaces, String? symbol, String? locale})humanizeRatio(int numerator, int denominator, {RatioStyle? style, String? locale})humanizeCurrency(double amount, String currencyCode, {int? decimalPlaces, String? locale})
Network & Technical Functions
Network Data
humanizeBandwidth(int bitsPerSecond, {int? decimalPlaces})- Format bandwidthhumanizeLatency(int milliseconds)- Format network latencyhumanizeDataRate(int bytesPerSecond, {int? decimalPlaces})- Format data transfer rateshumanizePacketLoss(double percentage)- Format packet loss percentage
Network Addresses
humanizeIPAddress(String ipAddress)- Format IP addresses with type detectionhumanizeMACAddress(String macAddress)- Format MAC addresses with vendor lookuphumanizeURL(String url, {bool showProtocol = false})- Clean URL formatting
Network Performance
humanizeSpeedTest({required int downloadSpeed, required int uploadSpeed, required int ping})humanizeSignalStrength(int dbm)- WiFi/cellular signal strengthhumanizeWiFiChannel(int channel)- WiFi channel with frequency
Geographic Functions
Coordinates
humanizeCoordinates(double latitude, double longitude, {int? precision})humanizeCoordinatesDMS(double latitude, double longitude)- Degrees, Minutes, SecondshumanizeUTMCoordinates(double easting, double northing, int zone, String band)humanizeWhat3Words(String words)- What3Words address formatting
Distances & Areas
humanizeDistance(double meters, {DistanceUnit? unit, int? decimalPlaces})humanizeArea(double squareMeters, {AreaUnit? unit, int? decimalPlaces})humanizeElevation(double meters, {ElevationUnit? unit})
Navigation & Location
humanizeBearing(double degrees)- Compass bearing with directionhumanizeGPSAccuracy(double meters)- GPS accuracy descriptionhumanizeTimezone(String timezone)- Timezone with UTC offsethumanizeAddress(Map<String, String> components)- Structured address formatting
Scientific Functions
Scientific Notation
humanizeScientificNotation(double value, {int? precision})- Unicode scientific notationhumanizeEngineeringNotation(double value, {int? precision})- Engineering notationhumanizePhysicalConstant(String constant)- Physical constants with proper formatting
Chemistry & Physics
humanizeChemicalFormula(String formula)- Chemical formulas with subscriptshumanizeMathExpression(String expression)- Math expressions with super/subscriptshumanizeWavelength(double meters)- Wavelength with appropriate unitshumanizeFrequency(double hertz)- Frequency with appropriate units
Physical Units
humanizeEnergy(double joules, {EnergyUnit? unit})- Energy formattinghumanizePower(double watts, {PowerUnit? unit})- Power formattinghumanizeVoltage(double volts)- Voltage formattinghumanizeCurrent(double amperes)- Current formattinghumanizeResistance(double ohms)- Resistance formattinghumanizeCapacitance(double farads)- Capacitance formattinghumanizeTemperature(double kelvin, {TemperatureUnit? unit})- Temperature formattinghumanizePressure(double pascals, {PressureUnit? unit})- Pressure formatting
Data Structure Functions
Structured Data
humanizeJSON(dynamic data, {int? indent, bool sortKeys = false})- Pretty JSON formattinghumanizeXML(String xml, {int? indent})- Pretty XML formattinghumanizeCSV(List<List<String>> data, {String delimiter = ','})- CSV formatting
Tables & Lists
humanizeTable(List<List<String>> data, {TableStyle? style, bool showIndex = false})humanizeListStructure(List<dynamic> list, {ListStyle? style, bool allowNesting = true})humanizeKeyValuePairs(Map<String, dynamic> data, {String separator = ': '})
Trees & Hierarchies
humanizeTree(Map<String, dynamic> tree, {TreeStyle? style})- Visual tree structureshumanizeHierarchy(Map<String, dynamic> hierarchy, {int maxDepth = 5})humanizeMatrix(List<List<dynamic>> matrix, {MatrixStyle? style})
Enums & Configuration
Standards & Units
FileSizeStandard:si,iecDistanceUnit:meters,kilometers,feet,miles,nauticalMilesAreaUnit:squareMeters,squareKilometers,squareFeet,acresTemperatureUnit:kelvin,celsius,fahrenheitPressureUnit:pascals,kilopascals,atmospheres,bars
Styles & Formats
DurationStyle:short,long,compactFriendlyDateStyle:friendly,relativeListStyle:bullet,numbered,dashTableStyle:ascii,unicode,minimalTreeStyle:unicode,ascii
Builder API
Use the HumanFormatter class for a fluent API:
final formatted = HumanFormatter()
..locale('es')
..decimalPlaces(2)
.humanizeFileSize(1572864);
Localization
The package includes built-in support for English (default) and Spanish. To add support for additional languages, you can implement the HumanReadableLocalizations interface.
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Libraries
- human_readable_formats
- Main entry point for the human_readable_formats library.