Humanizer is a library that transforms programmatic values into human-friendly text. It handles string casing, pluralisation, date humanisation, number-to-words conversion, enum descriptions, and more. Instead of writing string manipulation utilities from scratch, Humanizer gives you extension methods that cover the most common cases.
Setup
dotnet add package Humanizer
String Transformations
Humanise and Dehumanise
Convert PascalCase, camelCase, and underscore_case to readable text:
"PascalCaseInputString".Humanize(); // "Pascal case input string"
"someTitle_Separator".Humanize(); // "some title separator"
"HTML_is_great".Humanize(); // "HTML is great"
Go the other way:
"Pascal case input string".Dehumanize(); // "PascalCaseInputString"
Casing
"this is a title".Transform(To.TitleCase); // "This Is A Title"
"this is a title".Transform(To.SentenceCase); // "This is a title"
"this is a title".Transform(To.UpperCase); // "THIS IS A TITLE"
"This Is A Title".Transform(To.LowerCase); // "this is a title"
Truncation
"A long string that needs truncating".Truncate(20);
// "A long string tha..."
"A long string that needs truncating".Truncate(20, "...", Truncator.FixedNumberOfWords);
// Uses word boundaries instead of characters
Pluralisation and Singularisation
"person".Pluralize(); // "people"
"octopus".Pluralize(); // "octopi"
"people".Singularize(); // "person"
"matrices".Singularize(); // "matrix"
// Conditional pluralisation based on count
"item".ToQuantity(1); // "1 item"
"item".ToQuantity(5); // "5 items"
"person".ToQuantity(2); // "2 people"
Date and Time Humanisation
Convert DateTime and TimeSpan values to relative, readable text:
DateTime.UtcNow.AddHours(-1).Humanize(); // "an hour ago"
DateTime.UtcNow.AddDays(-3).Humanize(); // "3 days ago"
DateTime.UtcNow.AddMinutes(30).Humanize(); // "30 minutes from now"
DateTime.UtcNow.AddMonths(-2).Humanize(); // "2 months ago"
For TimeSpan:
TimeSpan.FromDays(1).Humanize(); // "1 day"
TimeSpan.FromMinutes(90).Humanize(); // "1 hour"
TimeSpan.FromMinutes(90).Humanize(precision: 2); // "1 hour, 30 minutes"
TimeSpan.FromMilliseconds(1299630020).Humanize(3); // "2 weeks, 1 day, 1 hour"
This is particularly useful for displaying durations in dashboards or audit logs.
Number Humanisation
Numbers to Words
1.ToWords(); // "one"
42.ToWords(); // "forty-two"
1000.ToWords(); // "one thousand"
Ordinals
1.Ordinalize(); // "1st"
2.Ordinalize(); // "2nd"
11.Ordinalize(); // "11th"
23.Ordinalize(); // "23rd"
Metric Notation
1500.ToMetric(); // "1.5k"
1000000.ToMetric(); // "1M"
Byte Sizes
(1024L * 1024 * 3).Bytes().Humanize(); // "3 MB"
(1536L).Bytes().Humanize(); // "1.5 KB"
(10240L).Kilobytes().Humanize(); // "10 MB"
Enum Humanisation
Convert enum values to readable descriptions:
public enum OrderStatus
{
[Description("Awaiting payment")]
AwaitingPayment,
[Description("In transit")]
InTransit,
Delivered
}
OrderStatus.AwaitingPayment.Humanize(); // "Awaiting payment"
OrderStatus.Delivered.Humanize(); // "Delivered"
Without a Description attribute, Humanizer splits the PascalCase name. With one, it uses the description text.
Collection Humanisation
var items = new[] { "apples", "oranges", "bananas" };
items.Humanize(); // "apples, oranges, and bananas"
items.Humanize("or"); // "apples, oranges, or bananas"
Practical Example
Combine several Humanizer features in a dashboard display:
public class DashboardViewModel
{
public string TimeSinceLastDeploy { get; set; }
public string UserCount { get; set; }
public string StorageUsed { get; set; }
public string Status { get; set; }
public static DashboardViewModel Create(
DateTime lastDeploy,
int users,
long storageBytes,
DeploymentStatus status)
{
return new DashboardViewModel
{
TimeSinceLastDeploy = lastDeploy.Humanize(),
UserCount = "user".ToQuantity(users),
StorageUsed = storageBytes.Bytes().Humanize(),
Status = status.Humanize()
};
}
}
This produces output like: "3 hours ago", "1,247 users", "2.4 GB", "Rolling update".
Localisation
Humanizer supports multiple languages. Set the culture and the output adapts:
using System.Globalization;
var culture = new CultureInfo("fr");
DateTime.UtcNow.AddHours(-2).Humanize(culture: culture); // "il y a 2 heures"
When to Use Humanizer
Humanizer is ideal for user-facing text — dashboards, notifications, reports, and CLI output. It handles edge cases in pluralisation, ordinals, and date formatting that are tedious to get right manually. The library is well-tested across many languages and locales, making it a solid choice over hand-rolled string utilities.