The lodash method kebabCase exported as a standalone Node.js module for converting strings to kebab-case format
npx @tessl/cli install tessl/npm-lodash.kebabcase@4.1.00
# Lodash Kebab Case
1
2
The lodash method `kebabCase` exported as a standalone Node.js module for converting strings to kebab-case format. It transforms strings to kebab case by splitting words on boundaries (camelCase, PascalCase, snake_case, spaces, etc.) and joining them with hyphens in lowercase.
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
The module exports the `kebabCase` function as the default export.
18
19
## Basic Usage
20
21
```javascript
22
var kebabCase = require('lodash.kebabcase');
23
24
// Convert different string formats to kebab-case
25
console.log(kebabCase('Foo Bar')); // => 'foo-bar'
26
console.log(kebabCase('fooBar')); // => 'foo-bar'
27
console.log(kebabCase('__FOO_BAR__')); // => 'foo-bar'
28
console.log(kebabCase('XMLHttpRequest')); // => 'xml-http-request'
29
```
30
31
## Capabilities
32
33
### String to Kebab Case Conversion
34
35
Converts strings to kebab case by splitting words and joining them with hyphens in lowercase.
36
37
```javascript { .api }
38
/**
39
* Converts string to kebab case
40
* @param {string} [string=''] - The string to convert
41
* @returns {string} Returns the kebab cased string
42
*/
43
function kebabCase(string = '')
44
```
45
46
**Examples:**
47
48
```javascript
49
kebabCase('Foo Bar');
50
// => 'foo-bar'
51
52
kebabCase('fooBar');
53
// => 'foo-bar'
54
55
kebabCase('__FOO_BAR__');
56
// => 'foo-bar'
57
58
kebabCase('XMLHttpRequest');
59
// => 'xml-http-request'
60
61
kebabCase('hello world 123');
62
// => 'hello-world-123'
63
64
kebabCase('camelCaseString');
65
// => 'camel-case-string'
66
67
kebabCase('PascalCaseString');
68
// => 'pascal-case-string'
69
70
kebabCase('snake_case_string');
71
// => 'snake-case-string'
72
73
kebabCase(' Multiple Spaces ');
74
// => 'multiple-spaces'
75
76
kebabCase('Special-Characters!@#');
77
// => 'special-characters'
78
79
kebabCase('unicode-café');
80
// => 'unicode-cafe'
81
82
kebabCase('');
83
// => ''
84
85
kebabCase();
86
// => ''
87
```
88
89
90