-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path71.StringUtilities.ts
30 lines (20 loc) · 1.28 KB
/
71.StringUtilities.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// TypeScript String Utilities
// Uppercase utility: Converts all characters in a string to uppercase.
type musicBand = Uppercase<'beatles'>; // 'BEATLES'
// Capitalize utility: Converts the first character in a string to uppercase.
type foodType = Capitalize<'burger'>; // 'Burger'
// Uncapitalize utility: Converts the first character in a string to lowercase.
type programmingLanguage = Uncapitalize<'JavaScript'>; // 'javaScript'
// Lowercase utility: Converts all characters in a string to lowercase.
type animalName = Lowercase<'ELEPHANT'>; // 'elephant'
// Explanation for beginners:
// In TypeScript, we can use utility types to transform strings in various ways.
// The above examples demonstrate some of the string utility types provided by TypeScript.
// 1. Uppercase: This utility will convert the entire string to uppercase letters.
// Example: 'beatles' becomes 'BEATLES'.
// 2. Capitalize: This utility will convert only the first letter of the string to uppercase.
// Example: 'burger' becomes 'Burger'.
// 3. Uncapitalize: This utility will convert only the first letter of the string to lowercase.
// Example: 'JavaScript' becomes 'javaScript'.
// 4. Lowercase: This utility will convert the entire string to lowercase letters.
// Example: 'ELEPHANT' becomes 'elephant'.