@ooneex/utils 0.0.6 → 0.0.8

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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +539 -203
  3. package/dist/index.d.ts +23 -16
  4. package/dist/index.js +3 -1
  5. package/dist/index.js.map +24 -0
  6. package/dist/ooneex-utils-0.0.8.tgz +0 -0
  7. package/package.json +23 -13
  8. package/dist/capitalizeWord.d.ts +0 -2
  9. package/dist/capitalizeWord.d.ts.map +0 -1
  10. package/dist/dataURLtoFile.d.ts +0 -2
  11. package/dist/dataURLtoFile.d.ts.map +0 -1
  12. package/dist/formatRelativeNumber.d.ts +0 -5
  13. package/dist/formatRelativeNumber.d.ts.map +0 -1
  14. package/dist/index.d.ts.map +0 -1
  15. package/dist/millisecondsToHMS.d.ts +0 -2
  16. package/dist/millisecondsToHMS.d.ts.map +0 -1
  17. package/dist/parseEnvVars.d.ts +0 -2
  18. package/dist/parseEnvVars.d.ts.map +0 -1
  19. package/dist/parseString.d.ts +0 -2
  20. package/dist/parseString.d.ts.map +0 -1
  21. package/dist/random.d.ts +0 -6
  22. package/dist/random.d.ts.map +0 -1
  23. package/dist/secondsToHMS.d.ts +0 -2
  24. package/dist/secondsToHMS.d.ts.map +0 -1
  25. package/dist/secondsToMS.d.ts +0 -2
  26. package/dist/secondsToMS.d.ts.map +0 -1
  27. package/dist/sleep.d.ts +0 -2
  28. package/dist/sleep.d.ts.map +0 -1
  29. package/dist/splitToWords.d.ts +0 -2
  30. package/dist/splitToWords.d.ts.map +0 -1
  31. package/dist/toCamelCase.d.ts +0 -2
  32. package/dist/toCamelCase.d.ts.map +0 -1
  33. package/dist/toKebabCase.d.ts +0 -2
  34. package/dist/toKebabCase.d.ts.map +0 -1
  35. package/dist/toPascalCase.d.ts +0 -2
  36. package/dist/toPascalCase.d.ts.map +0 -1
  37. package/dist/trim.d.ts +0 -2
  38. package/dist/trim.d.ts.map +0 -1
  39. package/src/capitalizeWord.ts +0 -3
  40. package/src/dataURLtoFile.ts +0 -12
  41. package/src/formatRelativeNumber.ts +0 -7
  42. package/src/index.ts +0 -15
  43. package/src/millisecondsToHMS.ts +0 -16
  44. package/src/parseEnvVars.ts +0 -14
  45. package/src/parseString.ts +0 -47
  46. package/src/random.ts +0 -13
  47. package/src/secondsToHMS.ts +0 -16
  48. package/src/secondsToMS.ts +0 -5
  49. package/src/sleep.ts +0 -3
  50. package/src/splitToWords.ts +0 -14
  51. package/src/toCamelCase.ts +0 -8
  52. package/src/toKebabCase.ts +0 -6
  53. package/src/toPascalCase.ts +0 -7
  54. package/src/trim.ts +0 -8
  55. package/tests/capitalizeWord.spec.ts +0 -163
  56. package/tests/dataURLtoFile.spec.ts +0 -472
  57. package/tests/formatRelativeNumber.spec.ts +0 -303
  58. package/tests/millisecondsToHMS.spec.ts +0 -209
  59. package/tests/parseEnvVars.spec.ts +0 -468
  60. package/tests/parseString.spec.ts +0 -377
  61. package/tests/random.spec.ts +0 -422
  62. package/tests/secondsToHMS.spec.ts +0 -341
  63. package/tests/secondsToMS.spec.ts +0 -467
  64. package/tests/splitToWords.spec.ts +0 -359
  65. package/tests/toCamelCase.spec.ts +0 -526
  66. package/tests/toKebabCase.spec.ts +0 -664
  67. package/tests/toPascalCase.spec.ts +0 -721
  68. package/tests/trim.spec.ts +0 -486
  69. package/tsconfig.build.json +0 -14
  70. package/tsconfig.json +0 -11
