搜尋套件、儲存庫與 APP 分類

套件詳情v1.2.1

humanize

Humanize 是一個緊湊的工具包,讓 UI 字串感覺更自然。它透過協助處理日期、數字、清單以及英語和法語文字,將原始資料與人性化的表達之間進行橋接。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1710
喜歡數
33
Pub 分數
145

安裝套件

flutter pub add humanize

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Humanize 是一個輕量級的 Dart 套件,可將原始資料轉換為英文和法文的自然、易讀文字。它提供直覺的輔助工具,用於格式化日期、數字、清單和一般文字,確保使用者介面內容感覺對話且精緻。非常適合需要本地化、使用者友善輸出而無需樣板程式碼的應用程式。該套件支援多種平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,使其在跨平台開發中具有高度彈性。

適用情境

  • 將時間戳格式化為可讀短語
  • 將數字轉換為自然語言
  • 使用 'and' 在最後一個項目前創建用逗號分隔的列表
  • 為英語和法語使用者本地化使用者介面文字
  • 提高應用程式中動態內容的可讀性
  • 簡化表單和儀表板中的字串產生

主要特色

  • 支援英文與法文本地化
  • 日期、數字和清單的輔助工具
  • 具直覺方法的最小 API
  • 跨平台相容性
  • 輕量且無依賴
  • 透過 Flutter pub add 輕鬆整合

適合對象

  • 面向英語和法語用戶的應用
  • 尋求乾淨、易讀的UI字串的開發者
  • 需要簡單文本格式化但不需要大型庫的項目
  • 重視在地化和使用者體驗的團隊
  • 具有動態內容的 Flutter 應用程式顯示
  • 希望設置簡單的前端開發人員

使用建議

  • 僅限英語和法語
  • 不支援其他語言環境
  • 需要手動處理複數等邊緣情況
  • 不適合複雜的國際化需求
  • 依賴於一致的輸入格式
  • 可能需要額外的邏輯來處理非標準用例

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Humanize

pub.dev Star on Github Awesome Flutter Flutter Samples License: MIT

Humanize

Humanize for Dart & Flutter 👋

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.

Table of Contents

Overview

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.

Feature Highlights

  • Relative time and calendar-friendly deltas via naturaltime, naturaldelta, naturalday
  • Flexible formatting for DateTime (ISO, RFC 2822, HTTP, timestamps, locale-aware)
  • Humanized lists and text helpers: naturalJoin, oxfordComma, capfirst, titlecase, truncate*
  • Number utilities with locale presets: intcomma, intword, ordinal, apNumber
  • File size display with filesizeformat
  • Calendar math helpers: addCalendarMonths, addCalendarYears
  • Lightweight i18n facade through HumanizeI18n

Getting Started

Installation

dependencies:
  humanize: latest_version
import 'package:humanize/humanize.dart';

Quick Start

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

Usage Guide

Dates & Times
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...
Numbers
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
Lists, Text & Filesize
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
Calendar Math
final d = DateTime(2017, 2, 13);
print(d.addCalendarMonths(1).toISODate());    // 2017-03-13
print(d.add(Duration(days: 30)).toISODate()); // 2017-03-15
i18n Facade
final hFr = HumanizeI18n('fr');
print(hFr.naturalTime(DateTime.now().subtract(Duration(minutes: 3))));
print(hFr.intComma(1234567)); // 1 234 567

Examples & Tests

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

Notes & Limitations

  • Built-in locales: en, fr. PRs welcome to extend.
  • For strict formatting (currencies, complex calendars), combine with package:intl and use Humanize for human-friendly phrasing.
  • Localized RFC/HTTP outputs are intended for display only (not protocol-compliant).

Resources

  • License: see LICENSE
  • Repo: https://github.com/jeanluc243/humanize
  • Issues: https://github.com/jeanluc243/humanize/issues

Keywords

  • Dart string formatting
  • Flutter localization helpers
  • humanize dates and numbers
  • Dart natural language utilities
  • human-readable UI text toolkit

Maintainers

Support

If 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.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。