$ show Humanizr/Humanizer
Humanizer is a .NET library that provides a comprehensive set of extension methods for converting raw data types (numbers, dates, times, byte sizes, strings, enums, collections) into human-readable, localized text. It supports over 90 locales with full pluralization, ordinalization, inflection, and parsing of number words back to numeric values. The library is designed as a reusable dependency for applications requiring user-friendly formatting. Architecturally, Humanizer follows a strategy/registry pattern: each formatting domain (number-to-words, date humanization, ordinalization, etc.) defines an interface and a default implementation, with locale-specific overrides resolved through a central Configurator. Locale data is defined in YAML files and compiled at build time by a Roslyn source generator into immutable profile classes, keeping runtime algorithms generic and data-driven. The library also includes Roslyn analyzers for API migration and a comprehensive test suite with cross-locale theory tests. Key entry points are extension methods on primitive types (e.g., `42.ToWords()`, `"hello_world".Humanize()`, `DateTime.Now.Humanize()`, `ByteSize.FromBytes(1024).Humanize()`) and the `Configurator` for advanced configuration. The primary data flow is: user calls an extension method → culture resolution → delegation to the appropriate converter/formatter → use of generated profile data to produce localized output. External dependencies are limited to the .NET standard library and CLDR plural rule data.
The LLM identified 5 files worth highlighting for reuse:
Implements CLDR 48.2 cardinal plural rules with exact BigInteger operands and a deterministic Ryu double-to-decimal algorithm. Self-contained struct that can be extracted for any project needing CLDR plural rule evaluation.
Core inflection engine with lexeme records, candidates, forward/reverse indexes, and rule ranking. Supports exact and productive inflection paths, script eligibility, and casing preservation. Demonstrates sophisticated data-driven design for pluralization/singularization.
Tokenizer for space-delimited number phrases without intermediate array allocations. Uses a state machine to split on whitespace and punctuation, handling edge cases like leading/trailing spaces. Reusable for any text tokenization task.
Strategy interface for string truncation with multiple implementations (fixed length, fixed characters, dynamic word preservation). Clean separation of concerns, easily extensible.
Generic registry with culture-aware resolution and parent fallback. Used for formatters, converters, ordinalizers, etc. Demonstrates a reusable pattern for locale-sensitive service location.