docs/quick-start.md
Get started with Humanizer in minutes.
Install the Humanizer NuGet package:
dotnet add package Humanizer
For English-only:
dotnet add package Humanizer.Core
See Installation for more options.
using Humanizer;
"PascalCaseString".Humanize();
// => "Pascal case string"
"some_property_name".Humanize();
// => "Some property name"
DateTime.UtcNow.AddHours(-2).Humanize();
// => "2 hours ago"
DateTime.UtcNow.AddDays(1).Humanize();
// => "tomorrow"
TimeSpan.FromDays(1).Humanize();
// => "1 day"
TimeSpan.FromMinutes(90).Humanize();
// => "an hour"
public enum PaymentStatus
{
PendingApproval,
Approved,
Declined
}
PaymentStatus.PendingApproval.Humanize();
// => "Pending approval"
"person".Pluralize();
// => "people"
"case".ToQuantity(5);
// => "5 cases"
1234.ToWords();
// => "one thousand two hundred and thirty-four"
1.Ordinalize();
// => "1st"
21.Ordinalize();
// => "21st"
In.January;
// => January 1st of current year
2.Days() + 3.Hours();
// => TimeSpan of 2 days and 3 hours
DateTime.Now + 2.Weeks();
// => DateTime 2 weeks from now
var items = new[] { "apple", "banana", "cherry" };
items.Humanize();
// => "apple, banana, and cherry"
"Long text that needs truncating".Truncate(10);
// => "Long text…"
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
}
// Generate labels automatically
nameof(Person.FirstName).Humanize();
// => "First name"
nameof(Person.DateOfBirth).Humanize();
// => "Date of birth"
var postDate = DateTime.UtcNow.AddHours(-3);
$"Posted {postDate.Humanize()}";
// => "Posted 3 hours ago"
var count = 1234567;
$"Downloaded {count.ToMetric()} times";
// => "Downloaded 1.23M times"
var itemCount = 5;
$"You have {itemCount} {"item".ToQuantity(itemCount)}";
// => "You have 5 items"
var singleItem = 1;
$"You have {singleItem} {"item".ToQuantity(singleItem)}";
// => "You have 1 item"
Explore the documentation for detailed information on each feature: