String transformation utilities for case conversion, templating, text manipulation, and comprehensive string processing operations.
Converts string to camel case.
/**
* Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
* @param string - The string to convert
* @returns Returns the camel cased string
*/
function camelCase(string?: string): string;Converts the first character of string to upper case and the remaining to lower case.
/**
* Converts the first character of `string` to upper case and the remaining
* to lower case.
* @param string - The string to capitalize
* @returns Returns the capitalized string
*/
function capitalize(string?: string): string;Deburrs string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.
/**
* Deburrs `string` by converting
* [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
* and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
* letters to basic Latin letters and removing
* [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
* @param string - The string to deburr
* @returns Returns the deburred string
*/
function deburr(string?: string): string;Checks if string ends with the given target string.
/**
* Checks if `string` ends with the given target string.
* @param string - The string to inspect
* @param target - The string to search for
* @param position - The position to search up to (defaults to string.length)
* @returns Returns `true` if `string` ends with `target`, else `false`
*/
function endsWith(string?: string, target?: string, position?: number): boolean;Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.
/**
* Converts the characters "&", "<", ">", '"', and "'" in `string` to their
* corresponding HTML entities.
* @param string - The string to escape
* @returns Returns the escaped string
*/
function escape(string?: string): string;Escapes the RegExp special characters "^", "$", "", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.
/**
* Escapes the `RegExp` special characters "^", "$", "\\", ".", "*", "+",
* "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
* @param string - The string to escape
* @returns Returns the escaped string
*/
function escapeRegExp(string?: string): string;Converts string to kebab case.
/**
* Converts `string` to
* [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
* @param string - The string to convert
* @returns Returns the kebab cased string
*/
function kebabCase(string?: string): string;Converts string, as space separated words, to lower case.
/**
* Converts `string`, as space separated words, to lower case.
* @param string - The string to convert
* @returns Returns the lower cased string
*/
function lowerCase(string?: string): string;Converts the first character of string to lower case.
/**
* Converts the first character of `string` to lower case.
* @param string - The string to convert
* @returns Returns the converted string
*/
function lowerFirst(string?: string): string;Pads string on the left and right sides if it's shorter than length.
/**
* Pads `string` on the left and right sides if it's shorter than `length`.
* Padding characters are truncated if they can't be evenly divided by `length`.
* @param string - The string to pad
* @param length - The padding length (defaults to 0)
* @param chars - The string used as padding (defaults to " ")
* @returns Returns the padded string
*/
function pad(string?: string, length?: number, chars?: string): string;Pads string on the right side if it's shorter than length.
/**
* Pads `string` on the right side if it's shorter than `length`. Padding
* characters are truncated if they exceed `length`.
* @param string - The string to pad
* @param length - The padding length (defaults to 0)
* @param chars - The string used as padding (defaults to " ")
* @returns Returns the padded string
*/
function padEnd(string?: string, length?: number, chars?: string): string;Pads string on the left side if it's shorter than length.
/**
* Pads `string` on the left side if it's shorter than `length`. Padding
* characters are truncated if they exceed `length`.
* @param string - The string to pad
* @param length - The padding length (defaults to 0)
* @param chars - The string used as padding (defaults to " ")
* @returns Returns the padded string
*/
function padStart(string?: string, length?: number, chars?: string): string;Converts string to an integer of the specified radix.
/**
* Converts `string` to an integer of the specified radix. If `radix` is
* `undefined` or `0`, a `radix` of `10` is used unless `value` is a
* hexadecimal, in which case a `radix` of `16` is used.
* @param string - The string to convert
* @param radix - The radix to interpret `value` by (defaults to 10)
* @returns Returns the converted integer
*/
function parseInt(string: string, radix?: number): number;Repeats the given string n times.
/**
* Repeats the given string `n` times.
* @param string - The string to repeat
* @param n - The number of times to repeat the string (defaults to 1)
* @returns Returns the repeated string
*/
function repeat(string?: string, n?: number): string;Replaces matches for pattern in string with replacement.
/**
* Replaces matches for `pattern` in `string` with `replacement`.
* @param string - The string to modify
* @param pattern - The pattern to replace
* @param replacement - The match replacement
* @returns Returns the modified string
*/
function replace(
string: string,
pattern: string | RegExp,
replacement: string | ((substring: string, ...args: any[]) => string)
): string;Converts string to snake case.
/**
* Converts `string` to
* [snake case](https://en.wikipedia.org/wiki/Snake_case).
* @param string - The string to convert
* @returns Returns the snake cased string
*/
function snakeCase(string?: string): string;Splits string by separator.
/**
* Splits `string` by `separator`.
* @param string - The string to split
* @param separator - The separator pattern to split by
* @param limit - The length to truncate results to
* @returns Returns the string segments
*/
function split(string?: string, separator?: string | RegExp, limit?: number): string[];Converts string to start case.
/**
* Converts `string` to
* [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
* @param string - The string to convert
* @returns Returns the start cased string
*/
function startCase(string?: string): string;Checks if string starts with the given target string.
/**
* Checks if `string` starts with the given target string.
* @param string - The string to inspect
* @param target - The string to search for
* @param position - The position to search from (defaults to 0)
* @returns Returns `true` if `string` starts with `target`, else `false`
*/
function startsWith(string?: string, target?: string, position?: number): boolean;Creates a compiled template function that can interpolate data properties in "interpolate" delimiters, HTML-escape interpolated data properties in "escape" delimiters, and execute JavaScript in "evaluate" delimiters.
/**
* Creates a compiled template function that can interpolate data properties
* in "interpolate" delimiters, HTML-escape interpolated data properties in
* "escape" delimiters, and execute JavaScript in "evaluate" delimiters.
* Data properties may be accessed as free variables in the template.
* @param string - The template string
* @param options - The options object
* @returns Returns the compiled template function
*/
function template(string?: string, options?: TemplateOptions): TemplateExecutor;
interface TemplateOptions {
/** The HTML "escape" delimiter */
escape?: RegExp;
/** The "evaluate" delimiter */
evaluate?: RegExp;
/** The "interpolate" delimiter */
interpolate?: RegExp;
/** Used to import variables into the compiled template */
variable?: string;
/** Used to reference the data object in the template text */
imports?: any;
}
interface TemplateExecutor {
(data?: any): string;
source: string;
}Converts string, as a whole, to lower case just like String#toLowerCase.
/**
* Converts `string`, as a whole, to lower case just like
* [String#toLowerCase](https://mdn.io/toLowerCase).
* @param string - The string to convert
* @returns Returns the lower cased string
*/
function toLower(string?: string): string;Converts string, as a whole, to upper case just like String#toUpperCase.
/**
* Converts `string`, as a whole, to upper case just like
* [String#toUpperCase](https://mdn.io/toUpperCase).
* @param string - The string to convert
* @returns Returns the upper cased string
*/
function toUpper(string?: string): string;Removes leading and trailing whitespace or specified characters from string.
/**
* Removes leading and trailing whitespace or specified characters from `string`.
* @param string - The string to trim
* @param chars - The characters to trim (defaults to whitespace)
* @returns Returns the trimmed string
*/
function trim(string?: string, chars?: string): string;Removes trailing whitespace or specified characters from string.
/**
* Removes trailing whitespace or specified characters from `string`.
* @param string - The string to trim
* @param chars - The characters to trim (defaults to whitespace)
* @returns Returns the trimmed string
*/
function trimEnd(string?: string, chars?: string): string;Removes leading whitespace or specified characters from string.
/**
* Removes leading whitespace or specified characters from `string`.
* @param string - The string to trim
* @param chars - The characters to trim (defaults to whitespace)
* @returns Returns the trimmed string
*/
function trimStart(string?: string, chars?: string): string;Truncates string if it's longer than the given maximum string length.
/**
* Truncates `string` if it's longer than the given maximum string length.
* The last characters of the truncated string are replaced with the omission
* string which defaults to "...".
* @param string - The string to truncate
* @param options - The options object
* @returns Returns the truncated string
*/
function truncate(string?: string, options?: TruncateOptions): string;
interface TruncateOptions {
/** The maximum string length (defaults to 30) */
length?: number;
/** The string to indicate text is omitted (defaults to "...") */
omission?: string;
/** The separator pattern to truncate to */
separator?: string | RegExp;
}The inverse of escape; this method converts the HTML entities &, <, >, ", and ' in string to their corresponding characters.
/**
* The inverse of `escape`; this method converts the HTML entities
* `&`, `<`, `>`, `"`, and `'` in `string` to
* their corresponding characters.
* @param string - The string to unescape
* @returns Returns the unescaped string
*/
function unescape(string?: string): string;Converts string, as space separated words, to upper case.
/**
* Converts `string`, as space separated words, to upper case.
* @param string - The string to convert
* @returns Returns the upper cased string
*/
function upperCase(string?: string): string;Converts the first character of string to upper case.
/**
* Converts the first character of `string` to upper case.
* @param string - The string to convert
* @returns Returns the converted string
*/
function upperFirst(string?: string): string;Splits string into an array of its words.
/**
* Splits `string` into an array of its words.
* @param string - The string to inspect
* @param pattern - The pattern to match words
* @returns Returns the words of `string`
*/
function words(string?: string, pattern?: string | RegExp): string[];