@ooneex/utils 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +539 -203
- package/dist/index.d.ts +24 -16
- package/dist/index.js +3 -1
- package/dist/index.js.map +25 -0
- package/package.json +22 -14
- package/dist/capitalizeWord.d.ts +0 -2
- package/dist/capitalizeWord.d.ts.map +0 -1
- package/dist/dataURLtoFile.d.ts +0 -2
- package/dist/dataURLtoFile.d.ts.map +0 -1
- package/dist/formatRelativeNumber.d.ts +0 -5
- package/dist/formatRelativeNumber.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/millisecondsToHMS.d.ts +0 -2
- package/dist/millisecondsToHMS.d.ts.map +0 -1
- package/dist/parseEnvVars.d.ts +0 -2
- package/dist/parseEnvVars.d.ts.map +0 -1
- package/dist/parseString.d.ts +0 -2
- package/dist/parseString.d.ts.map +0 -1
- package/dist/random.d.ts +0 -6
- package/dist/random.d.ts.map +0 -1
- package/dist/secondsToHMS.d.ts +0 -2
- package/dist/secondsToHMS.d.ts.map +0 -1
- package/dist/secondsToMS.d.ts +0 -2
- package/dist/secondsToMS.d.ts.map +0 -1
- package/dist/sleep.d.ts +0 -2
- package/dist/sleep.d.ts.map +0 -1
- package/dist/splitToWords.d.ts +0 -2
- package/dist/splitToWords.d.ts.map +0 -1
- package/dist/toCamelCase.d.ts +0 -2
- package/dist/toCamelCase.d.ts.map +0 -1
- package/dist/toKebabCase.d.ts +0 -2
- package/dist/toKebabCase.d.ts.map +0 -1
- package/dist/toPascalCase.d.ts +0 -2
- package/dist/toPascalCase.d.ts.map +0 -1
- package/dist/trim.d.ts +0 -2
- package/dist/trim.d.ts.map +0 -1
- package/src/capitalizeWord.ts +0 -3
- package/src/dataURLtoFile.ts +0 -12
- package/src/formatRelativeNumber.ts +0 -7
- package/src/index.ts +0 -15
- package/src/millisecondsToHMS.ts +0 -16
- package/src/parseEnvVars.ts +0 -14
- package/src/parseString.ts +0 -47
- package/src/random.ts +0 -13
- package/src/secondsToHMS.ts +0 -16
- package/src/secondsToMS.ts +0 -5
- package/src/sleep.ts +0 -3
- package/src/splitToWords.ts +0 -14
- package/src/toCamelCase.ts +0 -8
- package/src/toKebabCase.ts +0 -6
- package/src/toPascalCase.ts +0 -7
- package/src/trim.ts +0 -8
- package/tests/capitalizeWord.spec.ts +0 -163
- package/tests/dataURLtoFile.spec.ts +0 -472
- package/tests/formatRelativeNumber.spec.ts +0 -303
- package/tests/millisecondsToHMS.spec.ts +0 -209
- package/tests/parseEnvVars.spec.ts +0 -468
- package/tests/parseString.spec.ts +0 -377
- package/tests/random.spec.ts +0 -422
- package/tests/secondsToHMS.spec.ts +0 -341
- package/tests/secondsToMS.spec.ts +0 -467
- package/tests/splitToWords.spec.ts +0 -359
- package/tests/toCamelCase.spec.ts +0 -526
- package/tests/toKebabCase.spec.ts +0 -664
- package/tests/toPascalCase.spec.ts +0 -721
- package/tests/trim.spec.ts +0 -486
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -11
|
@@ -1,664 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { toKebabCase } from "@/index";
|
|
3
|
-
|
|
4
|
-
describe("toKebabCase", () => {
|
|
5
|
-
describe("basic functionality", () => {
|
|
6
|
-
test("should convert simple lowercase words", () => {
|
|
7
|
-
expect(toKebabCase("hello world")).toBe("hello-world");
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test("should convert capitalized words", () => {
|
|
11
|
-
expect(toKebabCase("Hello World")).toBe("hello-world");
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test("should convert single word to lowercase", () => {
|
|
15
|
-
expect(toKebabCase("hello")).toBe("hello");
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("should convert single capitalized word to lowercase", () => {
|
|
19
|
-
expect(toKebabCase("Hello")).toBe("hello");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("should handle empty string", () => {
|
|
23
|
-
expect(toKebabCase("")).toBe("");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("should handle whitespace only", () => {
|
|
27
|
-
expect(toKebabCase(" ")).toBe("");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("should convert multiple words", () => {
|
|
31
|
-
expect(toKebabCase("hello world test")).toBe("hello-world-test");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("should handle mixed case input", () => {
|
|
35
|
-
expect(toKebabCase("HeLLo WoRLd")).toBe("he-l-lo-wo-r-ld");
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("camelCase and PascalCase conversion", () => {
|
|
40
|
-
test("should convert camelCase string", () => {
|
|
41
|
-
expect(toKebabCase("camelCase")).toBe("camel-case");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("should convert PascalCase string", () => {
|
|
45
|
-
expect(toKebabCase("PascalCase")).toBe("pascal-case");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("should convert complex camelCase", () => {
|
|
49
|
-
expect(toKebabCase("getUserProfile")).toBe("get-user-profile");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("should convert camelCase with numbers", () => {
|
|
53
|
-
expect(toKebabCase("user123Profile")).toBe("user-123-profile");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("should handle single camelCase word", () => {
|
|
57
|
-
expect(toKebabCase("hello")).toBe("hello");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("should handle alternating case", () => {
|
|
61
|
-
expect(toKebabCase("aBcDeFg")).toBe("a-bc-de-fg");
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("snake_case conversion", () => {
|
|
66
|
-
test("should convert simple snake_case", () => {
|
|
67
|
-
expect(toKebabCase("hello_world")).toBe("hello-world");
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("should convert multiple snake_case words", () => {
|
|
71
|
-
expect(toKebabCase("hello_world_test")).toBe("hello-world-test");
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("should convert uppercase snake_case", () => {
|
|
75
|
-
expect(toKebabCase("HELLO_WORLD")).toBe("hello-world");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("should convert mixed case snake_case", () => {
|
|
79
|
-
expect(toKebabCase("Hello_World_Test")).toBe("hello-world-test");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("should handle leading underscore", () => {
|
|
83
|
-
expect(toKebabCase("_hello_world")).toBe("hello-world");
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("should handle trailing underscore", () => {
|
|
87
|
-
expect(toKebabCase("hello_world_")).toBe("hello-world");
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("should handle multiple underscores", () => {
|
|
91
|
-
expect(toKebabCase("hello__world")).toBe("hello-world");
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe("already kebab-case conversion", () => {
|
|
96
|
-
test("should handle simple kebab-case", () => {
|
|
97
|
-
expect(toKebabCase("hello-world")).toBe("hello-world");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("should convert uppercase kebab-case", () => {
|
|
101
|
-
expect(toKebabCase("HELLO-WORLD")).toBe("hello-world");
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test("should convert mixed case kebab-case", () => {
|
|
105
|
-
expect(toKebabCase("Hello-World-Test")).toBe("hello-world-test");
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("should handle leading hyphen", () => {
|
|
109
|
-
expect(toKebabCase("-hello-world")).toBe("hello-world");
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("should handle trailing hyphen", () => {
|
|
113
|
-
expect(toKebabCase("hello-world-")).toBe("hello-world");
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test("should handle multiple hyphens", () => {
|
|
117
|
-
expect(toKebabCase("hello--world")).toBe("hello-world");
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe("dot.case conversion", () => {
|
|
122
|
-
test("should convert dot separated words", () => {
|
|
123
|
-
expect(toKebabCase("hello.world")).toBe("hello-world");
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test("should convert multiple dot separated words", () => {
|
|
127
|
-
expect(toKebabCase("hello.world.test")).toBe("hello-world-test");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("should convert mixed case dot separated", () => {
|
|
131
|
-
expect(toKebabCase("Hello.World.Test")).toBe("hello-world-test");
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("should handle leading dot", () => {
|
|
135
|
-
expect(toKebabCase(".hello.world")).toBe("hello-world");
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test("should handle trailing dot", () => {
|
|
139
|
-
expect(toKebabCase("hello.world.")).toBe("hello-world");
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("numbers handling", () => {
|
|
144
|
-
test("should handle words with numbers", () => {
|
|
145
|
-
expect(toKebabCase("hello123 world456")).toBe("hello-123-world-456");
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test("should handle standalone numbers", () => {
|
|
149
|
-
expect(toKebabCase("hello 123 world")).toBe("hello-123-world");
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test("should handle numbers at start", () => {
|
|
153
|
-
expect(toKebabCase("123 hello world")).toBe("123-hello-world");
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test("should handle version-like patterns", () => {
|
|
157
|
-
expect(toKebabCase("version 1.2.3")).toBe("version-1-2-3");
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
test("should handle mixed numbers and letters", () => {
|
|
161
|
-
expect(toKebabCase("user123 profile456 test")).toBe("user-123-profile-456-test");
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test("should handle camelCase with numbers", () => {
|
|
165
|
-
expect(toKebabCase("version2Beta3")).toBe("version-2-beta-3");
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe("acronyms handling", () => {
|
|
170
|
-
test("should handle simple acronyms", () => {
|
|
171
|
-
expect(toKebabCase("ID")).toBe("id");
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test("should handle URL acronym", () => {
|
|
175
|
-
expect(toKebabCase("URL")).toBe("url");
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test("should handle acronym with words", () => {
|
|
179
|
-
expect(toKebabCase("HTML Element")).toBe("html-element");
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test("should handle multiple acronyms", () => {
|
|
183
|
-
expect(toKebabCase("HTTP API")).toBe("http-api");
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
test("should handle acronym at end", () => {
|
|
187
|
-
expect(toKebabCase("parse XML")).toBe("parse-xml");
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test("should handle mixed acronyms and words", () => {
|
|
191
|
-
expect(toKebabCase("XML Http Request")).toBe("xml-http-request");
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test("should handle complex acronym patterns", () => {
|
|
195
|
-
expect(toKebabCase("XMLParser")).toBe("xml-parser");
|
|
196
|
-
expect(toKebabCase("HTTPApi")).toBe("http-api");
|
|
197
|
-
expect(toKebabCase("JSONData")).toBe("json-data");
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
test("should handle acronym patterns correctly", () => {
|
|
201
|
-
expect(toKebabCase("parseHTML5Document")).toBe("parse-html-5-document");
|
|
202
|
-
expect(toKebabCase("XMLHttpRequestV2")).toBe("xml-http-request-v-2");
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
describe("mixed separators", () => {
|
|
207
|
-
test("should handle mixed hyphen and underscore", () => {
|
|
208
|
-
expect(toKebabCase("hello-world_test")).toBe("hello-world-test");
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
test("should handle mixed separators with spaces", () => {
|
|
212
|
-
expect(toKebabCase("hello-world test_case")).toBe("hello-world-test-case");
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
test("should handle all separator types", () => {
|
|
216
|
-
expect(toKebabCase("hello-world_test.case api")).toBe("hello-world-test-case-api");
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
test("should handle multiple mixed separators", () => {
|
|
220
|
-
expect(toKebabCase("hello--world__test..case")).toBe("hello-world-test-case");
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test("should handle camelCase with separators", () => {
|
|
224
|
-
expect(toKebabCase("helloWorld_testCase-apiKey")).toBe("hello-world-test-case-api-key");
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
describe("special characters", () => {
|
|
229
|
-
test("should ignore punctuation", () => {
|
|
230
|
-
expect(toKebabCase("hello, world!")).toBe("hello-world");
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
test("should handle parentheses", () => {
|
|
234
|
-
expect(toKebabCase("hello(world)")).toBe("hello-world");
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
test("should handle brackets", () => {
|
|
238
|
-
expect(toKebabCase("hello[world]")).toBe("hello-world");
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
test("should handle braces", () => {
|
|
242
|
-
expect(toKebabCase("hello{world}")).toBe("hello-world");
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
test("should handle quotes", () => {
|
|
246
|
-
expect(toKebabCase("'hello' \"world\"")).toBe("hello-world");
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
test("should handle mixed special characters", () => {
|
|
250
|
-
expect(toKebabCase("hello@#$%world^&*test")).toBe("hello-world-test");
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test("should handle complex punctuation patterns", () => {
|
|
254
|
-
expect(toKebabCase("hello... world??? test!!!")).toBe("hello-world-test");
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
describe("unicode and international characters", () => {
|
|
259
|
-
test("should handle accented characters", () => {
|
|
260
|
-
expect(toKebabCase("café résumé")).toBe("café-résumé");
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
test("should handle cyrillic characters", () => {
|
|
264
|
-
expect(toKebabCase("привет мир")).toBe("привет-мир");
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
test("should handle chinese characters", () => {
|
|
268
|
-
expect(toKebabCase("你好 世界")).toBe("你好-世界");
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
test("should handle arabic characters", () => {
|
|
272
|
-
expect(toKebabCase("مرحبا بالعالم")).toBe("مرحبا-بالعالم");
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
test("should handle mixed latin and unicode", () => {
|
|
276
|
-
expect(toKebabCase("hello 世界")).toBe("hello-世界");
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
test("should handle emoji with text", () => {
|
|
280
|
-
expect(toKebabCase("hello 😀 world")).toBe("hello-world");
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
test("should handle unicode camelCase", () => {
|
|
284
|
-
expect(toKebabCase("caféWorld")).toBe("café-world");
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
describe("whitespace handling", () => {
|
|
289
|
-
test("should handle leading whitespace", () => {
|
|
290
|
-
expect(toKebabCase(" hello world")).toBe("hello-world");
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
test("should handle trailing whitespace", () => {
|
|
294
|
-
expect(toKebabCase("hello world ")).toBe("hello-world");
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
test("should handle multiple spaces", () => {
|
|
298
|
-
expect(toKebabCase("hello world")).toBe("hello-world");
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
test("should handle tabs", () => {
|
|
302
|
-
expect(toKebabCase("hello\tworld")).toBe("hello-world");
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
test("should handle newlines", () => {
|
|
306
|
-
expect(toKebabCase("hello\nworld")).toBe("hello-world");
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
test("should handle mixed whitespace", () => {
|
|
310
|
-
expect(toKebabCase(" hello \t world \n test ")).toBe("hello-world-test");
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
test("should handle only whitespace", () => {
|
|
314
|
-
expect(toKebabCase(" \t\n ")).toBe("");
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
describe("edge cases", () => {
|
|
319
|
-
test("should handle single character", () => {
|
|
320
|
-
expect(toKebabCase("a")).toBe("a");
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
test("should handle single uppercase character", () => {
|
|
324
|
-
expect(toKebabCase("A")).toBe("a");
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
test("should handle single number", () => {
|
|
328
|
-
expect(toKebabCase("1")).toBe("1");
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
test("should handle alternating case input", () => {
|
|
332
|
-
expect(toKebabCase("aBcDeFg")).toBe("a-bc-de-fg");
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
test("should handle all uppercase input", () => {
|
|
336
|
-
expect(toKebabCase("HELLO")).toBe("hello");
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
test("should handle all lowercase input", () => {
|
|
340
|
-
expect(toKebabCase("hello")).toBe("hello");
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
test("should handle numbers only", () => {
|
|
344
|
-
expect(toKebabCase("123456")).toBe("123456");
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
test("should handle special characters only", () => {
|
|
348
|
-
expect(toKebabCase("!@#$%^&*()")).toBe("");
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
test("should handle very short inputs", () => {
|
|
352
|
-
expect(toKebabCase("a b")).toBe("a-b");
|
|
353
|
-
expect(toKebabCase("A B")).toBe("a-b");
|
|
354
|
-
expect(toKebabCase("1 2")).toBe("1-2");
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
test("should handle hyphen only", () => {
|
|
358
|
-
expect(toKebabCase("-")).toBe("");
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
test("should handle multiple hyphens only", () => {
|
|
362
|
-
expect(toKebabCase("---")).toBe("");
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
describe("real-world examples", () => {
|
|
367
|
-
test("should convert JavaScript function names", () => {
|
|
368
|
-
expect(toKebabCase("getElementById")).toBe("get-element-by-id");
|
|
369
|
-
expect(toKebabCase("addEventListener")).toBe("add-event-listener");
|
|
370
|
-
expect(toKebabCase("querySelector")).toBe("query-selector");
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
test("should convert CSS class names", () => {
|
|
374
|
-
expect(toKebabCase("btnPrimary")).toBe("btn-primary");
|
|
375
|
-
expect(toKebabCase("formControl")).toBe("form-control");
|
|
376
|
-
expect(toKebabCase("navbarBrand")).toBe("navbar-brand");
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
test("should convert database column names", () => {
|
|
380
|
-
expect(toKebabCase("userId")).toBe("user-id");
|
|
381
|
-
expect(toKebabCase("createdAt")).toBe("created-at");
|
|
382
|
-
expect(toKebabCase("firstName")).toBe("first-name");
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
test("should convert API endpoint names", () => {
|
|
386
|
-
expect(toKebabCase("getUserById")).toBe("get-user-by-id");
|
|
387
|
-
expect(toKebabCase("createUserProfile")).toBe("create-user-profile");
|
|
388
|
-
expect(toKebabCase("updatePassword")).toBe("update-password");
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
test("should convert file names", () => {
|
|
392
|
-
expect(toKebabCase("myFile.txt")).toBe("my-file-txt");
|
|
393
|
-
expect(toKebabCase("userProfile.json")).toBe("user-profile-json");
|
|
394
|
-
expect(toKebabCase("configDev.yaml")).toBe("config-dev-yaml");
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
test("should convert package names", () => {
|
|
398
|
-
expect(toKebabCase("reactDom")).toBe("react-dom");
|
|
399
|
-
expect(toKebabCase("lodashGet")).toBe("lodash-get");
|
|
400
|
-
expect(toKebabCase("typesNode")).toBe("types-node");
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
test("should convert technical terms", () => {
|
|
404
|
-
expect(toKebabCase("XMLHttpRequest")).toBe("xml-http-request");
|
|
405
|
-
expect(toKebabCase("jsonWebToken")).toBe("json-web-token");
|
|
406
|
-
expect(toKebabCase("restAPI")).toBe("rest-api");
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
test("should convert component names", () => {
|
|
410
|
-
expect(toKebabCase("UserProfile")).toBe("user-profile");
|
|
411
|
-
expect(toKebabCase("NavbarComponent")).toBe("navbar-component");
|
|
412
|
-
expect(toKebabCase("ButtonGroup")).toBe("button-group");
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
describe("parametrized tests", () => {
|
|
417
|
-
test.each([
|
|
418
|
-
["hello world", "hello-world"],
|
|
419
|
-
["Hello World", "hello-world"],
|
|
420
|
-
["HELLO WORLD", "hello-world"],
|
|
421
|
-
["hello-world", "hello-world"],
|
|
422
|
-
["hello_world", "hello-world"],
|
|
423
|
-
["hello.world", "hello-world"],
|
|
424
|
-
["helloWorld", "hello-world"],
|
|
425
|
-
["HelloWorld", "hello-world"],
|
|
426
|
-
["camelCase", "camel-case"],
|
|
427
|
-
["PascalCase", "pascal-case"],
|
|
428
|
-
["hello", "hello"],
|
|
429
|
-
["Hello", "hello"],
|
|
430
|
-
["HELLO", "hello"],
|
|
431
|
-
["hello123", "hello-123"],
|
|
432
|
-
["123hello", "123-hello"],
|
|
433
|
-
["XMLParser", "xml-parser"],
|
|
434
|
-
["parseXML", "parse-xml"],
|
|
435
|
-
["HTML5", "html-5"],
|
|
436
|
-
["getUserById", "get-user-by-id"],
|
|
437
|
-
["user_id", "user-id"],
|
|
438
|
-
["API", "api"],
|
|
439
|
-
["", ""],
|
|
440
|
-
[" ", ""],
|
|
441
|
-
["a", "a"],
|
|
442
|
-
["A", "a"],
|
|
443
|
-
["1", "1"],
|
|
444
|
-
["hello world test", "hello-world-test"],
|
|
445
|
-
["HELLO_WORLD_TEST", "hello-world-test"],
|
|
446
|
-
["hello-world-test", "hello-world-test"],
|
|
447
|
-
["hello.world.test", "hello-world-test"],
|
|
448
|
-
["helloWorldTest", "hello-world-test"],
|
|
449
|
-
["HTTPSProxy", "https-proxy"],
|
|
450
|
-
["iPhone14Pro", "i-phone-14-pro"],
|
|
451
|
-
])("toKebabCase(%s) should return %s", (input, expected) => {
|
|
452
|
-
expect(toKebabCase(input)).toBe(expected);
|
|
453
|
-
});
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
describe("complex patterns", () => {
|
|
457
|
-
test("should handle complex mixed patterns", () => {
|
|
458
|
-
expect(toKebabCase("parseHTML5Document")).toBe("parse-html-5-document");
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
test("should handle version numbers", () => {
|
|
462
|
-
expect(toKebabCase("v1.2.3-beta")).toBe("v-1-2-3-beta");
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
test("should handle technical terms with versions", () => {
|
|
466
|
-
expect(toKebabCase("XMLHttpRequestV2")).toBe("xml-http-request-v-2");
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
test("should handle namespace-like patterns", () => {
|
|
470
|
-
expect(toKebabCase("com.example.MyClass")).toBe("com-example-my-class");
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
test("should handle URL-like patterns", () => {
|
|
474
|
-
expect(toKebabCase("httpAPIServer")).toBe("http-api-server");
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
test("should handle constant names", () => {
|
|
478
|
-
expect(toKebabCase("MAX_USER_COUNT")).toBe("max-user-count");
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
test("should handle mixed case with numbers and separators", () => {
|
|
482
|
-
expect(toKebabCase("iPhone14-Pro_Max")).toBe("i-phone-14-pro-max");
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
test("should handle complex real-world examples", () => {
|
|
486
|
-
expect(toKebabCase("XMLHttpRequest-v2.0_beta")).toBe("xml-http-request-v-2-0-beta");
|
|
487
|
-
expect(toKebabCase("getUserProfile_byId-V3")).toBe("get-user-profile-by-id-v-3");
|
|
488
|
-
expect(toKebabCase("API_KEY_VERSION_2")).toBe("api-key-version-2");
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
test("should handle framework component names", () => {
|
|
492
|
-
expect(toKebabCase("MyAwesomeReactComponent")).toBe("my-awesome-react-component");
|
|
493
|
-
expect(toKebabCase("VueJSAppRouter")).toBe("vue-js-app-router");
|
|
494
|
-
expect(toKebabCase("AngularMaterialButton")).toBe("angular-material-button");
|
|
495
|
-
});
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
describe("function behavior", () => {
|
|
499
|
-
test("should return string type", () => {
|
|
500
|
-
const result = toKebabCase("test");
|
|
501
|
-
expect(typeof result).toBe("string");
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
test("should not mutate input", () => {
|
|
505
|
-
const original = "helloWorld";
|
|
506
|
-
const result = toKebabCase(original);
|
|
507
|
-
expect(original).toBe("helloWorld");
|
|
508
|
-
expect(result).toBe("hello-world");
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
test("should return same result for multiple calls", () => {
|
|
512
|
-
const input = "helloWorld";
|
|
513
|
-
const result1 = toKebabCase(input);
|
|
514
|
-
const result2 = toKebabCase(input);
|
|
515
|
-
expect(result1).toBe(result2);
|
|
516
|
-
expect(result1).toBe("hello-world");
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
test("should handle very long strings", () => {
|
|
520
|
-
const longString = `${"hello".repeat(1000)}World`;
|
|
521
|
-
const result = toKebabCase(longString);
|
|
522
|
-
expect(result).toMatch(/^hello/);
|
|
523
|
-
expect(result).toMatch(/world$/);
|
|
524
|
-
expect(result).toContain("-");
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
test("should be consistent with dependencies", () => {
|
|
528
|
-
// Test consistency with splitToWords behavior
|
|
529
|
-
expect(toKebabCase("XMLParser")).toBe("xml-parser");
|
|
530
|
-
expect(toKebabCase("parseXML")).toBe("parse-xml");
|
|
531
|
-
expect(toKebabCase("HTMLElement")).toBe("html-element");
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
test("should handle consecutive calls consistently", () => {
|
|
535
|
-
const input = "complexTestCase123";
|
|
536
|
-
const result1 = toKebabCase(input);
|
|
537
|
-
const result2 = toKebabCase(input);
|
|
538
|
-
const result3 = toKebabCase(input);
|
|
539
|
-
|
|
540
|
-
expect(result1).toBe(result2);
|
|
541
|
-
expect(result2).toBe(result3);
|
|
542
|
-
expect(result1).toBe("complex-test-case-123");
|
|
543
|
-
});
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
describe("performance considerations", () => {
|
|
547
|
-
test("should handle empty input efficiently", () => {
|
|
548
|
-
expect(toKebabCase("")).toBe("");
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
test("should handle whitespace-only input efficiently", () => {
|
|
552
|
-
expect(toKebabCase(" \n\t ")).toBe("");
|
|
553
|
-
});
|
|
554
|
-
|
|
555
|
-
test("should handle special characters only efficiently", () => {
|
|
556
|
-
expect(toKebabCase("!@#$%^&*()_+-=[]{}|;:,.<>?")).toBe("");
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
test("should handle single word efficiently", () => {
|
|
560
|
-
expect(toKebabCase("hello")).toBe("hello");
|
|
561
|
-
expect(toKebabCase("Hello")).toBe("hello");
|
|
562
|
-
expect(toKebabCase("HELLO")).toBe("hello");
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
test("should handle already kebab-case efficiently", () => {
|
|
566
|
-
expect(toKebabCase("hello-world")).toBe("hello-world");
|
|
567
|
-
expect(toKebabCase("hello-world-test")).toBe("hello-world-test");
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
describe("integration with dependencies", () => {
|
|
572
|
-
test("should work correctly with splitToWords edge cases", () => {
|
|
573
|
-
// Test cases that rely heavily on splitToWords behavior
|
|
574
|
-
expect(toKebabCase("XMLHttpRequest")).toBe("xml-http-request");
|
|
575
|
-
expect(toKebabCase("parseHTML5Document")).toBe("parse-html-5-document");
|
|
576
|
-
expect(toKebabCase("getUserProfile123")).toBe("get-user-profile-123");
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
test("should handle trim behavior correctly", () => {
|
|
580
|
-
expect(toKebabCase(" hello world ")).toBe("hello-world");
|
|
581
|
-
expect(toKebabCase("\t\nhelloWorld\t\n")).toBe("hello-world");
|
|
582
|
-
expect(toKebabCase(" ")).toBe("");
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
test("should work with splitToWords acronym handling", () => {
|
|
586
|
-
expect(toKebabCase("HTTPSProxy")).toBe("https-proxy");
|
|
587
|
-
expect(toKebabCase("APIKeyManager")).toBe("api-key-manager");
|
|
588
|
-
expect(toKebabCase("JSONWebToken")).toBe("json-web-token");
|
|
589
|
-
});
|
|
590
|
-
|
|
591
|
-
test("should handle splitToWords number patterns", () => {
|
|
592
|
-
expect(toKebabCase("version2Beta3Release")).toBe("version-2-beta-3-release");
|
|
593
|
-
expect(toKebabCase("HTML5Parser")).toBe("html-5-parser");
|
|
594
|
-
expect(toKebabCase("CSS3Animation")).toBe("css-3-animation");
|
|
595
|
-
});
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
describe("CSS class name scenarios", () => {
|
|
599
|
-
test("should convert component class names", () => {
|
|
600
|
-
expect(toKebabCase("buttonPrimary")).toBe("button-primary");
|
|
601
|
-
expect(toKebabCase("cardHeader")).toBe("card-header");
|
|
602
|
-
expect(toKebabCase("modalDialog")).toBe("modal-dialog");
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
test("should convert state class names", () => {
|
|
606
|
-
expect(toKebabCase("isActive")).toBe("is-active");
|
|
607
|
-
expect(toKebabCase("hasError")).toBe("has-error");
|
|
608
|
-
expect(toKebabCase("isDisabled")).toBe("is-disabled");
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
test("should convert size and variant classes", () => {
|
|
612
|
-
expect(toKebabCase("buttonLarge")).toBe("button-large");
|
|
613
|
-
expect(toKebabCase("textSmall")).toBe("text-small");
|
|
614
|
-
expect(toKebabCase("iconMedium")).toBe("icon-medium");
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
test("should convert BEM-style class names", () => {
|
|
618
|
-
expect(toKebabCase("blockElementModifier")).toBe("block-element-modifier");
|
|
619
|
-
expect(toKebabCase("navbarBrandLogo")).toBe("navbar-brand-logo");
|
|
620
|
-
expect(toKebabCase("cardBodyContent")).toBe("card-body-content");
|
|
621
|
-
});
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
describe("API endpoint scenarios", () => {
|
|
625
|
-
test("should convert REST endpoint names", () => {
|
|
626
|
-
expect(toKebabCase("getUsers")).toBe("get-users");
|
|
627
|
-
expect(toKebabCase("postUser")).toBe("post-user");
|
|
628
|
-
expect(toKebabCase("putUserProfile")).toBe("put-user-profile");
|
|
629
|
-
expect(toKebabCase("deleteUserAccount")).toBe("delete-user-account");
|
|
630
|
-
});
|
|
631
|
-
|
|
632
|
-
test("should convert GraphQL resolver names", () => {
|
|
633
|
-
expect(toKebabCase("userProfile")).toBe("user-profile");
|
|
634
|
-
expect(toKebabCase("userPosts")).toBe("user-posts");
|
|
635
|
-
expect(toKebabCase("createUserMutation")).toBe("create-user-mutation");
|
|
636
|
-
});
|
|
637
|
-
|
|
638
|
-
test("should convert service names", () => {
|
|
639
|
-
expect(toKebabCase("userService")).toBe("user-service");
|
|
640
|
-
expect(toKebabCase("authenticationService")).toBe("authentication-service");
|
|
641
|
-
expect(toKebabCase("emailNotificationService")).toBe("email-notification-service");
|
|
642
|
-
});
|
|
643
|
-
});
|
|
644
|
-
|
|
645
|
-
describe("file and directory scenarios", () => {
|
|
646
|
-
test("should convert file names", () => {
|
|
647
|
-
expect(toKebabCase("userController.js")).toBe("user-controller-js");
|
|
648
|
-
expect(toKebabCase("apiRoutes.ts")).toBe("api-routes-ts");
|
|
649
|
-
expect(toKebabCase("databaseConfig.json")).toBe("database-config-json");
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
test("should convert directory names", () => {
|
|
653
|
-
expect(toKebabCase("userComponents")).toBe("user-components");
|
|
654
|
-
expect(toKebabCase("sharedUtilities")).toBe("shared-utilities");
|
|
655
|
-
expect(toKebabCase("testFixtures")).toBe("test-fixtures");
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
test("should convert package names", () => {
|
|
659
|
-
expect(toKebabCase("myAwesomePackage")).toBe("my-awesome-package");
|
|
660
|
-
expect(toKebabCase("reactUtilityLibrary")).toBe("react-utility-library");
|
|
661
|
-
expect(toKebabCase("nodeJSHelpers")).toBe("node-js-helpers");
|
|
662
|
-
});
|
|
663
|
-
});
|
|
664
|
-
});
|