-
Notifications
You must be signed in to change notification settings - Fork 0
/
kebab-case-converter.html
199 lines (170 loc) · 7.29 KB
/
kebab-case-converter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Open Source Kebab Case Converter</title>
<meta name="description" content="Kebab Case Converter is a free online open source tool that converts your text to kebab-case, making it ideal for programming, URLs, and other technical formats.">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
h1, h2 {
color: #333;
text-align: center;
}
h1 {
margin-bottom: 0.5em;
}
h2 {
margin-top: 1.5em;
margin-bottom: 0.5em;
}
.convertcase {
margin: 20px 0;
}
textarea {
width: 100%;
min-height: 200px;
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-family: inherit;
font-size: 1rem;
box-sizing: border-box;
}
button {
display: block;
margin: 5px auto;
padding: 8px 16px;
border: 1px solid #ddd;
border-radius: 4px;
background: #f5f5f5;
cursor: pointer;
font-size: 1rem;
transition: background 0.2s ease;
}
button:hover {
background: #e5e5e5;
}
code {
background: #f5f5f5;
padding: 2px 4px;
border-radius: 3px;
font-family: monospace;
}
ul {
padding-left: 20px;
}
hr {
border: none;
border-top: 1px solid #ddd;
margin: 2em 0;
}
.footer {
margin-top: 2em;
padding-top: 1em;
border-top: 1px solid #ddd;
font-size: 0.9em;
color: #666;
}
.links {
text-align: center;
margin: 1em 0;
}
.links a {
margin: 0 10px;
color: #0366d6;
text-decoration: none;
}
.links a:hover {
text-decoration: underline;
}
.license {
font-size: 0.8em;
color: #666;
margin-top: 2em;
padding: 1em;
background: #f8f8f8;
border-radius: 4px;
}
</style>
</head>
<body>
<h1>Kebab Case Converter</h1>
<h2>Convert Text to Kebab Case</h2>
<p>Welcome to <b>Kebab Case Converter</b>, a free online open source tool that transforms your text into kebab-case format. Simply type or paste your text in the box below and click the convert button to generate kebab case text for your programming, URLs, and file naming needs.</p>
<form class="convertcase" onsubmit="return false;">
<textarea id="stringbox" autofocus></textarea>
<br>
<button type="button" onclick="convertstring(stringbox, 'kebabcase')" title="Convert to Kebab Case">To Kebab Case</button>
</form>
<p style="text-align: center"><b>Word Count:</b> <span id="wordcount"></span>, <b>Character Count:</b> <span id="charcount"></span></p>
<hr>
<h2>What is Kebab Case?</h2>
<p>Kebab case is a text format that replaces spaces with hyphens and converts all text to lowercase. It's commonly used in programming, especially in URL paths, CSS class names, and file naming conventions, as it improves readability by clearly separating words.</p>
<h2>Common Uses of Kebab Case</h2>
<ul>
<li><b>Web Development:</b> Used for naming CSS classes and IDs (e.g., <code>main-header</code>, <code>nav-item</code>).</li>
<li><b>URLs:</b> Enhances readability in URLs and improves SEO (e.g., <code>example.com/blog/latest-posts</code>).</li>
<li><b>File Names:</b> Creates clear, readable file names without spaces (e.g., <code>project-overview.pdf</code>, <code>default-avatar.png</code>).</li>
<li><b>Configuration Files:</b> Used in naming configuration and property files (e.g., <code>user-settings.yaml</code>, <code>max-connections.json</code>).</li>
</ul>
<div class="footer">
<div class="links">
<a href="https://caseconverter.cc/kebab-case-converter" target="_blank" rel="noopener noreferrer" title="Try the live version of Kebab Case Converter on CaseConverter.cc">Live Version of Kebab Case Converter</a>
<a href="https://github.com/caseconverter/Kebab-Case-Converter" target="_blank" rel="noopener noreferrer" title="View source code and contribute on GitHub">GitHub Repository</a>
</div>
<div class="license">
<h3>MIT License</h3>
<p>Copyright (c) 2024 <a href="https://caseconverter.cc/" target="_blank" rel="noopener noreferrer" title="Visit Case Converter's official website">Case Converter</a>.</p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.</p>
</div>
</div>
<script>
var stringbox = document.getElementById('stringbox');
var wordcountspan = document.getElementById('wordcount');
var charcountspan = document.getElementById('charcount');
function convertstring(textarea, action) {
if (action == 'kebabcase') {
textarea.value = toKebabCase(textarea.value);
}
wordandcharcount();
textarea.focus();
}
function toKebabCase(str) {
return str
.trim()
.toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^\w-]+/g, '');
}
function wordandcharcount() {
var trimmedString = stringbox.value.trim();
wordcountspan.innerHTML = trimmedString ? trimmedString.split(/\s+/).length : 0;
charcountspan.innerHTML = stringbox.value.length;
}
stringbox.addEventListener('input', wordandcharcount, false);
wordandcharcount();
</script>
</body>
</html>