- Spec files
npm-lodash
Describes: pkg:npm/lodash@4.9.x
- Description
- A comprehensive JavaScript utility library with 296+ functions for arrays, objects, strings, and functional programming
- Author
- tessl
- Last updated
string-methods.md docs/
1# String Methods23String transformation utilities for case conversion, templating, text manipulation, and comprehensive string processing operations.45## Capabilities67### Camel Case89Converts string to camel case.1011```javascript { .api }12/**13* Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).14* @param string - The string to convert15* @returns Returns the camel cased string16*/17function camelCase(string?: string): string;18```1920### Capitalize2122Converts the first character of string to upper case and the remaining to lower case.2324```javascript { .api }25/**26* Converts the first character of `string` to upper case and the remaining27* to lower case.28* @param string - The string to capitalize29* @returns Returns the capitalized string30*/31function capitalize(string?: string): string;32```3334### Deburr3536Deburrs string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.3738```javascript { .api }39/**40* Deburrs `string` by converting41* [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)42* and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)43* letters to basic Latin letters and removing44* [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).45* @param string - The string to deburr46* @returns Returns the deburred string47*/48function deburr(string?: string): string;49```5051### Ends With5253Checks if string ends with the given target string.5455```javascript { .api }56/**57* Checks if `string` ends with the given target string.58* @param string - The string to inspect59* @param target - The string to search for60* @param position - The position to search up to (defaults to string.length)61* @returns Returns `true` if `string` ends with `target`, else `false`62*/63function endsWith(string?: string, target?: string, position?: number): boolean;64```6566### Escape6768Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.6970```javascript { .api }71/**72* Converts the characters "&", "<", ">", '"', and "'" in `string` to their73* corresponding HTML entities.74* @param string - The string to escape75* @returns Returns the escaped string76*/77function escape(string?: string): string;78```7980### Escape RegExp8182Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.8384```javascript { .api }85/**86* Escapes the `RegExp` special characters "^", "$", "\\", ".", "*", "+",87* "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.88* @param string - The string to escape89* @returns Returns the escaped string90*/91function escapeRegExp(string?: string): string;92```9394### Kebab Case9596Converts string to kebab case.9798```javascript { .api }99/**100* Converts `string` to101* [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).102* @param string - The string to convert103* @returns Returns the kebab cased string104*/105function kebabCase(string?: string): string;106```107108### Lower Case109110Converts string, as space separated words, to lower case.111112```javascript { .api }113/**114* Converts `string`, as space separated words, to lower case.115* @param string - The string to convert116* @returns Returns the lower cased string117*/118function lowerCase(string?: string): string;119```120121### Lower First122123Converts the first character of string to lower case.124125```javascript { .api }126/**127* Converts the first character of `string` to lower case.128* @param string - The string to convert129* @returns Returns the converted string130*/131function lowerFirst(string?: string): string;132```133134### Pad135136Pads string on the left and right sides if it's shorter than length.137138```javascript { .api }139/**140* Pads `string` on the left and right sides if it's shorter than `length`.141* Padding characters are truncated if they can't be evenly divided by `length`.142* @param string - The string to pad143* @param length - The padding length (defaults to 0)144* @param chars - The string used as padding (defaults to " ")145* @returns Returns the padded string146*/147function pad(string?: string, length?: number, chars?: string): string;148```149150### Pad End151152Pads string on the right side if it's shorter than length.153154```javascript { .api }155/**156* Pads `string` on the right side if it's shorter than `length`. Padding157* characters are truncated if they exceed `length`.158* @param string - The string to pad159* @param length - The padding length (defaults to 0)160* @param chars - The string used as padding (defaults to " ")161* @returns Returns the padded string162*/163function padEnd(string?: string, length?: number, chars?: string): string;164```165166### Pad Start167168Pads string on the left side if it's shorter than length.169170```javascript { .api }171/**172* Pads `string` on the left side if it's shorter than `length`. Padding173* characters are truncated if they exceed `length`.174* @param string - The string to pad175* @param length - The padding length (defaults to 0)176* @param chars - The string used as padding (defaults to " ")177* @returns Returns the padded string178*/179function padStart(string?: string, length?: number, chars?: string): string;180```181182### Parse Int183184Converts string to an integer of the specified radix.185186```javascript { .api }187/**188* Converts `string` to an integer of the specified radix. If `radix` is189* `undefined` or `0`, a `radix` of `10` is used unless `value` is a190* hexadecimal, in which case a `radix` of `16` is used.191* @param string - The string to convert192* @param radix - The radix to interpret `value` by (defaults to 10)193* @returns Returns the converted integer194*/195function parseInt(string: string, radix?: number): number;196```197198### Repeat199200Repeats the given string n times.201202```javascript { .api }203/**204* Repeats the given string `n` times.205* @param string - The string to repeat206* @param n - The number of times to repeat the string (defaults to 1)207* @returns Returns the repeated string208*/209function repeat(string?: string, n?: number): string;210```211212### Replace213214Replaces matches for pattern in string with replacement.215216```javascript { .api }217/**218* Replaces matches for `pattern` in `string` with `replacement`.219* @param string - The string to modify220* @param pattern - The pattern to replace221* @param replacement - The match replacement222* @returns Returns the modified string223*/224function replace(225string: string,226pattern: string | RegExp,227replacement: string | ((substring: string, ...args: any[]) => string)228): string;229```230231### Snake Case232233Converts string to snake case.234235```javascript { .api }236/**237* Converts `string` to238* [snake case](https://en.wikipedia.org/wiki/Snake_case).239* @param string - The string to convert240* @returns Returns the snake cased string241*/242function snakeCase(string?: string): string;243```244245### Split246247Splits string by separator.248249```javascript { .api }250/**251* Splits `string` by `separator`.252* @param string - The string to split253* @param separator - The separator pattern to split by254* @param limit - The length to truncate results to255* @returns Returns the string segments256*/257function split(string?: string, separator?: string | RegExp, limit?: number): string[];258```259260### Start Case261262Converts string to start case.263264```javascript { .api }265/**266* Converts `string` to267* [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).268* @param string - The string to convert269* @returns Returns the start cased string270*/271function startCase(string?: string): string;272```273274### Starts With275276Checks if string starts with the given target string.277278```javascript { .api }279/**280* Checks if `string` starts with the given target string.281* @param string - The string to inspect282* @param target - The string to search for283* @param position - The position to search from (defaults to 0)284* @returns Returns `true` if `string` starts with `target`, else `false`285*/286function startsWith(string?: string, target?: string, position?: number): boolean;287```288289### Template290291Creates 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.292293```javascript { .api }294/**295* Creates a compiled template function that can interpolate data properties296* in "interpolate" delimiters, HTML-escape interpolated data properties in297* "escape" delimiters, and execute JavaScript in "evaluate" delimiters.298* Data properties may be accessed as free variables in the template.299* @param string - The template string300* @param options - The options object301* @returns Returns the compiled template function302*/303function template(string?: string, options?: TemplateOptions): TemplateExecutor;304305interface TemplateOptions {306/** The HTML "escape" delimiter */307escape?: RegExp;308/** The "evaluate" delimiter */309evaluate?: RegExp;310/** The "interpolate" delimiter */311interpolate?: RegExp;312/** Used to import variables into the compiled template */313variable?: string;314/** Used to reference the data object in the template text */315imports?: any;316}317318interface TemplateExecutor {319(data?: any): string;320source: string;321}322```323324### To Lower325326Converts string, as a whole, to lower case just like String#toLowerCase.327328```javascript { .api }329/**330* Converts `string`, as a whole, to lower case just like331* [String#toLowerCase](https://mdn.io/toLowerCase).332* @param string - The string to convert333* @returns Returns the lower cased string334*/335function toLower(string?: string): string;336```337338### To Upper339340Converts string, as a whole, to upper case just like String#toUpperCase.341342```javascript { .api }343/**344* Converts `string`, as a whole, to upper case just like345* [String#toUpperCase](https://mdn.io/toUpperCase).346* @param string - The string to convert347* @returns Returns the upper cased string348*/349function toUpper(string?: string): string;350```351352### Trim353354Removes leading and trailing whitespace or specified characters from string.355356```javascript { .api }357/**358* Removes leading and trailing whitespace or specified characters from `string`.359* @param string - The string to trim360* @param chars - The characters to trim (defaults to whitespace)361* @returns Returns the trimmed string362*/363function trim(string?: string, chars?: string): string;364```365366### Trim End367368Removes trailing whitespace or specified characters from string.369370```javascript { .api }371/**372* Removes trailing whitespace or specified characters from `string`.373* @param string - The string to trim374* @param chars - The characters to trim (defaults to whitespace)375* @returns Returns the trimmed string376*/377function trimEnd(string?: string, chars?: string): string;378```379380### Trim Start381382Removes leading whitespace or specified characters from string.383384```javascript { .api }385/**386* Removes leading whitespace or specified characters from `string`.387* @param string - The string to trim388* @param chars - The characters to trim (defaults to whitespace)389* @returns Returns the trimmed string390*/391function trimStart(string?: string, chars?: string): string;392```393394### Truncate395396Truncates string if it's longer than the given maximum string length.397398```javascript { .api }399/**400* Truncates `string` if it's longer than the given maximum string length.401* The last characters of the truncated string are replaced with the omission402* string which defaults to "...".403* @param string - The string to truncate404* @param options - The options object405* @returns Returns the truncated string406*/407function truncate(string?: string, options?: TruncateOptions): string;408409interface TruncateOptions {410/** The maximum string length (defaults to 30) */411length?: number;412/** The string to indicate text is omitted (defaults to "...") */413omission?: string;414/** The separator pattern to truncate to */415separator?: string | RegExp;416}417```418419### Unescape420421The inverse of escape; this method converts the HTML entities &, <, >, ", and ' in string to their corresponding characters.422423```javascript { .api }424/**425* The inverse of `escape`; this method converts the HTML entities426* `&`, `<`, `>`, `"`, and `'` in `string` to427* their corresponding characters.428* @param string - The string to unescape429* @returns Returns the unescaped string430*/431function unescape(string?: string): string;432```433434### Upper Case435436Converts string, as space separated words, to upper case.437438```javascript { .api }439/**440* Converts `string`, as space separated words, to upper case.441* @param string - The string to convert442* @returns Returns the upper cased string443*/444function upperCase(string?: string): string;445```446447### Upper First448449Converts the first character of string to upper case.450451```javascript { .api }452/**453* Converts the first character of `string` to upper case.454* @param string - The string to convert455* @returns Returns the converted string456*/457function upperFirst(string?: string): string;458```459460### Words461462Splits string into an array of its words.463464```javascript { .api }465/**466* Splits `string` into an array of its words.467* @param string - The string to inspect468* @param pattern - The pattern to match words469* @returns Returns the words of `string`470*/471function words(string?: string, pattern?: string | RegExp): string[];472```