human_readable_formats 0.0.1 copy "human_readable_formats: ^0.0.1" to clipboard
human_readable_formats: ^0.0.1 copied to clipboard

Pure Dart package to format raw data (numbers, dates, file sizes, etc.) into human-readable text. Platform-independent, no Flutter dependency.

Human Readable Formats #

A pure all in one Dart package to format raw data like numbers, dates, and file sizes into human-readable text. This package is platform-independent and has no dependency on Flutter, making it suitable for any Dart project.

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.

Features #

  • Relative Time: Format DateTime as a relative time string (e.g., "5 minutes ago").
  • Compact Numbers: Format large numbers into a compact form (e.g., "1.23M").
  • Ordinals: Convert integers to ordinal strings (e.g., "2nd", "3rd").
  • Currency: Format numbers as currency with customizable symbols (e.g., "₹99").
  • Booleans: Convert booleans to human-readable strings (e.g., "Yes", "No").
  • Lists: Format lists into a human-readable enumeration (e.g., "apples, bananas, and oranges").

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  human_readable_formats: ^0.0.1 # Replace with the latest version

Then, run dart pub get.

Usage #

import 'package:human_readable_formats/humanize.dart';

void main() {
  // Relative time
  final fiveMinutesAgo = DateTime.now().subtract(const Duration(minutes: 5));
  print(humanizeRelativeTime(fiveMinutesAgo)); // "5 minutes ago"

  // Compact numbers
  print(humanizeCompactNumber(1234567)); // "1.23M"

  // Ordinals
  print(humanizeOrdinal(21)); // "21st"

  // Currency
  print(humanizeCurrency(99, symbol: '\$')); // "$99"

  // Booleans
  print(humanizeBoolean(true, positive: 'Active', negative: 'Inactive')); // "Active"

  // Lists
  print(humanizeList(['apples', 'bananas', 'oranges'])); // "apples, bananas, and oranges"
}

API Reference #

  • humanizeRelativeTime(DateTime dateTime, {DateTime? now}): Formats a DateTime into a relative time string.
  • humanizeCompactNumber(num number, {String? locale}): Formats a number into a compact form.
  • humanizeOrdinal(int number): Converts an integer to its ordinal representation.
  • humanizeCurrency(num amount, {String symbol = '₹', String? locale}): Formats a number as currency.
  • humanizeBoolean(bool? value, {String positive = 'Yes', String negative = 'No', String? nullValue}): Converts a boolean to a human-readable string.
  • humanizeList(List<String> items, {String conjunction = 'and', bool oxfordComma = true}): Formats a list into a human-readable enumeration.

Contributing #

Contributions are welcome! If you have a feature request, bug report, or want to contribute to the code, please feel free to open an issue or submit a pull request on our GitHub repository.

License #

This project is licensed under the MIT License. See the LICENSE file for details.

1
likes
0
points
13
downloads

Publisher

verified publishersdkwala.com

Weekly Downloads

Pure Dart package to format raw data (numbers, dates, file sizes, etc.) into human-readable text. Platform-independent, no Flutter dependency.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

intl

More

Packages that depend on human_readable_formats