humanize
Humanize는 UI 문자열이 자연스럽게 느껴지도록 도와주는 컴팩트한 툴킷입니다. 영어와 프랑스어로 된 날짜, 숫자, 목록 및 텍스트를 위한 보조 기능을 통해 원시 데이터와 인간 친화적인 표현 사이를 연결합니다.
숫자와 날짜를 인간이 읽기 쉬운 형식으로 변환하는 Dart 및 Flutter 패키지입니다.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Humanize
pub.dev Star on Github Awesome Flutter Flutter Samples License: MIT
Humanize is a compact toolkit that makes UI strings feel natural. It bridges raw data and human-friendly phrasing with helpers for dates, numbers, lists, and text in English and French.
Humanize focuses on pragmatic, readable output for UI strings. It packages natural phrases (e.g., “3 minutes ago”, “tomorrow”) and formatting helpers under a consistent API with light-touch locale support.
naturaltime, naturaldelta, naturaldayDateTime (ISO, RFC 2822, HTTP, timestamps, locale-aware)naturalJoin, oxfordComma, capfirst, titlecase, truncate*intcomma, intword, ordinal, apNumberfilesizeformataddCalendarMonths, addCalendarYearsHumanizeI18ndependencies:
humanize: latest_version
import 'package:humanize/humanize.dart';
print(naturaltime(DateTime.now().subtract(Duration(minutes: 3)), locale: 'en')); // 3 minutes ago
print(naturaldelta(Duration(hours: 2), locale: 'fr')); // 2 heures
final ref = DateTime(2007, 2, 17, 12);
print(naturalday(DateTime(2007, 2, 16), now: ref, locale: 'en', format: 'dd MMMM yyyy')); // yesterday
print(naturalJoin(['a','b','c'], locale: 'fr')); // a, b et c
print(oxfordComma(['a','b','c'], locale: 'en')); // a, b, and c
print(intcomma(4500.2)); // 4,500.2
print(intcomma(1234567, sep: ' ')); // 1 234 567
print(intword(1200000, locale: 'fr')); // 1,2 millions
print(filesizeformat(1536)); // 1.5 KB
final now = DateTime(2007, 2, 17, 16, 30, 0);
print(naturaltime(now.add(Duration(days: 9)), now: now)); // in 1 week, 2 days
print(naturaltime(now.subtract(Duration(days: 1, hours: 2)), now: now, locale: 'fr')); // il y a un jour, 2 heures
final dt = DateTime(2017,4,20,11,32);
print(dt.toISO()); // 2017-04-20T11:32:00.000-04:00
print(dt.toRFC2822()); // Thu, 20 Apr 2017 11:32:00 -0400
print(dt.toHTTP()); // Thu, 20 Apr 2017 15:32:00 GMT
print(dt.asLocale('fr').toHTTP()); // jeu., 20 avr. 2017 15:32:00 GMT (display)
// Locale formats
print(dt.toLocaleString()); // e.g., 4/20/2017
print(dt.toLocaleString(HumanDateFormat.DATETIME_FULL)); // April 20, 2017...
print(dt.asLocale('fr').toLocaleString(HumanDateFormat.DATETIME_FULL)); // 20 avril 2017...
print(intcomma(4500)); // 4,500
print(intword(1500000, short: true)); // 1.5 M
print(ordinal(1, locale: 'fr')); // 1er
print(apNumber(5, locale: 'fr')); // cinq
print(naturalJoin(['a','b','c'], locale: 'fr')); // a, b et c
print(oxfordComma(['a','b','c'])); // a, b, and c
print(capfirst('hello')); // Hello
print(filesizeformat(1536)); // 1.5 KB
final d = DateTime(2017, 2, 13);
print(d.addCalendarMonths(1).toISODate()); // 2017-03-13
print(d.add(Duration(days: 30)).toISODate()); // 2017-03-15
final hFr = HumanizeI18n('fr');
print(hFr.naturalTime(DateTime.now().subtract(Duration(minutes: 3))));
print(hFr.intComma(1234567)); // 1 234 567
Examples in example/: basic_usage.dart, i18n_facade.dart, intcomma_examples.dart, naturaltime_examples.dart, naturalday_examples.dart, ordinal_examples.dart, formatting_examples.dart, math_examples.dart
Run tests:
dart test
en, fr. PRs welcome to extend.package:intl and use Humanize for human-friendly phrasing.LICENSEIf Humanize makes your UI sparkle, feel free to fuel the magic with a donation—anything from a cheeky 🍺 to the legendary MacBook Pro upgrade 💻😂. Tap the link, pick your vibe, and let's keep shipping joy: Buy Me a Coffee.