String Utility Functions
This module provides a set of utility functions for manipulating and analyzing strings.
shuffle(data: string): string
Randomly shuffles the characters in a string.
Parameters:
data
: The input string to be shuffled.
Returns:
- A new string with characters randomly shuffled.
Example:
untitled
shuffle("hello"); // e.g., "elolh"
capitalize(text: string): string
Capitalizes the first letter of a string. All other letters are converted to lowercase.
Parameters:
text
: The input string.
Returns:
- The capitalized string.
Example:
untitled
capitalize("hello WORLD"); // "Hello"
capitalizeWords(text: string): string
Capitalizes the first letter of each word in a string.
Parameters:
text
: The input string.
Returns:
- The string with each word capitalized.
Example:
untitled
capitalizeWords("hello world"); // "Hello World"
toSnakeCase(text: string): string
Converts a string to snake_case
.
Parameters:
text
: The input string.
Returns:
- The string in
snake_case
.
Example:
untitled
toSnakeCase("Hello World"); // "hello_world"
toSnakeCase("helloWorld"); // "hello_world"
toKebabCase(text: string): string
Converts a string to kebab-case
.
Parameters:
text
: The input string.
Returns:
- The string in
kebab-case
.
Example:
untitled
toKebabCase("Hello World"); // "hello-world"
toKebabCase("helloWorld"); // "hello-world"
toCamelCase(text: string): string
Converts a string to camelCase
.
Parameters:
text
: The input string.
Returns:
- The string in
camelCase
.
Example:
untitled
toCamelCase("hello world"); // "helloWorld"
toCamelCase("Hello World"); // "helloWorld"
reverse(text: string): string
Reverses the characters of a string.
Parameters:
text
: The input string.
Returns:
- The reversed string.
Example:
untitled
reverse("hello"); // "olleh"
isPalindrome(text: string): boolean
Checks whether a string is a palindrome, ignoring spaces and case.
Parameters:
text
: The input string.
Returns:
true
if the string is a palindrome, otherwisefalse
.
Example:
untitled
isPalindrome("Racecar"); // true
isPalindrome("Was it a car or a cat I saw"); // true
isNumeric(text: string): boolean
Checks whether a string contains only digits.
Parameters:
text
: The input string.
Returns:
true
if the string contains only digits, otherwisefalse
.
Example:
untitled
isNumeric("12345"); // true
isNumeric("123a5"); // false
toTitleCase(text: string): string
Converts a string to title case (first letter of each word capitalized).
Parameters:
text
: The input string.
Returns:
- The string in title case.
Example:
untitled
toTitleCase("the quick brown fox"); // "The Quick Brown Fox"