{"id":13431129,"url":"https://github.com/Humanizr/Humanizer","last_synced_at":"2025-03-16T06:32:20.768Z","repository":{"id":3181511,"uuid":"4213474","full_name":"Humanizr/Humanizer","owner":"Humanizr","description":"Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities","archived":false,"fork":false,"pushed_at":"2024-10-25T09:13:26.000Z","size":8583,"stargazers_count":8671,"open_issues_count":181,"forks_count":966,"subscribers_count":195,"default_branch":"main","last_synced_at":"2024-10-29T11:29:04.439Z","etag":null,"topics":["hacktoberfest","localization"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Humanizr.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"license.txt","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-05-03T12:01:45.000Z","updated_at":"2024-10-26T09:33:22.000Z","dependencies_parsed_at":"2023-07-11T11:02:55.438Z","dependency_job_id":"890633a7-33ab-43c1-8daa-e30c52dc7cd8","html_url":"https://github.com/Humanizr/Humanizer","commit_stats":{"total_commits":1770,"total_committers":252,"mean_commits":7.023809523809524,"dds":0.7853107344632768,"last_synced_commit":"1bdd7a1bad03fd001d04fc0e252d279b4e785818"},"previous_names":["mehdik/humanizer"],"tags_count":70,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Humanizr%2FHumanizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Humanizr%2FHumanizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Humanizr%2FHumanizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Humanizr%2FHumanizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Humanizr","download_url":"https://codeload.github.com/Humanizr/Humanizer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243835952,"owners_count":20355611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","localization"],"created_at":"2024-07-31T02:01:00.733Z","updated_at":"2025-03-16T06:32:20.273Z","avatar_url":"https://github.com/Humanizr.png","language":"C#","readme":"﻿# \u003cimg width=\"30px\" src=\"logo.png\" /\u003e Humanizer\r\n\r\nHumanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities.\r\n\r\n\r\n## Install\u003c/a\u003e\r\n\r\nYou can install Humanizer as [a nuget package](https://nuget.org/packages/Humanizer):\r\n\r\n**English only**: `Humanizer.Core`\r\n\r\nAll languages: `Humanizer`\r\n\r\n\r\n### Supported frameworks\r\n\r\nThe following frameworks are supported: net4.8, net6, net7, and net8\r\n\r\nNote: The nuget also targets netstandard2. This is to enable scenario where netstandard2 is required. For example Roslyn Analyzers or MSBuild tasks. Other frameworks (other than listed above) that can consume netstandard2 (example net4.6.1 through to net 4.7.2) are not supported. For example net4.6.1 through to net4.7.2 are not supported.\r\n\r\nAlso Humanizer symbols are source indexed with [SourceLink](https://github.com/dotnet/sourcelink) and are included in the package so you can step through Humanizer code while debugging your code.\r\n\r\n\r\n### Specify Languages (Optional)\r\n\r\nYou choose which packages based on what NuGet package(s) you install. By default, the main `Humanizer` 2.0 package installs all supported languages exactly like it does in 1.x. If you're not sure, then just use the main `Humanizer` package.\r\n\r\nHere are the options:\r\n\r\n  - **All languages**: use the main `Humanizer` package. This pulls in `Humanizer.Core` and all language packages.\r\n  - **English**: use the `Humanizer.Core` package. Only the English language resources will be available\r\n  - **Specific languages**: Use the language specific packages you'd like. For example for French, use `Humanizer.Core.fr`. You can include multiple languages by installing however many language packages you want.\r\n\r\nThe detailed explanation for how this works is in the comments [here](https://github.com/Humanizr/Humanizer/issues/59#issuecomment-152546079).\r\n\r\n\r\n## Features\r\n\r\n\r\n### Humanize String\r\n\r\n`Humanize` string extensions allow you turn an otherwise computerized string into a more readable human-friendly one.\r\nThe foundation of this was set in the [BDDfy framework](https://github.com/TestStack/TestStack.BDDfy) where class names, method names and properties are turned into human readable sentences.\r\n\r\n```C#\r\n\"PascalCaseInputStringIsTurnedIntoSentence\".Humanize() =\u003e \"Pascal case input string is turned into sentence\"\r\n\r\n\"Underscored_input_string_is_turned_into_sentence\".Humanize() =\u003e \"Underscored input string is turned into sentence\"\r\n\r\n\"Underscored_input_String_is_turned_INTO_sentence\".Humanize() =\u003e \"Underscored input String is turned INTO sentence\"\r\n```\r\n\r\nNote that a string that contains only upper case letters, and consists only of one word, is always treated as an acronym (regardless of its length). To guarantee that any arbitrary string will always be humanized you must use a transform (see `Transform` method below):\r\n\r\n```C#\r\n// acronyms are left intact\r\n\"HTML\".Humanize() =\u003e \"HTML\"\r\n\r\n// any unbroken upper case string is treated as an acronym\r\n\"HUMANIZER\".Humanize() =\u003e \"HUMANIZER\"\r\n\"HUMANIZER\".Transform(To.LowerCase, To.TitleCase) =\u003e \"Humanizer\"\r\n```\r\n\r\nYou may also specify the desired letter casing:\r\n\r\n```C#\r\n\"CanReturnTitleCase\".Humanize(LetterCasing.Title) =\u003e \"Can Return Title Case\"\r\n\r\n\"Can_return_title_Case\".Humanize(LetterCasing.Title) =\u003e \"Can Return Title Case\"\r\n\r\n\"CanReturnLowerCase\".Humanize(LetterCasing.LowerCase) =\u003e \"can return lower case\"\r\n\r\n\"CanHumanizeIntoUpperCase\".Humanize(LetterCasing.AllCaps) =\u003e \"CAN HUMANIZE INTO UPPER CASE\"\r\n```\r\n\r\n \u003e The `LetterCasing` API and the methods accepting it are legacy from V0.2 era and will be deprecated in the future. Instead of that, you can use `Transform` method explained below.\r\n\r\n\r\n### Dehumanize String\r\n\r\nMuch like you can humanize a computer friendly into human friendly string you can dehumanize a human friendly string into a computer friendly one:\r\n\r\n```C#\r\n\"Pascal case input string is turned into sentence\".Dehumanize() =\u003e \"PascalCaseInputStringIsTurnedIntoSentence\"\r\n```\r\n\r\n\r\n### Transform String\r\n\r\nThere is a `Transform` method that supersedes `LetterCasing`, `ApplyCase` and `Humanize` overloads that accept `LetterCasing`.\r\nTransform method signature is as follows:\r\n\r\n```C#\r\nstring Transform(this string input, params IStringTransformer[] transformers)\r\n```\r\n\r\nAnd there are some out of the box implementations of `IStringTransformer` for letter casing:\r\n\r\n```C#\r\n\"Sentence casing\".Transform(To.LowerCase) =\u003e \"sentence casing\"\r\n\"Sentence casing\".Transform(To.SentenceCase) =\u003e \"Sentence casing\"\r\n\"Sentence casing\".Transform(To.TitleCase) =\u003e \"Sentence Casing\"\r\n\"Sentence casing\".Transform(To.UpperCase) =\u003e \"SENTENCE CASING\"\r\n```\r\n\r\n`LowerCase` is a public static property on `To` class that returns an instance of private `ToLowerCase` class that implements `IStringTransformer` and knows how to turn a string into lower case.\r\n\r\nThe benefit of using `Transform` and `IStringTransformer` over `ApplyCase` and `LetterCasing` is that `LetterCasing` is an enum and you're limited to use what's in the framework\r\nwhile `IStringTransformer` is an interface you can implement in your codebase once and use it with `Transform` method allowing for easy extension.\r\n\r\n\r\n### Truncate String\r\n\r\nYou can truncate a `string` using the `Truncate` method:\r\n\r\n```c#\r\n\"Long text to truncate\".Truncate(10) =\u003e \"Long text…\"\r\n```\r\n\r\nBy default the `'…'` character is used to truncate strings. The advantage of using the `'…'` character instead of `\"...\"` is that the former only takes a single character and thus allows more text to be shown before truncation. If you want, you can also provide your own truncation string:\r\n\r\n```c#\r\n\"Long text to truncate\".Truncate(10, \"---\") =\u003e \"Long te---\"\r\n```\r\n\r\nThe default truncation strategy, `Truncator.FixedLength`, is to truncate the input string to a specific length, including the truncation string length.\r\nThere are two more truncator strategies available: one for a fixed number of (alpha-numerical) characters and one for a fixed number of words.\r\nTo use a specific truncator when truncating, the two `Truncate` methods shown in the previous examples all have an overload that allow you to specify the `ITruncator` instance to use for the truncation.\r\nHere are examples on how to use the three provided truncators:\r\n\r\n```c#\r\n\"Long text to truncate\".Truncate(10, Truncator.FixedLength) =\u003e \"Long text…\"\r\n\"Long text to truncate\".Truncate(10, \"---\", Truncator.FixedLength) =\u003e \"Long te---\"\r\n\r\n\"Long text to truncate\".Truncate(6, Truncator.FixedNumberOfCharacters) =\u003e \"Long t…\"\r\n\"Long text to truncate\".Truncate(6, \"---\", Truncator.FixedNumberOfCharacters) =\u003e \"Lon---\"\r\n\r\n\"Long text to truncate\".Truncate(2, Truncator.FixedNumberOfWords) =\u003e \"Long text…\"\r\n\"Long text to truncate\".Truncate(2, \"---\", Truncator.FixedNumberOfWords) =\u003e \"Long text---\"\r\n```\r\n\r\nNote that you can also use create your own truncator by implementing the `ITruncator` interface.\r\n\r\nThere is also an option to choose whether to truncate the string from the beginning (`TruncateFrom.Left`) or the end (`TruncateFrom.Right`).\r\nDefault is the right as shown in the examples above. The examples below show how to truncate from the beginning of the string:\r\n\r\n```c#\r\n\"Long text to truncate\".Truncate(10, Truncator.FixedLength, TruncateFrom.Left) =\u003e \"… truncate\"\r\n\"Long text to truncate\".Truncate(10, \"---\", Truncator.FixedLength, TruncateFrom.Left) =\u003e \"---runcate\"\r\n\r\n\"Long text to truncate\".Truncate(10, Truncator.FixedNumberOfCharacters, TruncateFrom.Left) =\u003e \"…o truncate\"\r\n\"Long text to truncate\".Truncate(16, \"---\", Truncator.FixedNumberOfCharacters, TruncateFrom.Left) =\u003e \"---ext to truncate\"\r\n\r\n\"Long text to truncate\".Truncate(2, Truncator.FixedNumberOfWords, TruncateFrom.Left) =\u003e \"…to truncate\"\r\n\"Long text to truncate\".Truncate(2, \"---\", Truncator.FixedNumberOfWords, TruncateFrom.Left) =\u003e \"---to truncate\"\r\n```\r\n\r\n\r\n### Humanize Enums\r\n\r\nCalling `ToString` directly on enum members usually results in less than ideal output for users. The solution to this is usually to use `DescriptionAttribute` data annotation and then read that at runtime to get a more friendly output. That is a great solution; but more often than not we only need to put some space between words of an enum member - which is what `String.Humanize()` does well. For an enum like:\r\n\r\n```C#\r\npublic enum EnumUnderTest\r\n{\r\n    [Description(\"Custom description\")]\r\n    MemberWithDescriptionAttribute,\r\n    MemberWithoutDescriptionAttribute,\r\n    ALLCAPITALS\r\n}\r\n```\r\n\r\nYou will get:\r\n\r\n```C#\r\n// DescriptionAttribute is honored\r\nEnumUnderTest.MemberWithDescriptionAttribute.Humanize() =\u003e \"Custom description\"\r\n\r\n// In the absence of Description attribute string.Humanizer kicks in\r\nEnumUnderTest.MemberWithoutDescriptionAttribute.Humanize() =\u003e \"Member without description attribute\"\r\n\r\n// Of course you can still apply letter casing\r\nEnumUnderTest.MemberWithoutDescriptionAttribute.Humanize().Transform(To.TitleCase) =\u003e \"Member Without Description Attribute\"\r\n```\r\n\r\nYou are not limited to `DescriptionAttribute` for custom description. Any attribute applied on enum members with a `string Description` property counts.\r\nThis is to help with platforms with missing `DescriptionAttribute` and also for allowing subclasses of the `DescriptionAttribute`.\r\n\r\nYou can even configure the name of the property of attibute to use as description.\r\n\r\n`Configurator.EnumDescriptionPropertyLocator = p =\u003e p.Name == \"Info\"`\r\n\r\nIf you need to provide localised descriptions you can use `DisplayAttribute` data annotation instead.\r\n\r\n```C#\r\npublic enum EnumUnderTest\r\n{\r\n    [Display(Description = \"EnumUnderTest_Member\", ResourceType = typeof(Project.Resources))]\r\n    Member\r\n}\r\n```\r\n\r\nYou will get:\r\n\r\n```C#\r\nEnumUnderTest.Member.Humanize() =\u003e \"content\" // from Project.Resources found under \"EnumUnderTest_Member\" resource key\r\n```\r\n\r\nHopefully this will help avoid littering enums with unnecessary attributes!\r\n\r\n\r\n### Dehumanize Enums\r\n\r\nDehumanizes a string into the Enum it was originally Humanized from! The API looks like:\r\n\r\n```C#\r\npublic static TTargetEnum DehumanizeTo\u003cTTargetEnum\u003e(this string input)\r\n```\r\n\r\nAnd the usage is:\r\n\r\n```C#\r\n\"Member without description attribute\".DehumanizeTo\u003cEnumUnderTest\u003e() =\u003e EnumUnderTest.MemberWithoutDescriptionAttribute\r\n```\r\n\r\nAnd just like the Humanize API it honors the `Description` attribute. You don't have to provide the casing you provided during humanization: it figures it out.\r\n\r\nThere is also a non-generic counterpart for when the original Enum is not known at compile time:\r\n\r\n```C#\r\npublic static Enum DehumanizeTo(this string input, Type targetEnum, NoMatch onNoMatch = NoMatch.ThrowsException)\r\n```\r\n\r\nwhich can be used like:\r\n\r\n```C#\r\n\"Member without description attribute\".DehumanizeTo(typeof(EnumUnderTest)) =\u003e EnumUnderTest.MemberWithoutDescriptionAttribute\r\n```\r\n\r\nBy default both methods throw a `NoMatchFoundException` when they cannot match the provided input against the target enum.\r\nIn the non-generic method you can also ask the method to return null by setting the second optional parameter to `NoMatch.ReturnsNull`.\r\n\r\n\r\n### Humanize DateTime\r\n\r\nYou can `Humanize` an instance of `DateTime` or `DateTimeOffset` and get back a string telling how far back or forward in time that is:\r\n\r\n```C#\r\nDateTime.UtcNow.AddHours(-30).Humanize() =\u003e \"yesterday\"\r\nDateTime.UtcNow.AddHours(-2).Humanize() =\u003e \"2 hours ago\"\r\n\r\nDateTime.UtcNow.AddHours(30).Humanize() =\u003e \"tomorrow\"\r\nDateTime.UtcNow.AddHours(2).Humanize() =\u003e \"2 hours from now\"\r\n\r\nDateTimeOffset.UtcNow.AddHours(1).Humanize() =\u003e \"an hour from now\"\r\n```\r\n\r\nHumanizer supports both local and UTC dates as well as dates with offset (`DateTimeOffset`). You could also provide the date you want the input date to be compared against. If null, it will use the current date as comparison base.\r\nAlso, culture to use can be specified explicitly. If it is not, current thread's current UI culture is used.\r\nHere is the API signature:\r\n\r\n```C#\r\npublic static string Humanize(this DateTime input, bool utcDate = true, DateTime? dateToCompareAgainst = null, CultureInfo culture = null)\r\npublic static string Humanize(this DateTimeOffset input, DateTimeOffset? dateToCompareAgainst = null, CultureInfo culture = null)\r\n```\r\n\r\nMany localizations are available for this method. Here is a few examples:\r\n\r\n```C#\r\n// In ar culture\r\nDateTime.UtcNow.AddDays(-1).Humanize() =\u003e \"أمس\"\r\nDateTime.UtcNow.AddDays(-2).Humanize() =\u003e \"منذ يومين\"\r\nDateTime.UtcNow.AddDays(-3).Humanize() =\u003e \"منذ 3 أيام\"\r\nDateTime.UtcNow.AddDays(-11).Humanize() =\u003e \"منذ 11 يوم\"\r\n\r\n// In ru-RU culture\r\nDateTime.UtcNow.AddMinutes(-1).Humanize() =\u003e \"минуту назад\"\r\nDateTime.UtcNow.AddMinutes(-2).Humanize() =\u003e \"2 минуты назад\"\r\nDateTime.UtcNow.AddMinutes(-10).Humanize() =\u003e \"10 минут назад\"\r\nDateTime.UtcNow.AddMinutes(-21).Humanize() =\u003e \"21 минуту назад\"\r\nDateTime.UtcNow.AddMinutes(-22).Humanize() =\u003e \"22 минуты назад\"\r\nDateTime.UtcNow.AddMinutes(-40).Humanize() =\u003e \"40 минут назад\"\r\n```\r\n\r\nThere are two strategies for `DateTime.Humanize`: the default one as seen above and a precision based one.\r\nTo use the precision based strategy you need to configure it:\r\n\r\n```C#\r\nConfigurator.DateTimeHumanizeStrategy = new PrecisionDateTimeHumanizeStrategy(precision: .75);\r\nConfigurator.DateTimeOffsetHumanizeStrategy = new PrecisionDateTimeOffsetHumanizeStrategy(precision: .75); // configure when humanizing DateTimeOffset\r\n```\r\n\r\nThe default precision is set to .75 but you can pass your desired precision too. With precision set to 0.75:\r\n\r\n```C#\r\n44 seconds =\u003e 44 seconds ago/from now\r\n45 seconds =\u003e one minute ago/from now\r\n104 seconds =\u003e one minute ago/from now\r\n105 seconds =\u003e two minutes ago/from now\r\n\r\n25 days =\u003e a month ago/from now\r\n```\r\n\r\n**No dehumanization for dates as `Humanize` is a lossy transformation and the human friendly date is not reversible**\r\n\r\n\r\n### Humanize TimeSpan\r\n\r\nYou can call `Humanize` on a `TimeSpan` to a get human friendly representation for it:\r\n\r\n```C#\r\nTimeSpan.FromMilliseconds(1).Humanize() =\u003e \"1 millisecond\"\r\nTimeSpan.FromMilliseconds(2).Humanize() =\u003e \"2 milliseconds\"\r\nTimeSpan.FromDays(1).Humanize() =\u003e \"1 day\"\r\nTimeSpan.FromDays(16).Humanize() =\u003e \"2 weeks\"\r\n```\r\n\r\nThere is an optional `precision` parameter for `TimeSpan.Humanize` which allows you to specify the precision of the returned value.\r\nThe default value of `precision` is 1 which means only the largest time unit is returned like you saw in `TimeSpan.FromDays(16).Humanize()`.\r\nHere is a few examples of specifying precision:\r\n\r\n```C#\r\nTimeSpan.FromDays(1).Humanize(precision:2) =\u003e \"1 day\" // no difference when there is only one unit in the provided TimeSpan\r\nTimeSpan.FromDays(16).Humanize(2) =\u003e \"2 weeks, 2 days\"\r\n\r\n// the same TimeSpan value with different precision returns different results\r\nTimeSpan.FromMilliseconds(1299630020).Humanize() =\u003e \"2 weeks\"\r\nTimeSpan.FromMilliseconds(1299630020).Humanize(3) =\u003e \"2 weeks, 1 day, 1 hour\"\r\nTimeSpan.FromMilliseconds(1299630020).Humanize(4) =\u003e \"2 weeks, 1 day, 1 hour, 30 seconds\"\r\nTimeSpan.FromMilliseconds(1299630020).Humanize(5) =\u003e \"2 weeks, 1 day, 1 hour, 30 seconds, 20 milliseconds\"\r\n```\r\n\r\nBy default when using `precision` parameter empty time units are not counted towards the precision of the returned value.\r\nIf this behavior isn't desired for you, you can use the overloaded `TimeSpan.Humanize` method with `countEmptyUnits` parameter. Leading empty time units never count.\r\nHere is an example showing the difference of counting empty units:\r\n\r\n```C#\r\nTimeSpan.FromMilliseconds(3603001).Humanize(3) =\u003e \"1 hour, 3 seconds, 1 millisecond\"\r\nTimeSpan.FromMilliseconds(3603001).Humanize(3, countEmptyUnits:true) =\u003e \"1 hour, 3 seconds\"\r\n```\r\n\r\nMany localizations are available for this method:\r\n\r\n```C#\r\n// in de-DE culture\r\nTimeSpan.FromDays(1).Humanize() =\u003e \"Ein Tag\"\r\nTimeSpan.FromDays(2).Humanize() =\u003e \"2 Tage\"\r\n\r\n// in sk-SK culture\r\nTimeSpan.FromMilliseconds(1).Humanize() =\u003e \"1 milisekunda\"\r\nTimeSpan.FromMilliseconds(2).Humanize() =\u003e \"2 milisekundy\"\r\nTimeSpan.FromMilliseconds(5).Humanize() =\u003e \"5 milisekúnd\"\r\n```\r\n\r\nCulture to use can be specified explicitly. If it is not, current thread's current UI culture is used. Example:\r\n\r\n```C#\r\nTimeSpan.FromDays(1).Humanize(culture: \"ru-RU\") =\u003e \"один день\"\r\n```\r\n\r\nIn addition, a minimum unit of time may be specified to avoid rolling down to a smaller unit. For example:\r\n  ```C#\r\n  TimeSpan.FromMilliseconds(122500).Humanize(minUnit: TimeUnit.Second) =\u003e \"2 minutes, 2 seconds\"    // instead of 2 minutes, 2 seconds, 500 milliseconds\r\n  TimeSpan.FromHours(25).Humanize(minUnit: TimeUnit.Day) =\u003e \"1 Day\"   //instead of 1 Day, 1 Hour\r\n  ```\r\n\r\nIn addition, a maximum unit of time may be specified to avoid rolling up to the next largest unit. For example:\r\n```C#\r\nTimeSpan.FromDays(7).Humanize(maxUnit: TimeUnit.Day) =\u003e \"7 days\"    // instead of 1 week\r\nTimeSpan.FromMilliseconds(2000).Humanize(maxUnit: TimeUnit.Millisecond) =\u003e \"2000 milliseconds\"    // instead of 2 seconds\r\n```\r\nThe default maxUnit is `TimeUnit.Week` because it gives exact results. You can increase this value to `TimeUnit.Month` or `TimeUnit.Year` which will give you an approximation based on 365.2425 days a year and 30.436875 days a month. Therefore the months are alternating between 30 and 31 days in length and every fourth year is 366 days long.\r\n```C#\r\nTimeSpan.FromDays(486).Humanize(maxUnit: TimeUnit.Year, precision: 7) =\u003e \"1 year, 3 months, 29 days\" // One day further is 1 year, 4 month\r\nTimeSpan.FromDays(517).Humanize(maxUnit: TimeUnit.Year, precision: 7) =\u003e \"1 year, 4 months, 30 days\" // This month has 30 days and one day further is 1 year, 5 months\r\n```\r\n\r\nWhen there are multiple time units, they are combined using the `\", \"` string:\r\n\r\n```C#\r\nTimeSpan.FromMilliseconds(1299630020).Humanize(3) =\u003e \"2 weeks, 1 day, 1 hour\"\r\n```\r\n\r\nWhen `TimeSpan` is zero, the default behavior will return \"0\" plus whatever the minimum time unit is. However, if you assign `true` to `toWords` when calling `Humanize`, then the method returns \"no time\". For example:\r\n```C#\r\nTimeSpan.Zero.Humanize(1) =\u003e \"0 milliseconds\"\r\nTimeSpan.Zero.Humanize(1, toWords: true) =\u003e \"no time\"\r\nTimeSpan.Zero.Humanize(1, minUnit: Humanizer.Localisation.TimeUnit.Second) =\u003e \"0 seconds\"\r\n```\r\n\r\nUsing the `collectionSeparator` parameter, you can specify your own separator string:\r\n\r\n```C#\r\nTimeSpan.FromMilliseconds(1299630020).Humanize(3, collectionSeparator: \" - \") =\u003e \"2 weeks - 1 day - 1 hour\"\r\n````\r\n\r\nIt is also possible to use the current culture's collection formatter to combine the time units. To do so, specify `null` as the `collectionSeparator` parameter:\r\n\r\n```C#\r\n// in en-US culture\r\nTimeSpan.FromMilliseconds(1299630020).Humanize(3, collectionSeparator: null) =\u003e \"2 weeks, 1 day, and 1 hour\"\r\n\r\n// in de-DE culture\r\nTimeSpan.FromMilliseconds(1299630020).Humanize(3, collectionSeparator: null) =\u003e \"2 Wochen, Ein Tag und Eine Stunde\"\r\n```\r\n\r\nIf words are preferred to numbers, a `toWords: true` parameter can be set to convert the numbers in a humanized TimeSpan to words:\r\n```C#\r\nTimeSpan.FromMilliseconds(1299630020).Humanize(3, toWords: true) =\u003e \"two weeks, one day, one hour\"\r\n```\r\n\r\nBy calling `ToAge`, a `TimeSpan` can also be expressed as an age.\r\nFor cultures that do not define an age expression, the result will be the same as calling `Humanize` _(but with a default `maxUnit` equal to `TimeUnit.Year`)_. \r\n\r\n```C#\r\n// in en-US culture\r\nTimeSpan.FromDays(750).ToAge() =\u003e \"2 years old\"\r\n\r\n// in fr culture\r\nTimeSpan.FromDays(750).ToAge() =\u003e \"2 ans\"\r\n```\r\n\r\n\r\n### Humanize Collections\r\n\r\nYou can call `Humanize` on any `IEnumerable` to get a nicely formatted string representing the objects in the collection. By default `ToString()` will be called on each item to get its representation but a formatting function may be passed to `Humanize` instead. Additionally, a default separator is provided (\"and\" in English), but a different separator may be passed into `Humanize`.\r\n\r\nFor instance:\r\n\r\n```C#\r\nclass SomeClass\r\n{\r\n    public string SomeString;\r\n    public int SomeInt;\r\n    public override string ToString()\r\n    {\r\n        return \"Specific String\";\r\n    }\r\n}\r\n\r\nstring FormatSomeClass(SomeClass sc)\r\n{\r\n    return string.Format(\"SomeObject #{0} - {1}\", sc.SomeInt, sc.SomeString);\r\n}\r\n\r\nvar collection = new List\u003cSomeClass\u003e\r\n{\r\n    new SomeClass { SomeInt = 1, SomeString = \"One\" },\r\n    new SomeClass { SomeInt = 2, SomeString = \"Two\" },\r\n    new SomeClass { SomeInt = 3, SomeString = \"Three\" }\r\n};\r\n\r\ncollection.Humanize()                                    // \"Specific String, Specific String, and Specific String\"\r\ncollection.Humanize(\"or\")                                // \"Specific String, Specific String, or Specific String\"\r\ncollection.Humanize(FormatSomeClass)                     // \"SomeObject #1 - One, SomeObject #2 - Two, and SomeObject #3 - Three\"\r\ncollection.Humanize(sc =\u003e sc.SomeInt.Ordinalize(), \"or\") // \"1st, 2nd, or 3rd\"\r\n```\r\n\r\nItems are trimmed and blank (NullOrWhitespace) items are skipped. This results in clean comma punctuation. (If there is a custom formatter function, this applies only to the formatter's output.)\r\n\r\nYou can provide your own collection formatter by implementing `ICollectionFormatter` and registering it with `Configurator.CollectionFormatters`.\r\n\r\n\r\n### Inflector methods\r\n\r\nThere are also a few inflector methods:\r\n\r\n\r\n#### Pluralize\r\n\r\n`Pluralize` pluralizes the provided input while taking irregular and uncountable words into consideration:\r\n\r\n```C#\r\n\"Man\".Pluralize() =\u003e \"Men\"\r\n\"string\".Pluralize() =\u003e \"strings\"\r\n```\r\n\r\nNormally you would call `Pluralize` on a singular word but if you're unsure about the singularity of the word you can call the method with the optional `inputIsKnownToBeSingular` argument:\r\n\r\n```C#\r\n\"Men\".Pluralize(inputIsKnownToBeSingular: false) =\u003e \"Men\"\r\n\"Man\".Pluralize(inputIsKnownToBeSingular: false) =\u003e \"Men\"\r\n\"string\".Pluralize(inputIsKnownToBeSingular: false) =\u003e \"strings\"\r\n```\r\n\r\n\r\nThe overload of `Pluralize` with `plurality` argument is obsolete and was removed in version 2.0.\r\n\r\n\r\n#### Singularize\r\n\r\n`Singularize` singularizes the provided input while taking irregular and uncountable words into consideration:\r\n\r\n```C#\r\n\"Men\".Singularize() =\u003e \"Man\"\r\n\"strings\".Singularize() =\u003e \"string\"\r\n```\r\n\r\nNormally you would call `Singularize` on a plural word but if you're unsure about the plurality of the word you can call the method with the optional `inputIsKnownToBePlural` argument:\r\n\r\n```C#\r\n\"Men\".Singularize(inputIsKnownToBePlural: false) =\u003e \"Man\"\r\n\"Man\".Singularize(inputIsKnownToBePlural: false) =\u003e \"Man\"\r\n\"strings\".Singularize(inputIsKnownToBePlural: false) =\u003e \"string\"\r\n```\r\n\r\n\r\nThe overload of `Singularize` with `plurality` argument is obsolete and was removed in version 2.0.\r\n\r\n\r\n## Adding Words\r\n\r\nSometimes, you may need to add a rule from the singularization/pluralization vocabulary (the examples below are already in the `DefaultVocabulary` used by `Inflector`):\r\n\r\n```C#\r\n// Adds a word to the vocabulary which cannot easily be pluralized/singularized by RegEx.\r\n// Will match both \"salesperson\" and \"person\".\r\nVocabularies.Default.AddIrregular(\"person\", \"people\");\r\n\r\n// To only match \"person\" and not \"salesperson\" you would pass false for the 'matchEnding' parameter.\r\nVocabularies.Default.AddIrregular(\"person\", \"people\", matchEnding: false);\r\n\r\n// Adds an uncountable word to the vocabulary.  Will be ignored when plurality is changed:\r\nVocabularies.Default.AddUncountable(\"fish\");\r\n\r\n// Adds a rule to the vocabulary that does not follow trivial rules for pluralization:\r\nVocabularies.Default.AddPlural(\"bus\", \"buses\");\r\n\r\n// Adds a rule to the vocabulary that does not follow trivial rules for singularization\r\n// (will match both \"vertices\" -\u003e \"vertex\" and \"indices\" -\u003e \"index\"):\r\nVocabularies.Default.AddSingular(\"(vert|ind)ices$\", \"$1ex\");\r\n\r\n```\r\n\r\n\r\n#### ToQuantity\r\n\r\nMany times you want to call `Singularize` and `Pluralize` to prefix a word with a number; e.g. \"2 requests\", \"3 men\". `ToQuantity` prefixes the provided word with the number and accordingly pluralizes or singularizes the word:\r\n\r\n```C#\r\n\"case\".ToQuantity(0) =\u003e \"0 cases\"\r\n\"case\".ToQuantity(1) =\u003e \"1 case\"\r\n\"case\".ToQuantity(5) =\u003e \"5 cases\"\r\n\"man\".ToQuantity(0) =\u003e \"0 men\"\r\n\"man\".ToQuantity(1) =\u003e \"1 man\"\r\n\"man\".ToQuantity(2) =\u003e \"2 men\"\r\n```\r\n\r\n`ToQuantity` can figure out whether the input word is singular or plural and will singularize or pluralize as necessary:\r\n\r\n```C#\r\n\"men\".ToQuantity(2) =\u003e \"2 men\"\r\n\"process\".ToQuantity(2) =\u003e \"2 processes\"\r\n\"process\".ToQuantity(1) =\u003e \"1 process\"\r\n\"processes\".ToQuantity(2) =\u003e \"2 processes\"\r\n\"processes\".ToQuantity(1) =\u003e \"1 process\"\r\n```\r\n\r\nYou can also pass a second argument, `ShowQuantityAs`, to `ToQuantity` to specify how you want the provided quantity to be outputted. The default value is `ShowQuantityAs.Numeric` which is what we saw above. The other two values are `ShowQuantityAs.Words` and `ShowQuantityAs.None`.\r\n\r\n```C#\r\n\"case\".ToQuantity(5, ShowQuantityAs.Words) =\u003e \"five cases\"\r\n\"case\".ToQuantity(5, ShowQuantityAs.None) =\u003e \"cases\"\r\n```\r\n\r\nThere is also an overload that allows you to format the number. You can pass in the format and the culture to be used.\r\n\r\n```C#\r\n\"dollar\".ToQuantity(2, \"C0\", new CultureInfo(\"en-US\")) =\u003e \"$2 dollars\"\r\n\"dollar\".ToQuantity(2, \"C2\", new CultureInfo(\"en-US\")) =\u003e \"$2.00 dollars\"\r\n\"cases\".ToQuantity(12000, \"N0\") =\u003e \"12,000 cases\"\r\n```\r\n\r\n\r\n#### Ordinalize\r\n\r\n`Ordinalize` turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th:\r\n\r\n```C#\r\n1.Ordinalize() =\u003e \"1st\"\r\n5.Ordinalize() =\u003e \"5th\"\r\n```\r\n\r\nYou can also call `Ordinalize` on a numeric string and achieve the same result: `\"21\".Ordinalize()` =\u003e `\"21st\"`\r\n\r\n`Ordinalize` also supports grammatical gender for both forms.\r\nYou can pass an argument to `Ordinalize` to specify which gender the number should be outputted in.\r\nThe possible values are `GrammaticalGender.Masculine`, `GrammaticalGender.Feminine` and `GrammaticalGender.Neuter`:\r\n\r\n```C#\r\n// for Brazilian Portuguese locale\r\n1.Ordinalize(GrammaticalGender.Masculine) =\u003e \"1º\"\r\n1.Ordinalize(GrammaticalGender.Feminine) =\u003e \"1ª\"\r\n1.Ordinalize(GrammaticalGender.Neuter) =\u003e \"1º\"\r\n\"2\".Ordinalize(GrammaticalGender.Masculine) =\u003e \"2º\"\r\n\"2\".Ordinalize(GrammaticalGender.Feminine) =\u003e \"2ª\"\r\n\"2\".Ordinalize(GrammaticalGender.Neuter) =\u003e \"2º\"\r\n```\r\n\r\nObviously this only applies to some cultures. For others passing gender in or not passing at all doesn't make any difference in the result.\r\n\r\nIn addition, `Ordinalize` supports variations some cultures apply depending on the position of the ordinalized number in a sentence.\r\nUse the argument `wordForm` to get one result or another. Possible values are `WordForm.Abbreviation` and `WordForm.Normal`.\r\nYou can combine `wordForm` argument with gender but passing this argument in when it is not applicable will not make any difference in the result.\r\n\r\n```C#\r\n// Spanish locale\r\n1.Ordinalize(WordForm.Abbreviation) =\u003e \"1.er\" // As in \"Vivo en el 1.er piso\"\r\n1.Ordinalize(WordForm.Normal) =\u003e \"1.º\" // As in \"He llegado el 1º\"\r\n\"3\".Ordinalize(GrammaticalGender.Feminine, WordForm.Abbreviation) =\u003e \"3.ª\"\r\n\"3\".Ordinalize(GrammaticalGender.Feminine, WordForm.Normal) =\u003e \"3.ª\"\r\n\"3\".Ordinalize(GrammaticalGender.Masculine, WordForm.Abbreviation) =\u003e \"3.er\"\r\n\"3\".Ordinalize(GrammaticalGender.Masculine, WordForm.Normal) =\u003e \"3.º\"\r\n```\r\n\r\n\r\n#### Titleize\r\n\r\n`Titleize` converts the input words to Title casing; equivalent to `\"some title\".Humanize(LetterCasing.Title)`\r\n\r\n\r\n#### Pascalize\r\n\r\n`Pascalize` converts the input words to UpperCamelCase, also removing underscores and spaces:\r\n\r\n```C#\r\n\"some_title for something\".Pascalize() =\u003e \"SomeTitleForSomething\"\r\n```\r\n\r\n\r\n#### Camelize\r\n\r\n`Camelize` behaves identically to `Pascalize`, except that the first character is lower case:\r\n\r\n```C#\r\n\"some_title for something\".Camelize() =\u003e \"someTitleForSomething\"\r\n```\r\n\r\n\r\n#### Underscore\r\n\r\n`Underscore` separates the input words with underscore:\r\n\r\n```C#\r\n\"SomeTitle\".Underscore() =\u003e \"some_title\"\r\n```\r\n\r\n\r\n#### Dasherize \u0026 Hyphenate\r\n\r\n`Dasherize` and `Hyphenate` replace underscores with dashes in the string:\r\n\r\n```C#\r\n\"some_title\".Dasherize() =\u003e \"some-title\"\r\n\"some_title\".Hyphenate() =\u003e \"some-title\"\r\n```\r\n\r\n\r\n#### Kebaberize\r\n\r\n`Kebaberize` separates the input words with hyphens and all words are converted to lowercase\r\n\r\n```C#\r\n\"SomeText\".Kebaberize() =\u003e \"some-text\"\r\n```\r\n\r\n\r\n### Fluent Date\r\n\r\nHumanizer provides a fluent API to deal with `DateTime` and `TimeSpan` as follows:\r\n\r\n`TimeSpan` methods:\r\n\r\n```C#\r\n2.Milliseconds() =\u003e TimeSpan.FromMilliseconds(2)\r\n2.Seconds() =\u003e TimeSpan.FromSeconds(2)\r\n2.Minutes() =\u003e TimeSpan.FromMinutes(2)\r\n2.Hours() =\u003e TimeSpan.FromHours(2)\r\n2.Days() =\u003e TimeSpan.FromDays(2)\r\n2.Weeks() =\u003e TimeSpan.FromDays(14)\r\n```\r\n\r\n\u003csmall\u003eThere are no fluent APIs for month or year as a month could have between 28 to 31 days and a year could be 365 or 366 days.\u003c/small\u003e\r\n\r\nYou could use these methods to, for example, replace\r\n\r\n```C#\r\nDateTime.Now.AddDays(2).AddHours(3).AddMinutes(-5)\r\n```\r\n\r\nwith\r\n\r\n```C#\r\nDateTime.Now + 2.Days() + 3.Hours() - 5.Minutes()\r\n```\r\n\r\nThere are also three categories of fluent methods to deal with `DateTime`:\r\n\r\n```C#\r\nIn.TheYear(2010) // Returns the first of January of 2010\r\nIn.January // Returns 1st of January of the current year\r\nIn.FebruaryOf(2009) // Returns 1st of February of 2009\r\n\r\nIn.One.Second //  DateTime.UtcNow.AddSeconds(1);\r\nIn.Two.SecondsFrom(DateTime dateTime)\r\nIn.Three.Minutes // With corresponding From method\r\nIn.Three.Hours // With corresponding From method\r\nIn.Three.Days // With corresponding From method\r\nIn.Three.Weeks // With corresponding From method\r\nIn.Three.Months // With corresponding From method\r\nIn.Three.Years // With corresponding From method\r\n\r\nOn.January.The4th // Returns 4th of January of the current year\r\nOn.February.The(12) // Returns 12th of Feb of the current year\r\n```\r\n\r\nand some extension methods:\r\n\r\n```C#\r\nvar someDateTime = new DateTime(2011, 2, 10, 5, 25, 45, 125);\r\n\r\n// Returns new DateTime(2008, 2, 10, 5, 25, 45, 125) changing the year to 2008\r\nsomeDateTime.In(2008)\r\n\r\n// Returns new DateTime(2011, 2, 10, 2, 25, 45, 125) changing the hour to 2:25:45.125\r\nsomeDateTime.At(2)\r\n\r\n// Returns new DateTime(2011, 2, 10, 2, 20, 15, 125) changing the time to 2:20:15.125\r\nsomeDateTime.At(2, 20, 15)\r\n\r\n// Returns new DateTime(2011, 2, 10, 12, 0, 0) changing the time to 12:00:00.000\r\nsomeDateTime.AtNoon()\r\n\r\n// Returns new DateTime(2011, 2, 10, 0, 0, 0) changing the time to 00:00:00.000\r\nsomeDateTime.AtMidnight()\r\n```\r\n\r\nObviously you could chain the methods too; e.g. `On.November.The13th.In(2010).AtNoon + 5.Minutes()`\r\n\r\n\r\n### Number to numbers\r\n\r\nHumanizer provides a fluent API that produces (usually big) numbers in a clearer fashion:\r\n\r\n```C#\r\n1.25.Billions() =\u003e 1250000000\r\n3.Hundreds().Thousands() =\u003e 300000\r\n```\r\n\r\n\r\n### Number to words\r\n\r\nHumanizer can change numbers to words using the `ToWords` extension:\r\n\r\n```C#\r\n1.ToWords() =\u003e \"one\"\r\n10.ToWords() =\u003e \"ten\"\r\n11.ToWords() =\u003e \"eleven\"\r\n122.ToWords() =\u003e \"one hundred and twenty-two\"\r\n3501.ToWords() =\u003e \"three thousand five hundred and one\"\r\n```\r\n\r\nYou can also pass a second argument, `GrammaticalGender`, to `ToWords` to specify which gender the number should be outputted in.\r\nThe possible values are `GrammaticalGender.Masculine`, `GrammaticalGender.Feminine` and `GrammaticalGender.Neuter`:\r\n\r\n```C#\r\n// for Russian locale\r\n1.ToWords(GrammaticalGender.Masculine) =\u003e \"один\"\r\n1.ToWords(GrammaticalGender.Feminine) =\u003e \"одна\"\r\n1.ToWords(GrammaticalGender.Neuter) =\u003e \"одно\"\r\n```\r\n\r\n```C#\r\n// for Arabic locale\r\n1.ToWords(GrammaticalGender.Masculine) =\u003e \"واحد\"\r\n1.ToWords(GrammaticalGender.Feminine) =\u003e \"واحدة\"\r\n1.ToWords(GrammaticalGender.Neuter) =\u003e \"واحد\"\r\n(-1).ToWords() =\u003e \"ناقص واحد\"\r\n```\r\n\r\nObviously this only applies to some cultures. For others passing gender in doesn't make any difference in the result.\r\n\r\nAlso, culture to use can be specified explicitly. If it is not, current thread's current UI culture is used. Here's an example:\r\n\r\n```C#\r\n11.ToWords(new CultureInfo(\"en\")) =\u003e \"eleven\"\r\n1.ToWords(GrammaticalGender.Masculine, new CultureInfo(\"ru\")) =\u003e \"один\"\r\n```\r\n\r\nAnother overload of the method allow you to pass a bool to remove the \"And\" that can be added before the last number:\r\n\r\n```C#\r\n3501.ToWords(false) =\u003e \"three thousand five hundred one\"\r\n102.ToWords(false) =\u003e \"one hundred two\"\r\n```\r\nThis method can be useful for writing checks for example.\r\n\r\nFurthermore, `ToWords` supports variations some cultures apply depending on the position of the number in a sentence.\r\nUse the argument `wordForm` to get one result or another. Possible values are `WordForm.Abbreviation` and `WordForm.Normal`.\r\nThis argument can be combined with the rest of the arguments presented above.\r\nPassing `wordForm` argument in when it is not applicable will not make any difference in the result.\r\n\r\n```C#\r\n// Spanish locale\r\n21501.ToWords(WordForm.Abbreviation, GrammaticalGender.Masculine) =\u003e \"veintiún mil quinientos un\"\r\n21501.ToWords(WordForm.Normal, GrammaticalGender.Masculine) =\u003e \"veintiún mil quinientos uno\"\r\n21501.ToWords(WordForm.Abbreviation, GrammaticalGender.Feminine) =\u003e \"veintiuna mil quinientas una\"\r\n// English US locale\r\n21501.ToWords(WordForm.Abbreviation, GrammaticalGender.Masculine, new CultureInfo(\"en-US\")) =\u003e \"twenty-one thousand five hundred and one\"\r\n```\r\n\r\n\r\n### Number to ordinal words\r\n\r\nThis is kind of mixing `ToWords` with `Ordinalize`. You can call `ToOrdinalWords` on a number to get an ordinal representation of the number in words! For example:\r\n\r\n```C#\r\n0.ToOrdinalWords() =\u003e \"zeroth\"\r\n1.ToOrdinalWords() =\u003e \"first\"\r\n2.ToOrdinalWords() =\u003e \"second\"\r\n8.ToOrdinalWords() =\u003e \"eighth\"\r\n10.ToOrdinalWords() =\u003e \"tenth\"\r\n11.ToOrdinalWords() =\u003e \"eleventh\"\r\n12.ToOrdinalWords() =\u003e \"twelfth\"\r\n20.ToOrdinalWords() =\u003e \"twentieth\"\r\n21.ToOrdinalWords() =\u003e \"twenty first\"\r\n121.ToOrdinalWords() =\u003e \"hundred and twenty first\"\r\n```\r\n\r\n`ToOrdinalWords` also supports grammatical gender.\r\nYou can pass a second argument to `ToOrdinalWords` to specify the gender of the output.\r\nThe possible values are `GrammaticalGender.Masculine`, `GrammaticalGender.Feminine` and `GrammaticalGender.Neuter`:\r\n\r\n```C#\r\n// for Brazilian Portuguese locale\r\n1.ToOrdinalWords(GrammaticalGender.Masculine) =\u003e \"primeiro\"\r\n1.ToOrdinalWords(GrammaticalGender.Feminine) =\u003e \"primeira\"\r\n1.ToOrdinalWords(GrammaticalGender.Neuter) =\u003e \"primeiro\"\r\n2.ToOrdinalWords(GrammaticalGender.Masculine) =\u003e \"segundo\"\r\n2.ToOrdinalWords(GrammaticalGender.Feminine) =\u003e \"segunda\"\r\n2.ToOrdinalWords(GrammaticalGender.Neuter) =\u003e \"segundo\"\r\n```\r\n\r\n```C#\r\n// for Arabic locale\r\n1.ToOrdinalWords(GrammaticalGender.Masculine) =\u003e \"الأول\"\r\n1.ToOrdinalWords(GrammaticalGender.Feminine) =\u003e \"الأولى\"\r\n1.ToOrdinalWords(GrammaticalGender.Neuter) =\u003e \"الأول\"\r\n2.ToOrdinalWords(GrammaticalGender.Masculine) =\u003e \"الثاني\"\r\n2.ToOrdinalWords(GrammaticalGender.Feminine) =\u003e \"الثانية\"\r\n2.ToOrdinalWords(GrammaticalGender.Neuter) =\u003e \"الثاني\"\r\n```\r\n\r\nObviously this only applies to some cultures. For others passing gender in doesn't make any difference in the result.\r\n\r\nAlso, culture to use can be specified explicitly. If it is not, current thread's current UI culture is used. Here's an example:\r\n\r\n```C#\r\n10.ToOrdinalWords(new CultureInfo(\"en-US\")) =\u003e \"tenth\"\r\n1.ToOrdinalWords(GrammaticalGender.Masculine, new CulureInfo(\"pt-BR\")) =\u003e \"primeiro\"\r\n```\r\n\r\n`ToOrdinalWords` also supports variations some cultures apply depending on the position of the ordinalized number in a sentence.\r\nUse the argument `wordForm` to get one result or another. Possible values are `WordForm.Abbreviation` and `WordForm.Normal`.\r\nCombine this argument with the rest of the arguments presented above.\r\nPassing `wordForm` argument in when it is not applicable will not make any difference in the result.\r\n\r\n```C#\r\n// Spanish locale\r\n43.ToOrdinalWords(WordForm.Normal, GrammaticalGender.Masculine) =\u003e \"cuadragésimo tercero\"\r\n43.ToOrdinalWords(WordForm.Abbreviation, GrammaticalGender.Masculine) =\u003e \"cuadragésimo tercer\"\r\n43.ToOrdinalWords(WordForm.Abbreviation, GrammaticalGender.Feminine) =\u003e \"cuadragésima tercera\"\r\n// English locale\r\n43.ToOrdinalWords(GrammaticalGender.Masculine, WordForm.Abbreviation, new CultureInfo(\"en\")) =\u003e \"forty-third\"\r\n```\r\n\r\n\r\n### DateTime to ordinal words\r\n\r\nThis is kind of an extension of Ordinalize\r\n```C#\r\n// for English UK locale\r\nnew DateTime(2015, 1, 1).ToOrdinalWords() =\u003e \"1st January 2015\"\r\nnew DateTime(2015, 2, 12).ToOrdinalWords() =\u003e \"12th February 2015\"\r\nnew DateTime(2015, 3, 22).ToOrdinalWords() =\u003e \"22nd March 2015\"\r\n// for English US locale\r\nnew DateTime(2015, 1, 1).ToOrdinalWords() =\u003e \"January 1st, 2015\"\r\nnew DateTime(2015, 2, 12).ToOrdinalWords() =\u003e \"February 12th, 2015\"\r\nnew DateTime(2015, 3, 22).ToOrdinalWords() =\u003e \"March 22nd, 2015\"\r\n```\r\n\r\n`ToOrdinalWords` also supports grammatical case.\r\nYou can pass a second argument to `ToOrdinalWords` to specify the case of the output.\r\nThe possible values are `GrammaticalCase.Nominative`, `GrammaticalCase.Genitive`, `GrammaticalCase.Dative`, `GrammaticalCase.Accusative`, `GrammaticalCase.Instrumental` and `GrammaticalGender.Prepositional`:\r\n\r\n```C#\r\n```\r\n\r\nObviously this only applies to some cultures. For others passing case in doesn't make any difference in the result.\r\n\r\n\r\n### TimeOnly to Clock Notation\r\n\r\nExtends TimeOnly to allow humanizing it to a clock notation\r\n```C#\r\n// for English US locale\r\nnew TimeOnly(3, 0).ToClockNotation() =\u003e \"three o'clock\"\r\nnew TimeOnly(12, 0).ToClockNotation() =\u003e \"noon\"\r\nnew TimeOnly(14, 30).ToClockNotation() =\u003e \"half past two\"\r\n\r\n// for Brazilian Portuguese locale\r\nnew TimeOnly(3, 0).ToClockNotation() =\u003e \"três em ponto\"\r\nnew TimeOnly(12, 0).ToClockNotation() =\u003e \"meio-dia\"\r\nnew TimeOnly(14, 30).ToClockNotation() =\u003e \"duas e meia\"\r\n```\r\n\r\n\r\n### Roman numerals\r\n\r\nHumanizer can change numbers to Roman numerals using the `ToRoman` extension. The numbers 1 to 10 can be expressed in Roman numerals as follows:\r\n\r\n```C#\r\n1.ToRoman() =\u003e \"I\"\r\n2.ToRoman() =\u003e \"II\"\r\n3.ToRoman() =\u003e \"III\"\r\n4.ToRoman() =\u003e \"IV\"\r\n5.ToRoman() =\u003e \"V\"\r\n6.ToRoman() =\u003e \"VI\"\r\n7.ToRoman() =\u003e \"VII\"\r\n8.ToRoman() =\u003e \"VIII\"\r\n9.ToRoman() =\u003e \"IX\"\r\n10.ToRoman() =\u003e \"X\"\r\n```\r\n\r\nAlso the reverse operation using the `FromRoman` extension.\r\n\r\n```C#\r\n\"I\".FromRoman() =\u003e 1\r\n\"II\".FromRoman() =\u003e 2\r\n\"III\".FromRoman() =\u003e 3\r\n\"IV\".FromRoman() =\u003e 4\r\n\"V\".FromRoman() =\u003e 5\r\n```\r\nNote that only integers smaller than 4000 can be converted to Roman numerals.\r\n\r\n\r\n### Metric numerals\r\n\r\nHumanizer can change numbers to Metric numerals using the `ToMetric` extension. The numbers 1, 1230 and 0.1 can be expressed in Metric numerals as follows:\r\n\r\n```C#\r\n1d.ToMetric() =\u003e \"1\"\r\n1230d.ToMetric() =\u003e \"1.23k\"\r\n0.1d.ToMetric() =\u003e \"100m\"\r\n```\r\n\r\nAlso the reverse operation using the `FromMetric` extension.\r\n\r\n```C#\r\n\"1\".FromMetric() =\u003e 1\r\n\"1.23k\".FromMetric() =\u003e 1230\r\n\"100m\".FromMetric() =\u003e 0.1\r\n```\r\n\r\n\r\n### ByteSize\r\n\r\nHumanizer includes a port of the brilliant [ByteSize](https://github.com/omar/ByteSize) library.\r\nQuite a few changes and additions are made on `ByteSize` to make the interaction with `ByteSize` easier and more consistent with the Humanizer API.\r\nHere is a few examples of how you can convert from numbers to byte sizes and between size magnitudes:\r\n\r\n```c#\r\nvar fileSize = (10).Kilobytes();\r\n\r\nfileSize.Bits      =\u003e 81920\r\nfileSize.Bytes     =\u003e 10240\r\nfileSize.Kilobytes =\u003e 10\r\nfileSize.Megabytes =\u003e 0.009765625\r\nfileSize.Gigabytes =\u003e 9.53674316e-6\r\nfileSize.Terabytes =\u003e 9.31322575e-9\r\n```\r\n\r\nThere are a few extension methods that allow you to turn a number into a ByteSize instance:\r\n\r\n```C#\r\n3.Bits();\r\n5.Bytes();\r\n(10.5).Kilobytes();\r\n(2.5).Megabytes();\r\n(10.2).Gigabytes();\r\n(4.7).Terabytes();\r\n```\r\n\r\nYou can also add/subtract the values using +/- operators and Add/Subtract methods:\r\n\r\n```C#\r\nvar total = (10).Gigabytes() + (512).Megabytes() - (2.5).Gigabytes();\r\ntotal.Subtract((2500).Kilobytes()).Add((25).Megabytes());\r\n```\r\n\r\nA `ByteSize` object contains two properties that represent the largest metric prefix symbol and value:\r\n\r\n```C#\r\nvar maxFileSize = (10).Kilobytes();\r\n\r\nmaxFileSize.LargestWholeNumberSymbol;  // \"KB\"\r\nmaxFileSize.LargestWholeNumberValue;   // 10\r\n```\r\n\r\nIf you want a string representation you can call `ToString` or `Humanize` interchangeably on the `ByteSize` instance:\r\n\r\n```C#\r\n7.Bits().ToString();           // 7 b\r\n8.Bits().ToString();           // 1 B\r\n(.5).Kilobytes().Humanize();   // 512 B\r\n(1000).Kilobytes().ToString(); // 1000 KB\r\n(1024).Kilobytes().Humanize(); // 1 MB\r\n(.5).Gigabytes().Humanize();   // 512 MB\r\n(1024).Gigabytes().ToString(); // 1 TB\r\n```\r\n\r\nYou can also optionally provide a format for the expected string representation.\r\nThe formatter can contain the symbol of the value to display: `b`, `B`, `KB`, `MB`, `GB`, `TB`.\r\nThe formatter uses the built in [`double.ToString` method](https://docs.microsoft.com/dotnet/api/system.double.tostring) with `#.##` as the default format which rounds the number to two decimal places:\r\n\r\n```C#\r\nvar b = (10.505).Kilobytes();\r\n\r\n// Default number format is #.##\r\nb.ToString(\"KB\");         // 10.52 KB\r\nb.Humanize(\"MB\");         // .01 MB\r\nb.Humanize(\"b\");          // 86057 b\r\n\r\n// Default symbol is the largest metric prefix value \u003e= 1\r\nb.ToString(\"#.#\");        // 10.5 KB\r\n\r\n// All valid values of double.ToString(string format) are acceptable\r\nb.ToString(\"0.0000\");     // 10.5050 KB\r\nb.Humanize(\"000.00\");     // 010.51 KB\r\n\r\n// You can include number format and symbols\r\nb.ToString(\"#.#### MB\");  // .0103 MB\r\nb.Humanize(\"0.00 GB\");    // 0 GB\r\nb.Humanize(\"#.## B\");     // 10757.12 B\r\n```\r\n\r\nIf you want a string representation with full words you can call `ToFullWords` on the `ByteSize` instance:\r\n\r\n```C#\r\n7.Bits().ToFullWords();           // 7 bits\r\n8.Bits().ToFullWords();           // 1 byte\r\n(.5).Kilobytes().ToFullWords();   // 512 bytes\r\n(1000).Kilobytes().ToFullWords(); // 1000 kilobytes\r\n(1024).Kilobytes().ToFullWords(); // 1 megabyte\r\n(.5).Gigabytes().ToFullWords();   // 512 megabytes\r\n(1024).Gigabytes().ToFullWords(); // 1 terabyte\r\n```\r\n\r\nThere isn't a `Dehumanize` method to turn a string representation back into a `ByteSize` instance; but you can use `Parse` and `TryParse` on `ByteSize` to do that.\r\nLike other `TryParse` methods, `ByteSize.TryParse` returns `boolean` value indicating whether or not the parsing was successful.\r\nIf the value is parsed it is output to the `out` parameter supplied:\r\n\r\n```C#\r\nByteSize output;\r\nByteSize.TryParse(\"1.5mb\", out output);\r\n\r\n// Invalid\r\nByteSize.Parse(\"1.5 b\");   // Can't have partial bits\r\n\r\n// Valid\r\nByteSize.Parse(\"5b\");\r\nByteSize.Parse(\"1.55B\");\r\nByteSize.Parse(\"1.55KB\");\r\nByteSize.Parse(\"1.55 kB \"); // Spaces are trimmed\r\nByteSize.Parse(\"1.55 kb\");\r\nByteSize.Parse(\"1.55 MB\");\r\nByteSize.Parse(\"1.55 mB\");\r\nByteSize.Parse(\"1.55 mb\");\r\nByteSize.Parse(\"1.55 GB\");\r\nByteSize.Parse(\"1.55 gB\");\r\nByteSize.Parse(\"1.55 gb\");\r\nByteSize.Parse(\"1.55 TB\");\r\nByteSize.Parse(\"1.55 tB\");\r\nByteSize.Parse(\"1.55 tb\");\r\n```\r\n\r\nFinally, if you need to calculate the rate at which a quantity of bytes has been transferred, you can use the `Per` method of `ByteSize`. The `Per` method accepts one argument - the measurement interval for the bytes; this is the amount of time it took to transfer the bytes.\r\n\r\nThe `Per` method returns a `ByteRate` class which has a `Humanize` method. By default, rates are given in seconds (eg, MB/s). However, if desired, a TimeUnit may be passed to `Humanize` for an alternate interval. Valid intervals are `TimeUnit.Second`, `TimeUnit.Minute`, and `TimeUnit.Hour`. Examples of each interval and example byte rate usage is below.\r\n\r\n```C#\r\nvar size = ByteSize.FromMegabytes(10);\r\nvar measurementInterval = TimeSpan.FromSeconds(1);\r\n\r\nvar text = size.Per(measurementInterval).Humanize();\r\n// 10 MB/s\r\n\r\ntext = size.Per(measurementInterval).Humanize(TimeUnit.Minute);\r\n// 600 MB/min\r\n\r\ntext = size.Per(measurementInterval).Humanize(TimeUnit.Hour);\r\n// 35.15625 GB/hour\r\n```\r\n\r\nYou can specify a format for the bytes part of the humanized output:\r\n\r\n```C#\r\n19854651984.Bytes().Per(1.Seconds()).Humanize(\"#.##\");\r\n// 18.49 GB/s\r\n```\r\n\r\n\r\n### Heading to words\r\n\r\nHumanizer includes methods to change a numeric heading to words. The heading can be a `double` whereas the result will be a string. You can choose whether to return a full representation of the heading (e.g. north, east, south or west), a short representation (e.g. N, E, S, W) or a unicode arrow character (e.g. ↑, →, ↓, ←).\r\n\r\n```C#\r\n360.ToHeading();\r\n// N\r\n720.ToHeading();\r\n// N\r\n```\r\n\r\nIn order to retrieve a full version of the heading, use the following call:\r\n\r\n```C#\r\n180.ToHeading(HeadingStyle.Full);\r\n// south\r\n360.ToHeading(HeadingStyle.Full);\r\n// north\r\n```\r\n\r\nPlease note that a textual representation has a maximum deviation of 11.25°.\r\n\r\nThe methods above all have an overload with which you can provide a `CultureInfo` object in order to determine the localized result to return.\r\n\r\nTo retrieve an arrow representing the heading use the following method:\r\n\r\n```C#\r\n90.ToHeadingArrow();\r\n// →\r\n225.ToHeadingArrow();\r\n// ↙\r\n```\r\n\r\nThe arrow representation of the heading has a maximum deviation of 22.5°.\r\n\r\nIn order to retrieve a heading based on the short text representation (e.g. N, E, S, W), the following method can be used:\r\n\r\n```C#\r\n\"S\".FromShortHeading();\r\n// 180\r\n\"SW\".FromShortHeading();\r\n// 225\r\n```\r\n\r\n\r\n### Tupleize\r\n\r\nHumanizer can change whole numbers into their 'tuple'  using `Tupleize`. For example:\r\n\r\n```C#\r\n1.Tupleize();\r\n// single\r\n3.Tupleize();\r\n// triple\r\n100.Tupleize();\r\n// centuple\r\n```\r\n\r\nThe numbers 1-10, 100 and 1000 will be converted into a 'named' tuple (i.e. \"single\", \"double\" etc.). Any other number \"n\" will be converted to \"n-tuple\".\r\n\r\n\r\n### Time unit to symbol\r\n\r\nHumanizer can translate time units to their symbols:\r\n\r\n```C#\r\nTimeUnit.Day.ToSymbol();\r\n// d\r\nTimeUnit.Week.ToSymbol();\r\n// week\r\nTimeUnit.Year.ToSymbol();\r\n// y\r\n```\r\n\r\n\r\n## Mix this into your framework to simplify your life\r\n\r\nThis is just a baseline and you can use this to simplify your day to day job. For example, in Asp.Net MVC we keep chucking `Display` attribute on ViewModel properties so `HtmlHelper` can generate correct labels for us; but, just like enums, in vast majority of cases we just need a space between the words in property name - so why not use `\"string\".Humanize` for that?!\r\n\r\nYou may find an Asp.Net MVC sample [in the code](https://github.com/Humanizr/Humanizer/tree/v2.7.9/samples/Humanizer.MvcSample) that does that (although the project is excluded from the solution file to make the nuget package available for .Net 3.5 too).\r\n\r\nThis is achieved using a custom `DataAnnotationsModelMetadataProvider` I called [HumanizerMetadataProvider](https://github.com/Humanizr/Humanizer/blob/v2.7.9/samples/Humanizer.MvcSample/HumanizerMetadataProvider.cs). It is small enough to repeat here; so here we go:\r\n\r\n```C#\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.ComponentModel;\r\nusing System.ComponentModel.DataAnnotations;\r\nusing System.Linq;\r\nusing System.Web.Mvc;\r\nusing Humanizer;\r\n\r\npublic class HumanizerMetadataProvider : DataAnnotationsModelMetadataProvider\r\n{\r\n    protected override ModelMetadata CreateMetadata(\r\n        IEnumerable\u003cAttribute\u003e attributes,\r\n        Type containerType,\r\n        Func\u003cobject\u003e modelAccessor,\r\n        Type modelType,\r\n        string propertyName)\r\n    {\r\n        var propertyAttributes = attributes.ToList();\r\n        var modelMetadata = base.CreateMetadata(propertyAttributes, containerType, modelAccessor, modelType, propertyName);\r\n\r\n        if (IsTransformRequired(modelMetadata, propertyAttributes))\r\n            modelMetadata.DisplayName = modelMetadata.PropertyName.Humanize();\r\n\r\n        return modelMetadata;\r\n    }\r\n\r\n    private static bool IsTransformRequired(ModelMetadata modelMetadata, IList\u003cAttribute\u003e propertyAttributes)\r\n    {\r\n        if (string.IsNullOrEmpty(modelMetadata.PropertyName))\r\n            return false;\r\n\r\n        if (propertyAttributes.OfType\u003cDisplayNameAttribute\u003e().Any())\r\n            return false;\r\n\r\n        if (propertyAttributes.OfType\u003cDisplayAttribute\u003e().Any())\r\n            return false;\r\n\r\n        return true;\r\n    }\r\n}\r\n```\r\n\r\nThis class calls the base class to extract the metadata and then, if required, humanizes the property name.\r\nIt is checking if the property already has a `DisplayName` or `Display` attribute on it in which case the metadata provider will just honor the attribute and leave the property alone.\r\nFor other properties it will Humanize the property name. That is all.\r\n\r\nNow you need to register this metadata provider with Asp.Net MVC.\r\nMake sure you use `System.Web.Mvc.ModelMetadataProviders`, and not `System.Web.ModelBinding.ModelMetadataProviders`:\r\n\r\n```C#\r\nModelMetadataProviders.Current = new HumanizerMetadataProvider();\r\n```\r\n\r\n... and now you can replace:\r\n\r\n```C#\r\npublic class RegisterModel\r\n{\r\n    [Display(Name = \"User name\")]\r\n    public string UserName { get; set; }\r\n\r\n    [Display(Name = \"Email address\")]\r\n    public string EmailAddress { get; set; }\r\n\r\n    [Display(Name = \"Confirm password\")]\r\n    public string ConfirmPassword { get; set; }\r\n}\r\n```\r\n\r\nwith:\r\n\r\n```C#\r\npublic class RegisterModel\r\n{\r\n    public string UserName { get; set; }\r\n    public string EmailAddress { get; set; }\r\n    public string ConfirmPassword { get; set; }\r\n}\r\n```\r\n\r\n... and the \"metadata humanizer\" will take care of the rest.\r\n\r\nNo need to mention that if you want title casing for your labels you can chain the method with `Transform`:\r\n\r\n```C#\r\nmodelMetadata.DisplayName = modelMetadata.PropertyName.Humanize().Transform(To.TitleCase);\r\n```\r\n\r\n\r\n## Use in ASP.NET 4.x MVC Views\r\n\r\nHumanizer is a Portable Class Library. There is currently [an issue](https://stackoverflow.com/questions/16675171/what-does-the-web-config-compilation-assemblies-element-do) if you try to use PCL's in an MVC view since the MVC views do not share the same build system as the regular project. You must specify all references in the `web.config` file, including ones the project system normally automatically adds.\r\n\r\nIf you encounter errors saying that you must add a reference to either `System.Runtime` or `System.Globalization`, this applies to you. The solution is to add the contract references to your `web.config` as listed [here](https://stackoverflow.com/a/19942274/738188). Note that this applies to any PCL you use in an MVC view, not just Humanizer.\r\n\r\n\r\n## Continuous Integration from Azure DevOps\r\n\r\nHumanizer project is built \u0026 tested continuously by Azure DevOps (more details [here](https://dev.azure.com/dotnet/Humanizer/_build?definitionId=14)). That applies to pull requests too. Shortly after you submit a PR you can check the build and test status notification on your PR.\r\n\r\nThe current build status on the CI server is [![Build status](https://dev.azure.com/dotnet/Humanizer/_apis/build/status/Humanizer-CI?branchName=main)](https://dev.azure.com/dotnet/Humanizer/_build?definitionId=14)\r\n\r\n\r\n## Related projects\r\n\r\nBelow is a list of related open source projects:\r\n\r\n\r\n### Humanizer ReSharper Annotations\r\n\r\nIf using ReSharper, annotations for Humanizer are available in the [Humanizer.Annotations package](https://resharper-plugins.jetbrains.com/packages/Humanizer.Annotations/), which you can obtain via the ReSharper Extension Manager.\r\nThese annotations do not yet cover the entire library, but [pull requests are always welcome!](https://github.com/enduracode/humanizer-annotations).\r\n\r\n\r\n### PowerShell Humanizer\r\n\r\n[PowerShell Humanizer](https://github.com/dfinke/PowerShellHumanizer) is a PowerShell module that wraps Humanizer.\r\n\r\n\r\n### Humanizer JVM\r\n\r\n[Humanizer.jvm](https://github.com/MehdiK/Humanizer.jvm) is an adaptation of the Humanizer framework for .Net which is made for the jvm and is written in Kotlin.\r\nHumanizer.jvm meets all your jvm needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities.\r\n\r\n\r\n### Humanizer.node\r\n\r\n[Humanizer.node](https://github.com/fakoua/humanizer.node) is a TypeScript port of the Humanizer framework.\r\n\r\n\r\n## Icon\r\n\r\nIcon created by [Tyrone Rieschiek](https://twitter.com/Inkventive)\r\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","C\\#","C#","C# #","框架, 库和工具","General","Libraries, Frameworks and Tools","localization","String Utils","Misc","杂项","Bibliotecas úteis","Identifiers"],"sub_categories":["Misc","大杂烩","GUI - other",".NET"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHumanizr%2FHumanizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHumanizr%2FHumanizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHumanizr%2FHumanizer/lists"}