Skip to content

Pull in https://github.com/Humanizr/Humanizer rather than bother writing anymore #15

@jeffshumphreys

Description

@jeffshumphreys

https://github.com/Humanizr/Humanizer

Massive functionality, and MIT as well.

"Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities. It is part of the .NET Foundation, and operates under their code of conduct. It is licensed under the MIT (an OSI approved license)."

ByteSize.Parse("1.55 gB");
var b = (10.505).Kilobytes();
(1024).Gigabytes().ToString(); // 1 TB
maxFileSize.LargestWholeNumberSymbol; // "KB"
b.Humanize("#.## B"); // 10757.12 B
(1000).Kilobytes().ToFullWords(); // 1000 kilobytes
(4.7).Terabytes();
3.Bits();
var fileSize = (10).Kilobytes();
1.ToRoman() => "I"
new DateTime(2015, 1, 1).ToOrdinalWords() => "January 1st, 2015"
new DateTime(2015, 2, 12).ToOrdinalWords() => "February 12th, 2015"
new DateTime(2015, 3, 22).ToOrdinalWords() => "March 22nd, 2015"
10.ToOrdinalWords(new CultureInfo("en-US")) => "tenth"
5.Ordinalize() => "5th"
121.ToOrdinalWords() => "hundred and twenty first"
3501.ToWords() => "three thousand five hundred and one"
3.Hundreds().Thousands() => 300000
1.25.Billions() => 1250000000
3.Hundreds().Thousands() => 300000
someDateTime.At(2, 20, 15)
On.November.The13th.In(2010).AtNoon + 5.Minutes()
In.One.Second // DateTime.UtcNow.AddSeconds(1);
In.TheYear(2010) // Returns the first of January of 2010
In.FebruaryOf(2009) // Returns 1st of February of 2009
In.Two.SecondsFrom(DateTime dateTime)
DateTime.Now + 2.Days() + 3.Hours() - 5.Minutes()
2.Hours() => TimeSpan.FromHours(2)
"SomeTitle".Underscore() => "some_title"
"some_title for something".Camelize() => "someTitleForSomething"
"case".ToQuantity(5, ShowQuantityAs.Words) => "five cases"
"case".ToQuantity(5, ShowQuantityAs.None) => "cases"
"man".ToQuantity(1) => "1 man"
"man".ToQuantity(2) => "2 men"
Vocabularies.Default.AddSingular("(vert|ind)ices$", "$1ex");
Vocabularies.Default.AddIrregular("person", "people");
Vocabularies.Default.AddUncountable("fish");
Vocabularies.Default.AddPlural("bus", "buses");
collection.Humanize() // "Specific String, Specific String, and Specific String"
collection.Humanize(sc => sc.SomeInt.Ordinalize(), "or") // "1st, 2nd, or 3rd"
TimeSpan.FromMilliseconds(1299630020).Humanize(3, toWords: true) => "two weeks, one day, one hour"
DateTime.UtcNow.AddHours(-30).Humanize() => "yesterday"
DateTime.UtcNow.AddHours(-2).Humanize() => "2 hours ago"
DateTime.UtcNow.AddHours(30).Humanize() => "tomorrow"
DateTime.UtcNow.AddHours(2).Humanize() => "2 hours from now"
DateTimeOffset.UtcNow.AddHours(1).Humanize() => "an hour from now"
"To be formatted -> {0}/{1}.".FormatWith(1, "A") => "To be formatted -> 1/A."
"Long text to truncate".Truncate(2, Truncator.FixedNumberOfWords) => "Long text…"
"Sentence casing".Transform(To.LowerCase) => "sentence casing"
"Sentence casing".Transform(To.SentenceCase) => "Sentence casing"
"Sentence casing".Transform(To.TitleCase) => "Sentence Casing"
"Sentence casing".Transform(To.UpperCase) => "SENTENCE CASING"
"Pascal case input string is turned into sentence".Dehumanize() => "PascalCaseInputStringIsTurnedIntoSentence"
"Underscored_input_String_is_turned_INTO_sentence".Humanize() => "Underscored input String is turned INTO sentence"

It's not framework, so I'll have to cut and paste.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions