0
# Lodash Kebab Case
1
2
Lodash Kebab Case is a standalone module that exports the lodash method `kebabCase` for converting strings to kebab-case format (lowercase words separated by hyphens). It handles various input formats including camelCase, PascalCase, snake_case, and strings with special characters or diacritical marks.
3
4
## Package Information
5
6
- **Package Name**: lodash.kebabcase
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash.kebabcase`
10
11
## Core Imports
12
13
```javascript
14
var kebabCase = require('lodash.kebabcase');
15
```
16
17
For ES modules (if supported by your environment):
18
19
```javascript
20
import kebabCase from 'lodash.kebabcase';
21
```
22
23
## Basic Usage
24
25
```javascript
26
var kebabCase = require('lodash.kebabcase');
27
28
// Convert camelCase
29
var result1 = kebabCase('fooBar');
30
// => 'foo-bar'
31
32
// Convert PascalCase
33
var result2 = kebabCase('FooBar');
34
// => 'foo-bar'
35
36
// Convert spaced strings
37
var result3 = kebabCase('Foo Bar');
38
// => 'foo-bar'
39
40
// Convert snake_case
41
var result4 = kebabCase('foo_bar');
42
// => 'foo-bar'
43
44
// Handle special characters
45
var result5 = kebabCase('__foo_bar__');
46
// => 'foo-bar'
47
48
// Handle empty strings
49
var result6 = kebabCase('');
50
// => ''
51
```
52
53
## Capabilities
54
55
### String Conversion
56
57
Converts a string to kebab-case format by removing diacritical marks, splitting into words, and joining with hyphens in lowercase.
58
59
```javascript { .api }
60
/**
61
* Converts string to kebab case.
62
* @param {string} [string=''] The string to convert.
63
* @returns {string} Returns the kebab cased string.
64
*/
65
function kebabCase(string)
66
```
67
68
**Parameters:**
69
- `string` (string, optional): The string to convert. Defaults to empty string if not provided.
70
71
**Returns:**
72
- (string): The kebab cased string with words separated by hyphens in lowercase.
73
74
**Usage Examples:**
75
76
```javascript
77
var kebabCase = require('lodash.kebabcase');
78
79
// Basic conversion
80
kebabCase('Foo Bar');
81
// => 'foo-bar'
82
83
kebabCase('fooBar');
84
// => 'foo-bar'
85
86
kebabCase('__FOO_BAR__');
87
// => 'foo-bar'
88
89
// Handling diacritical marks
90
kebabCase('café');
91
// => 'cafe'
92
93
// Unicode and special characters
94
kebabCase('résumé');
95
// => 'resume'
96
97
// Numbers and mixed content
98
kebabCase('foo2bar');
99
// => 'foo2bar'
100
101
// Edge cases
102
kebabCase('');
103
// => ''
104
105
kebabCase();
106
// => ''
107
108
kebabCase('a');
109
// => 'a'
110
```
111
112
**Behavior Notes:**
113
- Removes diacritical marks from characters using `lodash.deburr`
114
- Splits strings into words using `lodash.words`
115
- Converts all characters to lowercase
116
- Joins words with hyphens
117
- Handles various input formats: camelCase, PascalCase, snake_case, spaced strings
118
- Returns empty string for falsy inputs
119
- Preserves numbers and alphanumeric sequences