Have you ever seen things like "view your order(s)" in an application? If we know how many orders there are, we should pluralize the word "order" appropriately. Another example is showing detailed dates and times when a more simple format like "2 days ago," "yesterday," or "tomorrow" is a more appropriate, more human representation of the data. Humanizer also makes it trivial to convert computerized strings such as Pascal case method names into normal sentences, or turn numeric values into word equivalents. It even makes it easy to work with byte sizes such as writing (10.605).Kilobytes() and creating strings such as "10.61 KB" or ".01 MB". Scenarios like these are made easy with Humanizer, without us having to write and test the code ourselves.
Introduction to Humanizer Hi. I'm Jason Roberts from Pluralsight. Welcome to this course on making. NET data types more human with humanizer. So we've all seen applications where we have a quantity of something and the quantity is post with a parenthesis s to denote that it could either be plural or singular when in reality we either want to say something like order if there's only one or orders if there's more than one. So the humanizer library can help us to achieve things like this and also a lot more. So in this module we'll start off with a simple example application and we'll start off by seeing an inhuman version of this and how we can then start to humanize this user interface using humanizer and also for good measure we'll also output the humanizer strings via text to speech. We'll then get a high level overview of some of the features of humanizer. So we'll start off by looking at some of the features that allow us to work with more humanized numbers. We'll then get an overview of humanizing dates and times with humanizer and finally some of the things that we can do with strings. We'll then learn how to install humanizer and which platforms it's supported on. So we'll learn which NuGet package we need to install and also the currently supported platforms.
Humanizing Strings Hi, welcome back. In this module we'll look at how we can use humanizer to manipulate strings to make them more human. So first off we'll look at how we can take computerized strings and convert them to more human strings and also how we can convert in the opposite direction. So we'll see, for example, how we can take pascal case string and convert it to a regular sentence and also how we can take an underscore separated string and convert this to sentence case. Next, we'll see how we can convert between different cases such as lower, upper, sentence, and title case. And we'll also see how we can create our own custom transforms. Next, we'll look at truncating strings so if strings are too long to display we can truncate them either using three dots or the ellipsis character or our custom characters and also how we can implement custom truncation strategies. Next, we'll look at a quick shorthand for string. format that humanizer provides and then we'll look at how we can convert collections of things to human sentences. So for example, we'll see how a list of person can be transformed to a string Sarah, Amrit, and Gentry. We'll also look at how we can provide a custom formatting function for each item in the list and also how we can create our own custom collection formatters. Next, we'll look at pluralizing and singularizing words. So for example, we can pluralize words such as man so they become men and singularize words such as women so they become woman. Finally, we'll look at another helper method, which allows us to create strings separated by hyphens.
Humanizing Dates and Times Hi. Welcome back to this final module on humanizer. In this module we're going to see how we can use humanizer to humanize dates and times. So we'll start off by looking at date times and we'll see how we can take a date time instance and how we can convert it to a more human representation. So rather than actually outputting the date in terms of hours and minutes and seconds, we can actually say things like now or 2 minutes ago, or if the date time is in the future from the current time, things like tomorrow. We'll also see how when we're humanizing date times we can set the output precision so we can tailor the approximation of this humanized output to our applications needs. Next we'll look at how we can humanize time span instances, so we'll see how we can take a time span instance and convert it to a string such as 5 weeks, 1 day, 1 hour, and 33 seconds, as opposed to just outputting the numeric values for these things separated by colons for example. We'll then learn how we can configure this humanized output to choose which largest output unit we want. So rather than this 5 weeks, 1 day, 1 hour, 33 seconds, we can configure humanizer to instead output 5 weeks. In addition to humanizing date time values for use in our applications, we can also use the fluent date time API provided by humanizer internally in our code. So we'll see how we can create a date time instance in a fluent fashion, such as saying on January the 1st in 2000 at midnight or alternatively in 2 years from now. We'll also learn about the fluent API time span support, so we'll see how instead of saying something like TimeSpan. FromSeconds we can instead say something like 3. Seconds.