@@ -1,341 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { secondsToHMS } from "@/index";
3
-
4
- describe("secondsToHMS", () => {
5
- describe("basic functionality", () => {
6
- test("should convert seconds only (< 1 minute)", () => {
7
- expect(secondsToHMS(5)).toBe("5");
8
- expect(secondsToHMS(30)).toBe("30");
9
- expect(secondsToHMS(59)).toBe("59");
10
- });
11
-
12
- test("should convert minutes and seconds (< 1 hour)", () => {
13
- expect(secondsToHMS(60)).toBe("1:00");
14
- expect(secondsToHMS(90)).toBe("1:30");
15
- expect(secondsToHMS(3599)).toBe("59:59");
16
- });
17
-
18
- test("should convert hours, minutes and seconds (>= 1 hour)", () => {
19
- expect(secondsToHMS(3600)).toBe("1:00:00");
20
- expect(secondsToHMS(3661)).toBe("1:01:01");
21
- expect(secondsToHMS(7200)).toBe("2:00:00");
22
- });
23
-
24
- test("should handle zero seconds", () => {
25
- expect(secondsToHMS(0)).toBe("0");
26
- });
27
- });
28
-
29
- describe("formatting", () => {
30
- test("should pad minutes with leading zero when hours present", () => {
31
- expect(secondsToHMS(3660)).toBe("1:01:00");
32
- expect(secondsToHMS(3605)).toBe("1:00:05");
33
- expect(secondsToHMS(32400 + 60 + 5)).toBe("9:01:05");
34
- });
35
-
36
- test("should pad seconds with leading zero when minutes present", () => {
37
- expect(secondsToHMS(65)).toBe("1:05");
38
- expect(secondsToHMS(600 + 1)).toBe("10:01");
39
- expect(secondsToHMS(3600 + 60 + 1)).toBe("1:01:01");
40
- });
41
-
42
- test("should not pad single digits when no higher unit present", () => {
43
- expect(secondsToHMS(1)).toBe("1");
44
- expect(secondsToHMS(5)).toBe("5");
45
- expect(secondsToHMS(9)).toBe("9");
46
- });
47
-
48
- test("should handle double-digit values correctly", () => {
49
- expect(secondsToHMS(10)).toBe("10");
50
- expect(secondsToHMS(600 + 15)).toBe("10:15");
51
- expect(secondsToHMS(3600 + 600 + 15)).toBe("1:10:15");
52
- });
53
- });
54
-
55
- describe("edge cases", () => {
56
- test("should handle decimal seconds by flooring", () => {
57
- expect(secondsToHMS(1.5)).toBe("1"); // 1.5 seconds -> 1 second
58
- expect(secondsToHMS(1.999)).toBe("1"); // 1.999 seconds -> 1 second
59
- expect(secondsToHMS(61.5)).toBe("1:01"); // 61.5 seconds -> 1:01
60
- expect(secondsToHMS(3661.9)).toBe("1:01:01"); // 3661.9 seconds -> 1:01:01
61
- });
62
-
63
- test("should handle very small decimal values", () => {
64
- expect(secondsToHMS(0.001)).toBe("0");
65
- expect(secondsToHMS(0.5)).toBe("0");
66
- expect(secondsToHMS(0.999)).toBe("0");
67
- });
68
-
69
- test("should handle large hour values", () => {
70
- expect(secondsToHMS(24 * 3600)).toBe("24:00:00"); // 24 hours
71
- expect(secondsToHMS(100 * 3600)).toBe("100:00:00"); // 100 hours
72
- expect(secondsToHMS(999 * 3600)).toBe("999:00:00"); // 999 hours
73
- });
74
-
75
- test("should handle maximum safe integer values", () => {
76
- const largeValue = 999999999; // 999,999,999 seconds
77
- const result = secondsToHMS(largeValue);
78
- expect(typeof result).toBe("string");
79
- expect(result).toMatch(/^\d+:\d{2}:\d{2}$/);
80
- });
81
- });
82
-
83
- describe("mathematical precision", () => {
84
- test("should floor decimal seconds", () => {
85
- expect(secondsToHMS(1.01)).toBe("1");
86
- expect(secondsToHMS(1.99)).toBe("1");
87
- expect(secondsToHMS(2.01)).toBe("2");
88
- });
89
-
90
- test("should calculate minutes correctly", () => {
91
- expect(secondsToHMS(60)).toBe("1:00");
92
- expect(secondsToHMS(119)).toBe("1:59");
93
- expect(secondsToHMS(120)).toBe("2:00");
94
- });
95
-
96
- test("should calculate hours correctly", () => {
97
- expect(secondsToHMS(3600)).toBe("1:00:00");
98
- expect(secondsToHMS(7199)).toBe("1:59:59");
99
- expect(secondsToHMS(7200)).toBe("2:00:00");
100
- });
101
-
102
- test("should handle floating point precision edge cases", () => {
103
- expect(secondsToHMS(59.999999)).toBe("59");
104
- expect(secondsToHMS(60.000001)).toBe("1:00");
105
- expect(secondsToHMS(3599.999999)).toBe("59:59");
106
- expect(secondsToHMS(3600.000001)).toBe("1:00:00");
107
- });
108
- });
109
-
110
- describe("parametrized tests", () => {
111
- test.each([
112
- [0, "0"],
113
- [1, "1"],
114
- [10, "10"],
115
- [60, "1:00"],
116
- [90, "1:30"],
117
- [3600, "1:00:00"],
118
- [3661, "1:01:01"],
119
- [7200, "2:00:00"],
120
- [86400, "24:00:00"], // 1 day
121
- [90061, "25:01:01"], // 25 hours 1 minute 1 second
122
- [1.5, "1"], // decimal handling
123
- [61.7, "1:01"], // decimal handling with minutes
124
- [3661.9, "1:01:01"], // decimal handling with hours
125
- ])("secondsToHMS(%i) should return %s", (input, expected) => {
126
- expect(secondsToHMS(input)).toBe(expected);
127
- });
128
- });
129
-
130
- describe("real world examples", () => {
131
- test("should handle common video durations", () => {
132
- expect(secondsToHMS(30)).toBe("30"); // 30 second video
133
- expect(secondsToHMS(300)).toBe("5:00"); // 5 minute video
134
- expect(secondsToHMS(1800)).toBe("30:00"); // 30 minute video
135
- expect(secondsToHMS(5400)).toBe("1:30:00"); // 1.5 hour movie
136
- expect(secondsToHMS(7200)).toBe("2:00:00"); // 2 hour movie
137
- });
138
-
139
- test("should handle common music track durations", () => {
140
- expect(secondsToHMS(180)).toBe("3:00"); // 3 minute song
141
- expect(secondsToHMS(213)).toBe("3:33"); // 3:33 song
142
- expect(secondsToHMS(267)).toBe("4:27"); // 4:27 song
143
- expect(secondsToHMS(150)).toBe("2:30"); // 2:30 song
144
- });
145
-
146
- test("should handle timer/stopwatch use cases", () => {
147
- expect(secondsToHMS(5)).toBe("5"); // 5 second countdown
148
- expect(secondsToHMS(300)).toBe("5:00"); // 5 minute timer
149
- expect(secondsToHMS(900)).toBe("15:00"); // 15 minute timer
150
- expect(secondsToHMS(3600)).toBe("1:00:00"); // 1 hour timer
151
- });
152
-
153
- test("should handle workout/exercise durations", () => {
154
- expect(secondsToHMS(45)).toBe("45"); // 45 second exercise
155
- expect(secondsToHMS(90)).toBe("1:30"); // 90 second rest
156
- expect(secondsToHMS(1800)).toBe("30:00"); // 30 minute workout
157
- expect(secondsToHMS(2700)).toBe("45:00"); // 45 minute workout
158
- });
159
-
160
- test("should handle cooking/baking timers", () => {
161
- expect(secondsToHMS(300)).toBe("5:00"); // 5 minute boiling
162
- expect(secondsToHMS(600)).toBe("10:00"); // 10 minute prep
163
- expect(secondsToHMS(1200)).toBe("20:00"); // 20 minute baking
164
- expect(secondsToHMS(2400)).toBe("40:00"); // 40 minute roasting
165
- });
166
-
167
- test("should handle meeting/presentation durations", () => {
168
- expect(secondsToHMS(900)).toBe("15:00"); // 15 minute standup
169
- expect(secondsToHMS(1800)).toBe("30:00"); // 30 minute meeting
170
- expect(secondsToHMS(3600)).toBe("1:00:00"); // 1 hour presentation
171
- expect(secondsToHMS(5400)).toBe("1:30:00"); // 1.5 hour workshop
172
- });
173
- });
174
-
175
- describe("type safety and consistency", () => {
176
- test("should always return string type", () => {
177
- expect(typeof secondsToHMS(0)).toBe("string");
178
- expect(typeof secondsToHMS(1)).toBe("string");
179
- expect(typeof secondsToHMS(60)).toBe("string");
180
- expect(typeof secondsToHMS(3600)).toBe("string");
181
- expect(typeof secondsToHMS(1.5)).toBe("string");
182
- });
183
-
184
- test("should handle consecutive calls consistently", () => {
185
- const testValue = 3661;
186
- const result1 = secondsToHMS(testValue);
187
- const result2 = secondsToHMS(testValue);
188
- expect(result1).toBe(result2);
189
- expect(result1).toBe("1:01:01");
190
- });
191
-
192
- test("should not mutate input or have side effects", () => {
193
- const originalValue = 3661;
194
- const valueCopy = originalValue;
195
- const result = secondsToHMS(originalValue);
196
- expect(originalValue).toBe(valueCopy);
197
- expect(result).toBe("1:01:01");
198
- });
199
-
200
- test("should handle different numeric types consistently", () => {
201
- expect(secondsToHMS(60)).toBe("1:00");
202
- expect(secondsToHMS(60.0)).toBe("1:00");
203
- expect(secondsToHMS(60.9)).toBe("1:00"); // floors to 60
204
- });
205
- });
206
-
207
- describe("format validation", () => {
208
- test("seconds only format should be numeric string", () => {
209
- const result = secondsToHMS(5);
210
- expect(result).toMatch(/^\d+$/);
211
- });
212
-
213
- test("minutes format should be M:SS", () => {
214
- const result = secondsToHMS(90);
215
- expect(result).toMatch(/^\d+:\d{2}$/);
216
- });
217
-
218
- test("hours format should be H:MM:SS", () => {
219
- const result = secondsToHMS(3661);
220
- expect(result).toMatch(/^\d+:\d{2}:\d{2}$/);
221
- });
222
-
223
- test("should never return negative values", () => {
224
- const results = [secondsToHMS(0), secondsToHMS(1), secondsToHMS(60), secondsToHMS(3600), secondsToHMS(0.5)];
225
-
226
- results.forEach((result) => {
227
- expect(result).not.toMatch(/-/);
228
- });
229
- });
230
-
231
- test("should maintain consistent padding", () => {
232
- expect(secondsToHMS(3605)).toBe("1:00:05"); // H:MM:SS
233
- expect(secondsToHMS(3065)).toBe("51:05"); // M:SS when < 1 hour
234
- expect(secondsToHMS(65)).toBe("1:05"); // M:SS
235
- });
236
-
237
- test("should handle boundary values correctly", () => {
238
- expect(secondsToHMS(59)).toBe("59"); // Just under 1 minute
239
- expect(secondsToHMS(60)).toBe("1:00"); // Exactly 1 minute
240
- expect(secondsToHMS(3599)).toBe("59:59"); // Just under 1 hour
241
- expect(secondsToHMS(3600)).toBe("1:00:00"); // Exactly 1 hour
242
- });
243
- });
244
-
245
- describe("decimal handling", () => {
246
- test("should floor positive decimals", () => {
247
- expect(secondsToHMS(1.1)).toBe("1");
248
- expect(secondsToHMS(1.5)).toBe("1");
249
- expect(secondsToHMS(1.9)).toBe("1");
250
- expect(secondsToHMS(2.0)).toBe("2");
251
- });
252
-
253
- test("should handle decimals in minute range", () => {
254
- expect(secondsToHMS(60.1)).toBe("1:00");
255
- expect(secondsToHMS(60.9)).toBe("1:00");
256
- expect(secondsToHMS(61.1)).toBe("1:01");
257
- expect(secondsToHMS(61.9)).toBe("1:01");
258
- });
259
-
260
- test("should handle decimals in hour range", () => {
261
- expect(secondsToHMS(3600.1)).toBe("1:00:00");
262
- expect(secondsToHMS(3600.9)).toBe("1:00:00");
263
- expect(secondsToHMS(3661.1)).toBe("1:01:01");
264
- expect(secondsToHMS(3661.9)).toBe("1:01:01");
265
- });
266
-
267
- test("should handle very small decimal values", () => {
268
- expect(secondsToHMS(0.1)).toBe("0");
269
- expect(secondsToHMS(0.01)).toBe("0");
270
- expect(secondsToHMS(0.001)).toBe("0");
271
- expect(secondsToHMS(0.999)).toBe("0");
272
- });
273
- });
274
-
275
- describe("comparison with millisecondsToHMS", () => {
276
- test("should produce same results as millisecondsToHMS when input is equivalent", () => {
277
- // These tests verify consistency between the two functions
278
- expect(secondsToHMS(5)).toBe("5"); // Same as millisecondsToHMS(5000)
279
- expect(secondsToHMS(60)).toBe("1:00"); // Same as millisecondsToHMS(60000)
280
- expect(secondsToHMS(3600)).toBe("1:00:00"); // Same as millisecondsToHMS(3600000)
281
- expect(secondsToHMS(3661)).toBe("1:01:01"); // Same as millisecondsToHMS(3661000)
282
- });
283
-
284
- test("should handle decimal inputs that millisecondsToHMS cannot", () => {
285
- expect(secondsToHMS(1.5)).toBe("1"); // 1.5 seconds
286
- expect(secondsToHMS(61.5)).toBe("1:01"); // 61.5 seconds
287
- expect(secondsToHMS(3661.5)).toBe("1:01:01"); // 3661.5 seconds
288
- });
289
- });
290
-
291
- describe("function behavior", () => {
292
- test("should return string type for all inputs", () => {
293
- const inputs = [0, 1, 1.5, 60, 60.5, 3600, 3600.5, -1]; // Including negative for completeness
294
- inputs.forEach((input) => {
295
- expect(typeof secondsToHMS(input)).toBe("string");
296
- });
297
- });
298
-
299
- test("should not modify global state", () => {
300
- const before = Date.now();
301
- secondsToHMS(3661);
302
- const after = Date.now();
303
- // Should complete quickly and not affect global state
304
- expect(after - before).toBeLessThan(100);
305
- });
306
-
307
- test("should handle very long durations", () => {
308
- const result = secondsToHMS(999999);
309
- expect(typeof result).toBe("string");
310
- expect(result).toMatch(/^\d+:\d{2}:\d{2}$/);
311
- });
312
-
313
- test("should be deterministic", () => {
314
- const input = 3661.5;
315
- const results = Array.from({ length: 10 }, () => secondsToHMS(input));
316
- const uniqueResults = new Set(results);
317
- expect(uniqueResults.size).toBe(1);
318
- expect(results[0]).toBe("1:01:01");
319
- });
320
- });
321
-
322
- describe("performance considerations", () => {
323
- test("should handle zero input efficiently", () => {
324
- const start = Date.now();
325
- for (let i = 0; i < 1000; i++) {
326
- secondsToHMS(0);
327
- }
328
- const end = Date.now();
329
- expect(end - start).toBeLessThan(100); // Should be very fast
330
- });
331
-
332
- test("should handle large inputs efficiently", () => {
333
- const start = Date.now();
334
- for (let i = 0; i < 1000; i++) {
335
- secondsToHMS(999999);
336
- }
337
- const end = Date.now();
338
- expect(end - start).toBeLessThan(100); // Should be very fast
339
- });
340
- });
341
- });