Intrinsic string manipulation types in TypeScript

Example of Capitalize use
Example of Capitalize use

Today we discuss Capitalize

If you need to make first character in a string uppercase, that's the challenge you look for.

Let's have a look 👀

Type aliases for String manipulation

Since TypeScript 4.1 we have type aliases Uppercase, Lowercase, Capitalize and Uncapitalize.

Knowing how to iterate over a string let's find first element and make it uppercase:

Solution
Solution

We inferred First, made it uppercase with type alias Uppercase. In case of empty string we return itself without any update.

Tests and examples are available in Playground

Have a wonderful Friday 🔥

typescript

Alexey Berezin

Senior Software Engineer, UK Global Talent 🇬🇧

The portrait photo of me

Thank you for reading my blog post! If you have any questions, suggestions, or just want to say hi, feel free to reach out in social networks, or via email. I would love to hear from you!

Comments