The lodash method _.startCase exported as a module for converting strings to start case format
npx @tessl/cli install tessl/npm-lodash.startcase@3.1.00
# Lodash StartCase
1
2
Lodash StartCase provides the `startCase` method from the Lodash utility library as a standalone module. The `startCase` function converts strings to start case format, where each word is capitalized and separated by spaces. It handles various input formats including camelCase, snake_case, kebab-case, and other delimited strings, transforming them into properly formatted title case text.
3
4
## Package Information
5
6
- **Package Name**: lodash.startcase
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash.startcase`
10
11
## Core Imports
12
13
```javascript
14
var startCase = require('lodash.startcase');
15
```
16
17
For ES modules (if supported):
18
19
```javascript
20
import startCase from 'lodash.startcase';
21
```
22
23
## Basic Usage
24
25
```javascript
26
var startCase = require('lodash.startcase');
27
28
// Convert camelCase
29
var result1 = startCase('fooBar');
30
// => 'Foo Bar'
31
32
// Convert kebab-case
33
var result2 = startCase('--foo-bar');
34
// => 'Foo Bar'
35
36
// Convert snake_case
37
var result3 = startCase('__foo_bar__');
38
// => 'Foo Bar'
39
40
// Convert space-separated
41
var result4 = startCase('foo bar');
42
// => 'Foo Bar'
43
44
// Handle all caps (converted to proper case)
45
var result5 = startCase('FOO BAR');
46
// => 'Foo Bar'
47
```
48
49
## Capabilities
50
51
### Start Case Conversion
52
53
Converts strings to start case format where each word is capitalized and separated by spaces.
54
55
```javascript { .api }
56
/**
57
* Converts string to start case.
58
* @param {string} [string=''] - The string to convert
59
* @returns {string} Returns the start cased string
60
*/
61
function startCase(string)
62
```
63
64
**Usage Examples:**
65
66
```javascript
67
var startCase = require('lodash.startcase');
68
69
// Basic conversions
70
startCase('fooBar');
71
// => 'Foo Bar'
72
73
startCase('foo-bar');
74
// => 'Foo Bar'
75
76
startCase('foo_bar');
77
// => 'Foo Bar'
78
79
startCase('foo bar');
80
// => 'Foo Bar'
81
82
// Handles various delimiters
83
startCase('--foo-bar--');
84
// => 'Foo Bar'
85
86
startCase('__foo_bar__');
87
// => 'Foo Bar'
88
89
// All caps (converted to proper case)
90
startCase('FOO BAR');
91
// => 'Foo Bar'
92
93
startCase('fOoBaR');
94
// => 'F Oo Ba R'
95
96
// Empty and null handling
97
startCase('');
98
// => ''
99
100
startCase();
101
// => ''
102
103
// Accented characters
104
startCase('café-münü');
105
// => 'Cafe Menu'
106
107
// Numbers and special characters
108
startCase('foo2bar');
109
// => 'Foo 2 Bar'
110
111
startCase('foo-bar-123');
112
// => 'Foo Bar 123'
113
```
114
115
## Implementation Details
116
117
The `startCase` function:
118
119
1. **Input Processing**: Accepts any input and converts it to a string
120
2. **Deburring**: Removes diacritical marks from Latin characters (café → cafe)
121
3. **Word Extraction**: Uses pattern matching to identify word boundaries across various formats:
122
- Camel case boundaries (fooBar → foo, Bar)
123
- Underscore delimiters (foo_bar → foo, bar)
124
- Hyphen delimiters (foo-bar → foo, bar)
125
- Space delimiters (foo bar → foo, bar)
126
- Mixed delimiters (__foo-bar__ → foo, bar)
127
4. **Capitalization**: Capitalizes the first character of each extracted word
128
5. **Joining**: Combines words with single spaces
129
130
## Error Handling
131
132
- **Null/Undefined Input**: Returns empty string
133
- **Non-String Input**: Automatically converted to string representation
134
- **Empty String**: Returns empty string
135
- **No Exceptions**: Function does not throw errors for any input type
136
137
## Performance Characteristics
138
139
- **Algorithm**: Single-pass processing with regex-based word extraction
140
- **Memory**: Minimal allocation, processes input once
141
- **Compatibility**: Works in all JavaScript environments (Node.js, browsers)
142
- **Dependencies**: Standalone module with no external dependencies