@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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +539 -203
  3. package/dist/index.d.ts +24 -16
  4. package/dist/index.js +3 -1
  5. package/dist/index.js.map +25 -0
  6. package/package.json +22 -14
  7. package/dist/capitalizeWord.d.ts +0 -2
  8. package/dist/capitalizeWord.d.ts.map +0 -1
  9. package/dist/dataURLtoFile.d.ts +0 -2
  10. package/dist/dataURLtoFile.d.ts.map +0 -1
  11. package/dist/formatRelativeNumber.d.ts +0 -5
  12. package/dist/formatRelativeNumber.d.ts.map +0 -1
  13. package/dist/index.d.ts.map +0 -1
  14. package/dist/millisecondsToHMS.d.ts +0 -2
  15. package/dist/millisecondsToHMS.d.ts.map +0 -1
  16. package/dist/parseEnvVars.d.ts +0 -2
  17. package/dist/parseEnvVars.d.ts.map +0 -1
  18. package/dist/parseString.d.ts +0 -2
  19. package/dist/parseString.d.ts.map +0 -1
  20. package/dist/random.d.ts +0 -6
  21. package/dist/random.d.ts.map +0 -1
  22. package/dist/secondsToHMS.d.ts +0 -2
  23. package/dist/secondsToHMS.d.ts.map +0 -1
  24. package/dist/secondsToMS.d.ts +0 -2
  25. package/dist/secondsToMS.d.ts.map +0 -1
  26. package/dist/sleep.d.ts +0 -2
  27. package/dist/sleep.d.ts.map +0 -1
  28. package/dist/splitToWords.d.ts +0 -2
  29. package/dist/splitToWords.d.ts.map +0 -1
  30. package/dist/toCamelCase.d.ts +0 -2
  31. package/dist/toCamelCase.d.ts.map +0 -1
  32. package/dist/toKebabCase.d.ts +0 -2
  33. package/dist/toKebabCase.d.ts.map +0 -1
  34. package/dist/toPascalCase.d.ts +0 -2
  35. package/dist/toPascalCase.d.ts.map +0 -1
  36. package/dist/trim.d.ts +0 -2
  37. package/dist/trim.d.ts.map +0 -1
  38. package/src/capitalizeWord.ts +0 -3
  39. package/src/dataURLtoFile.ts +0 -12
  40. package/src/formatRelativeNumber.ts +0 -7
  41. package/src/index.ts +0 -15
  42. package/src/millisecondsToHMS.ts +0 -16
  43. package/src/parseEnvVars.ts +0 -14
  44. package/src/parseString.ts +0 -47
  45. package/src/random.ts +0 -13
  46. package/src/secondsToHMS.ts +0 -16
  47. package/src/secondsToMS.ts +0 -5
  48. package/src/sleep.ts +0 -3
  49. package/src/splitToWords.ts +0 -14
  50. package/src/toCamelCase.ts +0 -8
  51. package/src/toKebabCase.ts +0 -6
  52. package/src/toPascalCase.ts +0 -7
  53. package/src/trim.ts +0 -8
  54. package/tests/capitalizeWord.spec.ts +0 -163
  55. package/tests/dataURLtoFile.spec.ts +0 -472
  56. package/tests/formatRelativeNumber.spec.ts +0 -303
  57. package/tests/millisecondsToHMS.spec.ts +0 -209
  58. package/tests/parseEnvVars.spec.ts +0 -468
  59. package/tests/parseString.spec.ts +0 -377
  60. package/tests/random.spec.ts +0 -422
  61. package/tests/secondsToHMS.spec.ts +0 -341
  62. package/tests/secondsToMS.spec.ts +0 -467
  63. package/tests/splitToWords.spec.ts +0 -359
  64. package/tests/toCamelCase.spec.ts +0 -526
  65. package/tests/toKebabCase.spec.ts +0 -664
  66. package/tests/toPascalCase.spec.ts +0 -721
  67. package/tests/trim.spec.ts +0 -486
  68. package/tsconfig.build.json +0 -14
  69. package/tsconfig.json +0 -11
