TypeScript:
Перетворення рядка у нижній регістр
Що це таке та навіщо?
Converting a string to lower case means changing all letters in the string to their lower case form. Programmers do this for consistency, such as when comparing user inputs that should be case-insensitive.
How to:
Як це зробити:
let greeting: string = "Привіт, Світе!";
let lowerCaseGreeting: string = greeting.toLowerCase();
console.log(lowerCaseGreeting); // "привіт, світе!"
Deep Dive
Поглиблений огляд:
Historically, case conversion has been used to make text processing uniform, regardless of the case used when the text was inputted. In TypeScript, the toLowerCase()
method streamlines this process for strings.
Alternatives include manually iterating over each character and transforming it, but that’s unnecessary and error-prone when toLowerCase()
is available.
Implementation-wise, toLowerCase()
handles Unicode characters as well, respecting the locality (though, for specific locale rules, toLocaleLowerCase()
may be used instead).
See Also
Додаткова інформація:
- MDN Documentation on
toLowerCase()
: MDN web docs - TypeScript Official Documentation: TypeScript Language
- Unicode standard for case mapping: Unicode Case Mapping