Const
The converted sentence with proper spacing and capitalization
StringUtils.camelCaseToSentence('myVariableName'); // Returns "My Variable Name"
StringUtils.camelCaseToSentence('XMLHttpRequest'); // Returns "XML Http Request"
The camelCase string to convert
Converts a string to camelCase format.
The camelCased string
StringUtils.camelize('hello world'); // Returns "helloWorld"
StringUtils.camelize('my-variable-name'); // Returns "myVariableName"
The string to convert to camelCase
Capitalizes the first letter of a string.
The string with the first letter capitalized
StringUtils.capitalize('hello'); // Returns "Hello"
StringUtils.capitalize('WORLD'); // Returns "WORLD"
The string to capitalize
Capitalizes the first letter of each word in a string.
The string with each word capitalized
StringUtils.capitalizeWords('hello world'); // Returns "Hello World"
StringUtils.capitalizeWords('the quick brown fox'); // Returns "The Quick Brown Fox"
The string to convert to title case
Checks if a string contains another string (case-insensitive).
True if the haystack contains the needle, false otherwise
StringUtils.contains('Hello World', 'world'); // Returns true
StringUtils.contains('JavaScript', 'script'); // Returns true
StringUtils.contains('TypeScript', 'python'); // Returns false
The string to search in
The string to search for
Formats a number of bytes into a human-readable string with appropriate units.
A formatted string with appropriate byte units
StringUtils.formatBytes(1024); // Returns "1 KB"
StringUtils.formatBytes(1536, 1); // Returns "1.5 KB"
StringUtils.formatBytes(1048576); // Returns "1 MB"
The number of bytes to format
The number of decimal places to include (default: 0)
Type guard to check if a value is a string.
True if the value is a string, false otherwise
StringUtils.isString('hello'); // Returns true
StringUtils.isString(123); // Returns false
StringUtils.isString(null); // Returns false
The value to check
Gets the length of a string safely.
The length of the string, or 0 if the string is null/undefined
StringUtils.length('hello'); // Returns 5
StringUtils.length(''); // Returns 0
StringUtils.length(null); // Returns 0
The string to measure
Truncates a string in the middle with ellipsis if it exceeds the maximum length.
The truncated string with ellipsis in the middle
StringUtils.middleEllipsify('verylongfilename.txt', 15); // Returns "veryl...me.txt"
StringUtils.middleEllipsify('short.txt', 20); // Returns "short.txt"
The string to truncate (default: empty string)
The maximum length before truncation (default: 20)
Pads a string with a specified character to reach a target length.
The padded string
StringUtils.pad('5', 3, '0'); // Returns "005"
StringUtils.pad('hello', 8, '*', true); // Returns "hello***"
The string or number to pad
The target length after padding
The character to use for padding
Whether to pad on the right side (default: false, pads left)
Replaces all occurrences of a substring in a string.
The modified string with all occurrences replaced
StringUtils.replaceAll('hello world hello', 'hello', 'hi'); // Returns "hi world hi"
StringUtils.replaceAll('foo-bar-baz', '-', '_'); // Returns "foo_bar_baz"
The string to modify
The substring to find and replace
The substring to replace with
Sorts two values as strings with specified direction.
A number indicating the sort order (-1, 0, or 1)
StringUtils.sort('apple', 'banana'); // Returns -1 (apple comes before banana)
StringUtils.sort('zebra', 'apple', 'desc'); // Returns -1 (zebra comes before apple in desc order)
The first value to compare
The second value to compare
The sort direction: 'asc' for ascending, 'desc' for descending (default: 'asc')
Sorts two values as strings in ascending order.
A number indicating the sort order (-1, 0, or 1)
StringUtils.sortAsc('banana', 'apple'); // Returns 1
The first value to compare
The second value to compare
Sorts two values as strings in descending order.
A number indicating the sort order (-1, 0, or 1)
StringUtils.sortDesc('apple', 'banana'); // Returns 1
The first value to compare
The second value to compare
Converts a value to lowercase string.
The lowercase string representation, or empty string if not a string
StringUtils.toLowerCase('HELLO WORLD'); // Returns "hello world"
StringUtils.toLowerCase('MixedCase'); // Returns "mixedcase"
StringUtils.toLowerCase(123); // Returns ""
The value to convert to lowercase
Extracts only numeric characters from a string.
A string containing only the numeric characters
StringUtils.toNumbers('abc123def456'); // Returns "123456"
StringUtils.toNumbers('phone: (555) 123-4567'); // Returns "5551234567"
StringUtils.toNumbers('no numbers here'); // Returns ""
The string to extract numbers from
Converts any value to its string representation.
The string representation of the value
StringUtils.toString(123); // Returns "123"
StringUtils.toString(true); // Returns "true"
StringUtils.toString(null); // Returns "null"
The value to convert to string
Truncates a string with ellipsis if it exceeds the maximum length.
The truncated string with ellipsis appended if needed
StringUtils.truncateWithEllipsis('This is a very long string', 10); // Returns "This is..."
StringUtils.truncateWithEllipsis('Short', 10); // Returns "Short"
The string to truncate
The maximum length before truncation (default: 100)
Converts the first letter of a string to lowercase.
The string with the first letter in lowercase
StringUtils.uncapitalize('Hello World'); // Returns "hello World"
StringUtils.uncapitalize('UPPERCASE'); // Returns "uPPERCASE"
The string to convert
Converts a camelCase string to a sentence with proper capitalization.