Showing posts with label humanizer. Show all posts
Showing posts with label humanizer. Show all posts

Apr 28, 2014

Humanizer



Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities.
One can install Humanizer as a nuget package: 
Install-Package Humanizer

Features
  • Humanize: Humanize string extensions allow you turn an otherwise computerized string into a more readable human-friendly one.
  • Dehumanize: Much like you can humanize a computer friendly into human friendly string you can dehumanize a human friendly string into a computer friendly one
  • Transform: There is a Transform method that supersedes LetterCasing, ApplyCase and Humanize overloads that accept LetterCasing.
  • Truncate: You can truncate a string using the Truncate method
  • Humanize DateTime: You can Humanize an instance of DateTime and get back a string telling how far back or forward in time.
  • Inflector methods: There are also a few inflector methods:
    • Pluralize: Pluralize pluralizes the provided input while taking irregular and uncountable words into consideration.
    • Singularize: Singularize singularizes the provided input while taking irregular and uncountable words into consideration.
    • ToQuantity: Many times you want to call Singularize and Pluralize to prefix a word with a number; e.g. "2 requests", "3 men".
    • Ordinalize: Ordinalize turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
  • Number to words: Humanizer can change numbers to words using the ToWords extension



Few examples of above features:
  • "PascalCaseInputStringIsTurnedIntoSentence".Humanize() => "Pascal case input string is turned into sentence"
  • "CanReturnTitleCase".Humanize(LetterCasing.Title) => "Can Return Title Case"
  • "Pascal case input string is turned into sentence".Dehumanize() => "PascalCaseInputStringIsTurnedIntoSentence"
  • "Sentence casing".Transform(To.SentenceCase) => "Sentence casing"
  • "Long text to truncate".Truncate(10) => "Long text…"
  • "Long text to truncate".Truncate(2, Truncator.FixedNumberOfWords, TruncateFrom.Left) => "…to truncate"
  • DateTime.UtcNow.AddHours(30).Humanize() => "tomorrow"
  • DateTime.UtcNow.AddHours(2).Humanize() => "2 hours from now"
  • "Man".Pluralize() => "Men"
  • "Men".Singularize() => "Man"
  • "case".ToQuantity(0) => "0 cases"
  • 1.Ordinalize() => "1st"
  • 122.ToWords() => "one hundred and twenty-two"


You can download from here also.