npm-lodash

Description
A comprehensive JavaScript utility library with 296+ functions for arrays, objects, strings, and functional programming
Author
tessl
Last updated

How to use

npx @tessl/cli registry install tessl/npm-lodash@4.9.0

string-methods.md docs/

1
# String Methods
2
3
String transformation utilities for case conversion, templating, text manipulation, and comprehensive string processing operations.
4
5
## Capabilities
6
7
### Camel Case
8
9
Converts string to camel case.
10
11
```javascript { .api }
12
/**
13
* Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
14
* @param string - The string to convert
15
* @returns Returns the camel cased string
16
*/
17
function camelCase(string?: string): string;
18
```
19
20
### Capitalize
21
22
Converts the first character of string to upper case and the remaining to lower case.
23
24
```javascript { .api }
25
/**
26
* Converts the first character of `string` to upper case and the remaining
27
* to lower case.
28
* @param string - The string to capitalize
29
* @returns Returns the capitalized string
30
*/
31
function capitalize(string?: string): string;
32
```
33
34
### Deburr
35
36
Deburrs string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.
37
38
```javascript { .api }
39
/**
40
* Deburrs `string` by converting
41
* [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 removing
44
* [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
45
* @param string - The string to deburr
46
* @returns Returns the deburred string
47
*/
48
function deburr(string?: string): string;
49
```
50
51
### Ends With
52
53
Checks if string ends with the given target string.
54
55
```javascript { .api }
56
/**
57
* Checks if `string` ends with the given target string.
58
* @param string - The string to inspect
59
* @param target - The string to search for
60
* @param position - The position to search up to (defaults to string.length)
61
* @returns Returns `true` if `string` ends with `target`, else `false`
62
*/
63
function endsWith(string?: string, target?: string, position?: number): boolean;
64
```
65
66
### Escape
67
68
Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.
69
70
```javascript { .api }
71
/**
72
* Converts the characters "&", "<", ">", '"', and "'" in `string` to their
73
* corresponding HTML entities.
74
* @param string - The string to escape
75
* @returns Returns the escaped string
76
*/
77
function escape(string?: string): string;
78
```
79
80
### Escape RegExp
81
82
Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.
83
84
```javascript { .api }
85
/**
86
* Escapes the `RegExp` special characters "^", "$", "\\", ".", "*", "+",
87
* "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
88
* @param string - The string to escape
89
* @returns Returns the escaped string
90
*/
91
function escapeRegExp(string?: string): string;
92
```
93
94
### Kebab Case
95
96
Converts string to kebab case.
97
98
```javascript { .api }
99
/**
100
* Converts `string` to
101
* [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
102
* @param string - The string to convert
103
* @returns Returns the kebab cased string
104
*/
105
function kebabCase(string?: string): string;
106
```
107
108
### Lower Case
109
110
Converts string, as space separated words, to lower case.
111
112
```javascript { .api }
113
/**
114
* Converts `string`, as space separated words, to lower case.
115
* @param string - The string to convert
116
* @returns Returns the lower cased string
117
*/
118
function lowerCase(string?: string): string;
119
```
120
121
### Lower First
122
123
Converts the first character of string to lower case.
124
125
```javascript { .api }
126
/**
127
* Converts the first character of `string` to lower case.
128
* @param string - The string to convert
129
* @returns Returns the converted string
130
*/
131
function lowerFirst(string?: string): string;
132
```
133
134
### Pad
135
136
Pads string on the left and right sides if it's shorter than length.
137
138
```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 pad
143
* @param length - The padding length (defaults to 0)
144
* @param chars - The string used as padding (defaults to " ")
145
* @returns Returns the padded string
146
*/
147
function pad(string?: string, length?: number, chars?: string): string;
148
```
149
150
### Pad End
151
152
Pads string on the right side if it's shorter than length.
153
154
```javascript { .api }
155
/**
156
* Pads `string` on the right side if it's shorter than `length`. Padding
157
* characters are truncated if they exceed `length`.
158
* @param string - The string to pad
159
* @param length - The padding length (defaults to 0)
160
* @param chars - The string used as padding (defaults to " ")
161
* @returns Returns the padded string
162
*/
163
function padEnd(string?: string, length?: number, chars?: string): string;
164
```
165
166
### Pad Start
167
168
Pads string on the left side if it's shorter than length.
169
170
```javascript { .api }
171
/**
172
* Pads `string` on the left side if it's shorter than `length`. Padding
173
* characters are truncated if they exceed `length`.
174
* @param string - The string to pad
175
* @param length - The padding length (defaults to 0)
176
* @param chars - The string used as padding (defaults to " ")
177
* @returns Returns the padded string
178
*/
179
function padStart(string?: string, length?: number, chars?: string): string;
180
```
181
182
### Parse Int
183
184
Converts string to an integer of the specified radix.
185
186
```javascript { .api }
187
/**
188
* Converts `string` to an integer of the specified radix. If `radix` is
189
* `undefined` or `0`, a `radix` of `10` is used unless `value` is a
190
* hexadecimal, in which case a `radix` of `16` is used.
191
* @param string - The string to convert
192
* @param radix - The radix to interpret `value` by (defaults to 10)
193
* @returns Returns the converted integer
194
*/
195
function parseInt(string: string, radix?: number): number;
196
```
197
198
### Repeat
199
200
Repeats the given string n times.
201
202
```javascript { .api }
203
/**
204
* Repeats the given string `n` times.
205
* @param string - The string to repeat
206
* @param n - The number of times to repeat the string (defaults to 1)
207
* @returns Returns the repeated string
208
*/
209
function repeat(string?: string, n?: number): string;
210
```
211
212
### Replace
213
214
Replaces matches for pattern in string with replacement.
215
216
```javascript { .api }
217
/**
218
* Replaces matches for `pattern` in `string` with `replacement`.
219
* @param string - The string to modify
220
* @param pattern - The pattern to replace
221
* @param replacement - The match replacement
222
* @returns Returns the modified string
223
*/
224
function replace(
225
string: string,
226
pattern: string | RegExp,
227
replacement: string | ((substring: string, ...args: any[]) => string)
228
): string;
229
```
230
231
### Snake Case
232
233
Converts string to snake case.
234
235
```javascript { .api }
236
/**
237
* Converts `string` to
238
* [snake case](https://en.wikipedia.org/wiki/Snake_case).
239
* @param string - The string to convert
240
* @returns Returns the snake cased string
241
*/
242
function snakeCase(string?: string): string;
243
```
244
245
### Split
246
247
Splits string by separator.
248
249
```javascript { .api }
250
/**
251
* Splits `string` by `separator`.
252
* @param string - The string to split
253
* @param separator - The separator pattern to split by
254
* @param limit - The length to truncate results to
255
* @returns Returns the string segments
256
*/
257
function split(string?: string, separator?: string | RegExp, limit?: number): string[];
258
```
259
260
### Start Case
261
262
Converts string to start case.
263
264
```javascript { .api }
265
/**
266
* Converts `string` to
267
* [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
268
* @param string - The string to convert
269
* @returns Returns the start cased string
270
*/
271
function startCase(string?: string): string;
272
```
273
274
### Starts With
275
276
Checks if string starts with the given target string.
277
278
```javascript { .api }
279
/**
280
* Checks if `string` starts with the given target string.
281
* @param string - The string to inspect
282
* @param target - The string to search for
283
* @param position - The position to search from (defaults to 0)
284
* @returns Returns `true` if `string` starts with `target`, else `false`
285
*/
286
function startsWith(string?: string, target?: string, position?: number): boolean;
287
```
288
289
### Template
290
291
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.
292
293
```javascript { .api }
294
/**
295
* Creates a compiled template function that can interpolate data properties
296
* in "interpolate" delimiters, HTML-escape interpolated data properties in
297
* "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 string
300
* @param options - The options object
301
* @returns Returns the compiled template function
302
*/
303
function template(string?: string, options?: TemplateOptions): TemplateExecutor;
304
305
interface TemplateOptions {
306
/** The HTML "escape" delimiter */
307
escape?: RegExp;
308
/** The "evaluate" delimiter */
309
evaluate?: RegExp;
310
/** The "interpolate" delimiter */
311
interpolate?: RegExp;
312
/** Used to import variables into the compiled template */
313
variable?: string;
314
/** Used to reference the data object in the template text */
315
imports?: any;
316
}
317
318
interface TemplateExecutor {
319
(data?: any): string;
320
source: string;
321
}
322
```
323
324
### To Lower
325
326
Converts string, as a whole, to lower case just like String#toLowerCase.
327
328
```javascript { .api }
329
/**
330
* Converts `string`, as a whole, to lower case just like
331
* [String#toLowerCase](https://mdn.io/toLowerCase).
332
* @param string - The string to convert
333
* @returns Returns the lower cased string
334
*/
335
function toLower(string?: string): string;
336
```
337
338
### To Upper
339
340
Converts string, as a whole, to upper case just like String#toUpperCase.
341
342
```javascript { .api }
343
/**
344
* Converts `string`, as a whole, to upper case just like
345
* [String#toUpperCase](https://mdn.io/toUpperCase).
346
* @param string - The string to convert
347
* @returns Returns the upper cased string
348
*/
349
function toUpper(string?: string): string;
350
```
351
352
### Trim
353
354
Removes leading and trailing whitespace or specified characters from string.
355
356
```javascript { .api }
357
/**
358
* Removes leading and trailing whitespace or specified characters from `string`.
359
* @param string - The string to trim
360
* @param chars - The characters to trim (defaults to whitespace)
361
* @returns Returns the trimmed string
362
*/
363
function trim(string?: string, chars?: string): string;
364
```
365
366
### Trim End
367
368
Removes trailing whitespace or specified characters from string.
369
370
```javascript { .api }
371
/**
372
* Removes trailing whitespace or specified characters from `string`.
373
* @param string - The string to trim
374
* @param chars - The characters to trim (defaults to whitespace)
375
* @returns Returns the trimmed string
376
*/
377
function trimEnd(string?: string, chars?: string): string;
378
```
379
380
### Trim Start
381
382
Removes leading whitespace or specified characters from string.
383
384
```javascript { .api }
385
/**
386
* Removes leading whitespace or specified characters from `string`.
387
* @param string - The string to trim
388
* @param chars - The characters to trim (defaults to whitespace)
389
* @returns Returns the trimmed string
390
*/
391
function trimStart(string?: string, chars?: string): string;
392
```
393
394
### Truncate
395
396
Truncates string if it's longer than the given maximum string length.
397
398
```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 omission
402
* string which defaults to "...".
403
* @param string - The string to truncate
404
* @param options - The options object
405
* @returns Returns the truncated string
406
*/
407
function truncate(string?: string, options?: TruncateOptions): string;
408
409
interface TruncateOptions {
410
/** The maximum string length (defaults to 30) */
411
length?: number;
412
/** The string to indicate text is omitted (defaults to "...") */
413
omission?: string;
414
/** The separator pattern to truncate to */
415
separator?: string | RegExp;
416
}
417
```
418
419
### Unescape
420
421
The inverse of escape; this method converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; in string to their corresponding characters.
422
423
```javascript { .api }
424
/**
425
* The inverse of `escape`; this method converts the HTML entities
426
* `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
427
* their corresponding characters.
428
* @param string - The string to unescape
429
* @returns Returns the unescaped string
430
*/
431
function unescape(string?: string): string;
432
```
433
434
### Upper Case
435
436
Converts string, as space separated words, to upper case.
437
438
```javascript { .api }
439
/**
440
* Converts `string`, as space separated words, to upper case.
441
* @param string - The string to convert
442
* @returns Returns the upper cased string
443
*/
444
function upperCase(string?: string): string;
445
```
446
447
### Upper First
448
449
Converts the first character of string to upper case.
450
451
```javascript { .api }
452
/**
453
* Converts the first character of `string` to upper case.
454
* @param string - The string to convert
455
* @returns Returns the converted string
456
*/
457
function upperFirst(string?: string): string;
458
```
459
460
### Words
461
462
Splits string into an array of its words.
463
464
```javascript { .api }
465
/**
466
* Splits `string` into an array of its words.
467
* @param string - The string to inspect
468
* @param pattern - The pattern to match words
469
* @returns Returns the words of `string`
470
*/
471
function words(string?: string, pattern?: string | RegExp): string[];
472
```