@@ -1,526 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { toCamelCase } from "@/index";
3
-
4
- describe("toCamelCase", () => {
5
- describe("basic functionality", () => {
6
- test("should convert simple lowercase words", () => {
7
- expect(toCamelCase("hello world")).toBe("helloWorld");
8
- });
9
-
10
- test("should convert capitalized words", () => {
11
- expect(toCamelCase("Hello World")).toBe("helloWorld");
12
- });
13
-
14
- test("should convert single word to lowercase", () => {
15
- expect(toCamelCase("hello")).toBe("hello");
16
- });
17
-
18
- test("should convert single capitalized word to lowercase", () => {
19
- expect(toCamelCase("Hello")).toBe("hello");
20
- });
21
-
22
- test("should handle empty string", () => {
23
- expect(toCamelCase("")).toBe("");
24
- });
25
-
26
- test("should handle whitespace only", () => {
27
- expect(toCamelCase(" ")).toBe("");
28
- });
29
-
30
- test("should convert multiple words", () => {
31
- expect(toCamelCase("hello world test")).toBe("helloWorldTest");
32
- });
33
-
34
- test("should handle mixed case input", () => {
35
- expect(toCamelCase("HeLLo WoRLd")).toBe("heLLoWoRLd");
36
- });
37
- });
38
-
39
- describe("already camelCase input", () => {
40
- test("should handle already camelCase string", () => {
41
- expect(toCamelCase("camelCase")).toBe("camelCase");
42
- });
43
-
44
- test("should handle PascalCase string", () => {
45
- expect(toCamelCase("PascalCase")).toBe("pascalCase");
46
- });
47
-
48
- test("should handle complex camelCase", () => {
49
- expect(toCamelCase("getUserProfile")).toBe("getUserProfile");
50
- });
51
-
52
- test("should handle camelCase with numbers", () => {
53
- expect(toCamelCase("user123Profile")).toBe("user123Profile");
54
- });
55
- });
56
-
57
- describe("snake_case conversion", () => {
58
- test("should convert simple snake_case", () => {
59
- expect(toCamelCase("hello_world")).toBe("helloWorld");
60
- });
61
-
62
- test("should convert multiple snake_case words", () => {
63
- expect(toCamelCase("hello_world_test")).toBe("helloWorldTest");
64
- });
65
-
66
- test("should convert uppercase snake_case", () => {
67
- expect(toCamelCase("HELLO_WORLD")).toBe("helloWorld");
68
- });
69
-
70
- test("should convert mixed case snake_case", () => {
71
- expect(toCamelCase("Hello_World_Test")).toBe("helloWorldTest");
72
- });
73
-
74
- test("should handle leading underscore", () => {
75
- expect(toCamelCase("_hello_world")).toBe("helloWorld");
76
- });
77
-
78
- test("should handle trailing underscore", () => {
79
- expect(toCamelCase("hello_world_")).toBe("helloWorld");
80
- });
81
-
82
- test("should handle multiple underscores", () => {
83
- expect(toCamelCase("hello__world")).toBe("helloWorld");
84
- });
85
- });
86
-
87
- describe("kebab-case conversion", () => {
88
- test("should convert simple kebab-case", () => {
89
- expect(toCamelCase("hello-world")).toBe("helloWorld");
90
- });
91
-
92
- test("should convert multiple kebab-case words", () => {
93
- expect(toCamelCase("hello-world-test")).toBe("helloWorldTest");
94
- });
95
-
96
- test("should convert uppercase kebab-case", () => {
97
- expect(toCamelCase("HELLO-WORLD")).toBe("helloWorld");
98
- });
99
-
100
- test("should convert mixed case kebab-case", () => {
101
- expect(toCamelCase("Hello-World-Test")).toBe("helloWorldTest");
102
- });
103
-
104
- test("should handle leading hyphen", () => {
105
- expect(toCamelCase("-hello-world")).toBe("helloWorld");
106
- });
107
-
108
- test("should handle trailing hyphen", () => {
109
- expect(toCamelCase("hello-world-")).toBe("helloWorld");
110
- });
111
-
112
- test("should handle multiple hyphens", () => {
113
- expect(toCamelCase("hello--world")).toBe("helloWorld");
114
- });
115
- });
116
-
117
- describe("dot.case conversion", () => {
118
- test("should convert dot separated words", () => {
119
- expect(toCamelCase("hello.world")).toBe("helloWorld");
120
- });
121
-
122
- test("should convert multiple dot separated words", () => {
123
- expect(toCamelCase("hello.world.test")).toBe("helloWorldTest");
124
- });
125
-
126
- test("should convert mixed case dot separated", () => {
127
- expect(toCamelCase("Hello.World.Test")).toBe("helloWorldTest");
128
- });
129
-
130
- test("should handle leading dot", () => {
131
- expect(toCamelCase(".hello.world")).toBe("helloWorld");
132
- });
133
-
134
- test("should handle trailing dot", () => {
135
- expect(toCamelCase("hello.world.")).toBe("helloWorld");
136
- });
137
- });
138
-
139
- describe("numbers handling", () => {
140
- test("should handle words with numbers", () => {
141
- expect(toCamelCase("hello123 world456")).toBe("hello123World456");
142
- });
143
-
144
- test("should handle standalone numbers", () => {
145
- expect(toCamelCase("hello 123 world")).toBe("hello123World");
146
- });
147
-
148
- test("should handle numbers at start", () => {
149
- expect(toCamelCase("123 hello world")).toBe("123HelloWorld");
150
- });
151
-
152
- test("should handle version-like patterns", () => {
153
- expect(toCamelCase("version 1.2.3")).toBe("version123");
154
- });
155
-
156
- test("should handle mixed numbers and letters", () => {
157
- expect(toCamelCase("user123 profile456 test")).toBe("user123Profile456Test");
158
- });
159
- });
160
-
161
- describe("acronyms handling", () => {
162
- test("should handle simple acronyms", () => {
163
- expect(toCamelCase("ID")).toBe("id");
164
- });
165
-
166
- test("should handle URL acronym", () => {
167
- expect(toCamelCase("URL")).toBe("url");
168
- });
169
-
170
- test("should handle acronym with words", () => {
171
- expect(toCamelCase("HTML Element")).toBe("htmlElement");
172
- });
173
-
174
- test("should handle multiple acronyms", () => {
175
- expect(toCamelCase("HTTP API")).toBe("httpApi");
176
- });
177
-
178
- test("should handle acronym at end", () => {
179
- expect(toCamelCase("parse XML")).toBe("parseXml");
180
- });
181
-
182
- test("should handle mixed acronyms and words", () => {
183
- expect(toCamelCase("XML Http Request")).toBe("xmlHttpRequest");
184
- });
185
-
186
- test("should handle complex acronym patterns", () => {
187
- expect(toCamelCase("XMLParser")).toBe("xmlParser");
188
- expect(toCamelCase("HTTPApi")).toBe("httpApi");
189
- expect(toCamelCase("JSONData")).toBe("jsonData");
190
- });
191
- });
192
-
193
- describe("mixed separators", () => {
194
- test("should handle mixed hyphen and underscore", () => {
195
- expect(toCamelCase("hello-world_test")).toBe("helloWorldTest");
196
- });
197
-
198
- test("should handle mixed separators with spaces", () => {
199
- expect(toCamelCase("hello-world test_case")).toBe("helloWorldTestCase");
200
- });
201
-
202
- test("should handle all separator types", () => {
203
- expect(toCamelCase("hello-world_test.case api")).toBe("helloWorldTestCaseApi");
204
- });
205
-
206
- test("should handle multiple mixed separators", () => {
207
- expect(toCamelCase("hello--world__test..case")).toBe("helloWorldTestCase");
208
- });
209
- });
210
-
211
- describe("special characters", () => {
212
- test("should ignore punctuation", () => {
213
- expect(toCamelCase("hello, world!")).toBe("helloWorld");
214
- });
215
-
216
- test("should handle parentheses", () => {
217
- expect(toCamelCase("hello(world)")).toBe("helloWorld");
218
- });
219
-
220
- test("should handle brackets", () => {
221
- expect(toCamelCase("hello[world]")).toBe("helloWorld");
222
- });
223
-
224
- test("should handle braces", () => {
225
- expect(toCamelCase("hello{world}")).toBe("helloWorld");
226
- });
227
-
228
- test("should handle quotes", () => {
229
- expect(toCamelCase("'hello' \"world\"")).toBe("helloWorld");
230
- });
231
-
232
- test("should handle mixed special characters", () => {
233
- expect(toCamelCase("hello@#$%world^&*test")).toBe("helloWorldTest");
234
- });
235
- });
236
-
237
- describe("unicode and international characters", () => {
238
- test("should handle accented characters", () => {
239
- expect(toCamelCase("café résumé")).toBe("caféRésumé");
240
- });
241
-
242
- test("should handle cyrillic characters", () => {
243
- expect(toCamelCase("привет мир")).toBe("приветМир");
244
- });
245
-
246
- test("should handle chinese characters", () => {
247
- expect(toCamelCase("你好 世界")).toBe("你好世界");
248
- });
249
-
250
- test("should handle arabic characters", () => {
251
- expect(toCamelCase("مرحبا بالعالم")).toBe("مرحبابالعالم");
252
- });
253
-
254
- test("should handle mixed latin and unicode", () => {
255
- expect(toCamelCase("hello 世界")).toBe("hello世界");
256
- });
257
-
258
- test("should handle emoji with text", () => {
259
- expect(toCamelCase("hello 😀 world")).toBe("helloWorld");
260
- });
261
- });
262
-
263
- describe("whitespace handling", () => {
264
- test("should handle leading whitespace", () => {
265
- expect(toCamelCase(" hello world")).toBe("helloWorld");
266
- });
267
-
268
- test("should handle trailing whitespace", () => {
269
- expect(toCamelCase("hello world ")).toBe("helloWorld");
270
- });
271
-
272
- test("should handle multiple spaces", () => {
273
- expect(toCamelCase("hello world")).toBe("helloWorld");
274
- });
275
-
276
- test("should handle tabs", () => {
277
- expect(toCamelCase("hello\tworld")).toBe("helloWorld");
278
- });
279
-
280
- test("should handle newlines", () => {
281
- expect(toCamelCase("hello\nworld")).toBe("helloWorld");
282
- });
283
-
284
- test("should handle mixed whitespace", () => {
285
- expect(toCamelCase(" hello \t world \n test ")).toBe("helloWorldTest");
286
- });
287
-
288
- test("should handle only whitespace", () => {
289
- expect(toCamelCase(" \t\n ")).toBe("");
290
- });
291
- });
292
-
293
- describe("edge cases", () => {
294
- test("should handle single character", () => {
295
- expect(toCamelCase("a")).toBe("a");
296
- });
297
-
298
- test("should handle single uppercase character", () => {
299
- expect(toCamelCase("A")).toBe("a");
300
- });
301
-
302
- test("should handle single number", () => {
303
- expect(toCamelCase("1")).toBe("1");
304
- });
305
-
306
- test("should handle alternating case input", () => {
307
- expect(toCamelCase("aBcDeFg")).toBe("aBcDeFg");
308
- });
309
-
310
- test("should handle all uppercase input", () => {
311
- expect(toCamelCase("HELLO")).toBe("hello");
312
- });
313
-
314
- test("should handle all lowercase input", () => {
315
- expect(toCamelCase("hello")).toBe("hello");
316
- });
317
-
318
- test("should handle numbers only", () => {
319
- expect(toCamelCase("123456")).toBe("123456");
320
- });
321
-
322
- test("should handle special characters only", () => {
323
- expect(toCamelCase("!@#$%^&*()")).toBe("");
324
- });
325
-
326
- test("should handle very short inputs", () => {
327
- expect(toCamelCase("a b")).toBe("aB");
328
- expect(toCamelCase("A B")).toBe("aB");
329
- expect(toCamelCase("1 2")).toBe("12");
330
- });
331
- });
332
-
333
- describe("real-world examples", () => {
334
- test("should convert JavaScript function names", () => {
335
- expect(toCamelCase("get element by id")).toBe("getElementById");
336
- expect(toCamelCase("add event listener")).toBe("addEventListener");
337
- expect(toCamelCase("query selector")).toBe("querySelector");
338
- });
339
-
340
- test("should convert CSS class names", () => {
341
- expect(toCamelCase("btn-primary")).toBe("btnPrimary");
342
- expect(toCamelCase("form-control")).toBe("formControl");
343
- expect(toCamelCase("navbar-brand")).toBe("navbarBrand");
344
- });
345
-
346
- test("should convert database column names", () => {
347
- expect(toCamelCase("user_id")).toBe("userId");
348
- expect(toCamelCase("created_at")).toBe("createdAt");
349
- expect(toCamelCase("first_name")).toBe("firstName");
350
- });
351
-
352
- test("should convert API endpoint names", () => {
353
- expect(toCamelCase("get user by id")).toBe("getUserById");
354
- expect(toCamelCase("create user profile")).toBe("createUserProfile");
355
- expect(toCamelCase("update password")).toBe("updatePassword");
356
- });
357
-
358
- test("should convert file names", () => {
359
- expect(toCamelCase("my-file.txt")).toBe("myFileTxt");
360
- expect(toCamelCase("user_profile.json")).toBe("userProfileJson");
361
- expect(toCamelCase("config-dev.yaml")).toBe("configDevYaml");
362
- });
363
-
364
- test("should convert package names", () => {
365
- expect(toCamelCase("react-dom")).toBe("reactDom");
366
- expect(toCamelCase("lodash.get")).toBe("lodashGet");
367
- expect(toCamelCase("@types/node")).toBe("typesNode");
368
- });
369
-
370
- test("should convert technical terms", () => {
371
- expect(toCamelCase("XML Http Request")).toBe("xmlHttpRequest");
372
- expect(toCamelCase("JSON Web Token")).toBe("jsonWebToken");
373
- expect(toCamelCase("REST API")).toBe("restApi");
374
- });
375
- });
376
-
377
- describe("parametrized tests", () => {
378
- test.each([
379
- ["hello world", "helloWorld"],
380
- ["Hello World", "helloWorld"],
381
- ["HELLO WORLD", "helloWorld"],
382
- ["hello-world", "helloWorld"],
383
- ["hello_world", "helloWorld"],
384
- ["hello.world", "helloWorld"],
385
- ["helloWorld", "helloWorld"],
386
- ["HelloWorld", "helloWorld"],
387
- ["hello", "hello"],
388
- ["Hello", "hello"],
389
- ["HELLO", "hello"],
390
- ["hello123", "hello123"],
391
- ["123hello", "123Hello"],
392
- ["XMLParser", "xmlParser"],
393
- ["parseXML", "parseXml"],
394
- ["HTML5", "html5"],
395
- ["getUserById", "getUserById"],
396
- ["user_id", "userId"],
397
- ["API", "api"],
398
- ["", ""],
399
- [" ", ""],
400
- ["a", "a"],
401
- ["A", "a"],
402
- ["1", "1"],
403
- ["hello world test", "helloWorldTest"],
404
- ["HELLO_WORLD_TEST", "helloWorldTest"],
405
- ["hello-world-test", "helloWorldTest"],
406
- ["hello.world.test", "helloWorldTest"],
407
- ])("toCamelCase(%s) should return %s", (input, expected) => {
408
- expect(toCamelCase(input)).toBe(expected);
409
- });
410
- });
411
-
412
- describe("complex patterns", () => {
413
- test("should handle complex mixed patterns", () => {
414
- expect(toCamelCase("parse HTML5 Document")).toBe("parseHtml5Document");
415
- });
416
-
417
- test("should handle version numbers", () => {
418
- expect(toCamelCase("v1.2.3-beta")).toBe("v123Beta");
419
- });
420
-
421
- test("should handle technical terms with versions", () => {
422
- expect(toCamelCase("XMLHttpRequestV2")).toBe("xmlHttpRequestV2");
423
- });
424
-
425
- test("should handle namespace-like patterns", () => {
426
- expect(toCamelCase("com.example.MyClass")).toBe("comExampleMyClass");
427
- });
428
-
429
- test("should handle URL-like patterns", () => {
430
- expect(toCamelCase("http API Server")).toBe("httpApiServer");
431
- });
432
-
433
- test("should handle constant names", () => {
434
- expect(toCamelCase("MAX_USER_COUNT")).toBe("maxUserCount");
435
- });
436
-
437
- test("should handle mixed case with numbers and separators", () => {
438
- expect(toCamelCase("iPhone14-Pro_Max")).toBe("iPhone14ProMax");
439
- });
440
-
441
- test("should handle complex real-world examples", () => {
442
- expect(toCamelCase("XMLHttpRequest-v2.0_beta")).toBe("xmlHttpRequestV20Beta");
443
- expect(toCamelCase("getUserProfile_byId-V3")).toBe("getUserProfileByIdV3");
444
- expect(toCamelCase("API_KEY_VERSION_2")).toBe("apiKeyVersion2");
445
- });
446
- });
447
-
448
- describe("function behavior", () => {
449
- test("should return string type", () => {
450
- const result = toCamelCase("test");
451
- expect(typeof result).toBe("string");
452
- });
453
-
454
- test("should not mutate input", () => {
455
- const original = "hello world";
456
- const result = toCamelCase(original);
457
- expect(original).toBe("hello world");
458
- expect(result).toBe("helloWorld");
459
- });
460
-
461
- test("should return same result for multiple calls", () => {
462
- const input = "hello world";
463
- const result1 = toCamelCase(input);
464
- const result2 = toCamelCase(input);
465
- expect(result1).toBe(result2);
466
- expect(result1).toBe("helloWorld");
467
- });
468
-
469
- test("should handle very long strings", () => {
470
- const longString = `${"hello ".repeat(1000)}world`;
471
- const result = toCamelCase(longString);
472
- expect(result).toMatch(/^hello/);
473
- expect(result).toMatch(/World$/);
474
- expect(result).not.toContain(" ");
475
- });
476
-
477
- test("should be consistent with dependencies", () => {
478
- // Test consistency with splitToWords and capitalizeWord behavior
479
- expect(toCamelCase("XMLParser")).toBe("xmlParser");
480
- expect(toCamelCase("parseXML")).toBe("parseXml");
481
- expect(toCamelCase("HTMLElement")).toBe("htmlElement");
482
- });
483
- });
484
-
485
- describe("performance considerations", () => {
486
- test("should handle empty input efficiently", () => {
487
- expect(toCamelCase("")).toBe("");
488
- });
489
-
490
- test("should handle whitespace-only input efficiently", () => {
491
- expect(toCamelCase(" \n\t ")).toBe("");
492
- });
493
-
494
- test("should handle special characters only efficiently", () => {
495
- expect(toCamelCase("!@#$%^&*()_+-=[]{}|;:,.<>?")).toBe("");
496
- });
497
-
498
- test("should handle single word efficiently", () => {
499
- expect(toCamelCase("hello")).toBe("hello");
500
- expect(toCamelCase("Hello")).toBe("hello");
501
- expect(toCamelCase("HELLO")).toBe("hello");
502
- });
503
- });
504
-
505
- describe("integration with dependencies", () => {
506
- test("should work correctly with splitToWords edge cases", () => {
507
- // Test cases that rely heavily on splitToWords behavior
508
- expect(toCamelCase("XMLHttpRequest")).toBe("xmlHttpRequest");
509
- expect(toCamelCase("parseHTML5Document")).toBe("parseHtml5Document");
510
- expect(toCamelCase("getUserProfile123")).toBe("getUserProfile123");
511
- });
512
-
513
- test("should work correctly with capitalizeWord edge cases", () => {
514
- // Test cases that rely heavily on capitalizeWord behavior
515
- expect(toCamelCase("hello world")).toBe("helloWorld");
516
- expect(toCamelCase("HELLO WORLD")).toBe("helloWorld");
517
- expect(toCamelCase("café résumé")).toBe("caféRésumé");
518
- });
519
-
520
- test("should handle trim behavior correctly", () => {
521
- expect(toCamelCase(" hello world ")).toBe("helloWorld");
522
- expect(toCamelCase("\t\nhello world\t\n")).toBe("helloWorld");
523
- expect(toCamelCase(" ")).toBe("");
524
- });
525
- });
526
- });