@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,359 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { splitToWords } from "@/index";
|
|
3
|
-
|
|
4
|
-
describe("splitToWords", () => {
|
|
5
|
-
describe("basic functionality", () => {
|
|
6
|
-
test("should split simple lowercase words", () => {
|
|
7
|
-
expect(splitToWords("hello world")).toEqual(["hello", "world"]);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test("should split capitalized words", () => {
|
|
11
|
-
expect(splitToWords("Hello World")).toEqual(["Hello", "World"]);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test("should split single word", () => {
|
|
15
|
-
expect(splitToWords("hello")).toEqual(["hello"]);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("should split capitalized single word", () => {
|
|
19
|
-
expect(splitToWords("Hello")).toEqual(["Hello"]);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("should handle empty string", () => {
|
|
23
|
-
expect(splitToWords("")).toEqual([]);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("should handle whitespace only", () => {
|
|
27
|
-
expect(splitToWords(" ")).toEqual([]);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe("camelCase and PascalCase", () => {
|
|
32
|
-
test("should split camelCase", () => {
|
|
33
|
-
expect(splitToWords("camelCase")).toEqual(["camel", "Case"]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("should split PascalCase", () => {
|
|
37
|
-
expect(splitToWords("PascalCase")).toEqual(["Pascal", "Case"]);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("should split complex camelCase", () => {
|
|
41
|
-
expect(splitToWords("getUserProfile")).toEqual(["get", "User", "Profile"]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("should split camelCase with numbers", () => {
|
|
45
|
-
expect(splitToWords("user123Profile")).toEqual(["user", "123", "Profile"]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("should split camelCase starting with number", () => {
|
|
49
|
-
expect(splitToWords("123userProfile")).toEqual(["123", "user", "Profile"]);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("acronyms", () => {
|
|
54
|
-
test("should handle simple acronyms", () => {
|
|
55
|
-
expect(splitToWords("ID")).toEqual(["ID"]);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("should handle URL acronym", () => {
|
|
59
|
-
expect(splitToWords("URL")).toEqual(["URL"]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("should handle acronym followed by capitalized word", () => {
|
|
63
|
-
expect(splitToWords("HTMLElement")).toEqual(["HTML", "Element"]);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("should handle acronym followed by lowercase", () => {
|
|
67
|
-
expect(splitToWords("XMLparser")).toEqual(["XM", "Lparser"]);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("should handle multiple acronyms", () => {
|
|
71
|
-
expect(splitToWords("HTTPAPI")).toEqual(["HTTPAPI"]);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("should handle acronym at end", () => {
|
|
75
|
-
expect(splitToWords("parseXML")).toEqual(["parse", "XML"]);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("should handle mixed acronyms and words", () => {
|
|
79
|
-
expect(splitToWords("XMLHttpRequest")).toEqual(["XML", "Http", "Request"]);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("should handle acronym patterns correctly", () => {
|
|
83
|
-
expect(splitToWords("XMLParser")).toEqual(["XML", "Parser"]);
|
|
84
|
-
expect(splitToWords("HTTPApi")).toEqual(["HTTP", "Api"]);
|
|
85
|
-
expect(splitToWords("JSONData")).toEqual(["JSON", "Data"]);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("should handle all caps followed by lowercase as expected", () => {
|
|
89
|
-
expect(splitToWords("XMLparser")).toEqual(["XM", "Lparser"]);
|
|
90
|
-
expect(splitToWords("HTMLdocument")).toEqual(["HTM", "Ldocument"]);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe("numbers", () => {
|
|
95
|
-
test("should extract standalone numbers", () => {
|
|
96
|
-
expect(splitToWords("123")).toEqual(["123"]);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test("should extract multiple numbers", () => {
|
|
100
|
-
expect(splitToWords("123 456")).toEqual(["123", "456"]);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("should split words and numbers", () => {
|
|
104
|
-
expect(splitToWords("hello123world")).toEqual(["hello", "123", "world"]);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test("should handle decimal-like patterns", () => {
|
|
108
|
-
expect(splitToWords("version1.2.3")).toEqual(["version", "1", "2", "3"]);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test("should handle large numbers", () => {
|
|
112
|
-
expect(splitToWords("year2024")).toEqual(["year", "2024"]);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe("special characters and separators", () => {
|
|
117
|
-
test("should ignore hyphens as separators", () => {
|
|
118
|
-
expect(splitToWords("hello-world")).toEqual(["hello", "world"]);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("should ignore underscores as separators", () => {
|
|
122
|
-
expect(splitToWords("hello_world")).toEqual(["hello", "world"]);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test("should ignore dots as separators", () => {
|
|
126
|
-
expect(splitToWords("hello.world")).toEqual(["hello", "world"]);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test("should ignore multiple special characters", () => {
|
|
130
|
-
expect(splitToWords("hello-_-world")).toEqual(["hello", "world"]);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test("should handle mixed separators", () => {
|
|
134
|
-
expect(splitToWords("hello-world_test.case")).toEqual(["hello", "world", "test", "case"]);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test("should ignore punctuation", () => {
|
|
138
|
-
expect(splitToWords("hello, world!")).toEqual(["hello", "world"]);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test("should handle parentheses", () => {
|
|
142
|
-
expect(splitToWords("hello(world)")).toEqual(["hello", "world"]);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test("should handle brackets", () => {
|
|
146
|
-
expect(splitToWords("hello[world]")).toEqual(["hello", "world"]);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe("unicode and international characters", () => {
|
|
151
|
-
test("should handle accented characters", () => {
|
|
152
|
-
expect(splitToWords("café résumé")).toEqual(["café", "résumé"]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test("should handle cyrillic characters", () => {
|
|
156
|
-
expect(splitToWords("привет мир")).toEqual(["привет", "мир"]);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test("should handle chinese characters", () => {
|
|
160
|
-
expect(splitToWords("你好世界")).toEqual(["你好世界"]);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test("should handle arabic characters", () => {
|
|
164
|
-
expect(splitToWords("مرحبا بالعالم")).toEqual(["مرحبا", "بالعالم"]);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test("should handle mixed latin and unicode", () => {
|
|
168
|
-
expect(splitToWords("hello世界")).toEqual(["hello", "世界"]);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test("should handle emoji mixed with text", () => {
|
|
172
|
-
expect(splitToWords("hello😀world")).toEqual(["hello", "world"]);
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe("edge cases", () => {
|
|
177
|
-
test("should handle single character", () => {
|
|
178
|
-
expect(splitToWords("a")).toEqual(["a"]);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
test("should handle single uppercase character", () => {
|
|
182
|
-
expect(splitToWords("A")).toEqual(["A"]);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
test("should handle single number", () => {
|
|
186
|
-
expect(splitToWords("1")).toEqual(["1"]);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test("should handle alternating case", () => {
|
|
190
|
-
expect(splitToWords("aBcDeFg")).toEqual(["a", "Bc", "De", "Fg"]);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test("should handle all uppercase", () => {
|
|
194
|
-
expect(splitToWords("HELLO")).toEqual(["HELLO"]);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test("should handle all lowercase", () => {
|
|
198
|
-
expect(splitToWords("hello")).toEqual(["hello"]);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
test("should handle numbers only", () => {
|
|
202
|
-
expect(splitToWords("123456")).toEqual(["123456"]);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test("should handle mixed special characters only", () => {
|
|
206
|
-
expect(splitToWords("!@#$%^&*()")).toEqual([]);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
describe("real-world examples", () => {
|
|
211
|
-
test("should split JavaScript variable names", () => {
|
|
212
|
-
expect(splitToWords("getElementById")).toEqual(["get", "Element", "By", "Id"]);
|
|
213
|
-
expect(splitToWords("addEventListener")).toEqual(["add", "Event", "Listener"]);
|
|
214
|
-
expect(splitToWords("querySelector")).toEqual(["query", "Selector"]);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
test("should split CSS class names", () => {
|
|
218
|
-
expect(splitToWords("btn-primary")).toEqual(["btn", "primary"]);
|
|
219
|
-
expect(splitToWords("form-control")).toEqual(["form", "control"]);
|
|
220
|
-
expect(splitToWords("navbar-brand")).toEqual(["navbar", "brand"]);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test("should split file names", () => {
|
|
224
|
-
expect(splitToWords("myFile.txt")).toEqual(["my", "File", "txt"]);
|
|
225
|
-
expect(splitToWords("user_profile.json")).toEqual(["user", "profile", "json"]);
|
|
226
|
-
expect(splitToWords("config-dev.yaml")).toEqual(["config", "dev", "yaml"]);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
test("should split API endpoints", () => {
|
|
230
|
-
expect(splitToWords("getUserById")).toEqual(["get", "User", "By", "Id"]);
|
|
231
|
-
expect(splitToWords("createUserProfile")).toEqual(["create", "User", "Profile"]);
|
|
232
|
-
expect(splitToWords("updatePasswordV2")).toEqual(["update", "Password", "V", "2"]);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test("should split database column names", () => {
|
|
236
|
-
expect(splitToWords("user_id")).toEqual(["user", "id"]);
|
|
237
|
-
expect(splitToWords("created_at")).toEqual(["created", "at"]);
|
|
238
|
-
expect(splitToWords("firstName")).toEqual(["first", "Name"]);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
test("should split package names", () => {
|
|
242
|
-
expect(splitToWords("react-dom")).toEqual(["react", "dom"]);
|
|
243
|
-
expect(splitToWords("lodash.get")).toEqual(["lodash", "get"]);
|
|
244
|
-
expect(splitToWords("@types/node")).toEqual(["types", "node"]);
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe("complex patterns", () => {
|
|
249
|
-
test("should handle complex mixed patterns", () => {
|
|
250
|
-
expect(splitToWords("parseHTML5Document")).toEqual(["parse", "HTML", "5", "Document"]);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test("should handle version numbers", () => {
|
|
254
|
-
expect(splitToWords("v1.2.3-beta")).toEqual(["v", "1", "2", "3", "beta"]);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
test("should handle technical terms", () => {
|
|
258
|
-
expect(splitToWords("XMLHttpRequestV2")).toEqual(["XML", "Http", "Request", "V", "2"]);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test("should handle namespace-like patterns", () => {
|
|
262
|
-
expect(splitToWords("com.example.MyClass")).toEqual(["com", "example", "My", "Class"]);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test("should handle URL-like patterns", () => {
|
|
266
|
-
expect(splitToWords("httpAPIServer")).toEqual(["http", "API", "Server"]);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
test("should handle constant names", () => {
|
|
270
|
-
expect(splitToWords("MAX_USER_COUNT")).toEqual(["MAX", "USER", "COUNT"]);
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
test("should handle mixed case with numbers", () => {
|
|
274
|
-
expect(splitToWords("iPhone14Pro")).toEqual(["i", "Phone", "14", "Pro"]);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
test("should handle edge case acronym patterns", () => {
|
|
278
|
-
expect(splitToWords("APIKey")).toEqual(["API", "Key"]);
|
|
279
|
-
expect(splitToWords("URLPath")).toEqual(["URL", "Path"]);
|
|
280
|
-
expect(splitToWords("IDField")).toEqual(["ID", "Field"]);
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
describe("parametrized tests", () => {
|
|
285
|
-
test.each([
|
|
286
|
-
["hello", ["hello"]],
|
|
287
|
-
["Hello", ["Hello"]],
|
|
288
|
-
["HELLO", ["HELLO"]],
|
|
289
|
-
["helloWorld", ["hello", "World"]],
|
|
290
|
-
["HelloWorld", ["Hello", "World"]],
|
|
291
|
-
["hello_world", ["hello", "world"]],
|
|
292
|
-
["hello-world", ["hello", "world"]],
|
|
293
|
-
["hello123", ["hello", "123"]],
|
|
294
|
-
["123hello", ["123", "hello"]],
|
|
295
|
-
["XMLParser", ["XML", "Parser"]],
|
|
296
|
-
["parseXML", ["parse", "XML"]],
|
|
297
|
-
["HTML5", ["HTML", "5"]],
|
|
298
|
-
["getUserById", ["get", "User", "By", "Id"]],
|
|
299
|
-
["user_id", ["user", "id"]],
|
|
300
|
-
["API", ["API"]],
|
|
301
|
-
])("splitToWords(%s) should return %j", (input, expected) => {
|
|
302
|
-
expect(splitToWords(input) as unknown).toEqual(expected);
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
describe("function behavior", () => {
|
|
307
|
-
test("should return array", () => {
|
|
308
|
-
const result = splitToWords("test");
|
|
309
|
-
expect(Array.isArray(result)).toBe(true);
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
test("should not mutate input", () => {
|
|
313
|
-
const original = "helloWorld";
|
|
314
|
-
const result = splitToWords(original);
|
|
315
|
-
expect(original).toBe("helloWorld");
|
|
316
|
-
expect(result).toEqual(["hello", "World"]);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
test("should return new array each time", () => {
|
|
320
|
-
const result1 = splitToWords("hello");
|
|
321
|
-
const result2 = splitToWords("hello");
|
|
322
|
-
expect(result1).not.toBe(result2);
|
|
323
|
-
expect(result1).toEqual(result2);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
test("should handle very long strings", () => {
|
|
327
|
-
const longString = `${"a".repeat(1000)}B${"c".repeat(1000)}`;
|
|
328
|
-
const result = splitToWords(longString);
|
|
329
|
-
expect(result).toHaveLength(2);
|
|
330
|
-
expect(result[0]).toBe("a".repeat(1000));
|
|
331
|
-
expect(result[1]).toBe(`B${"c".repeat(1000)}`);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
test("should be consistent across multiple calls", () => {
|
|
335
|
-
const input = "complexTestCase123";
|
|
336
|
-
const result1 = splitToWords(input);
|
|
337
|
-
const result2 = splitToWords(input);
|
|
338
|
-
const result3 = splitToWords(input);
|
|
339
|
-
|
|
340
|
-
expect(result1).toEqual(result2);
|
|
341
|
-
expect(result2).toEqual(result3);
|
|
342
|
-
expect(result1).toEqual(["complex", "Test", "Case", "123"]);
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
describe("performance considerations", () => {
|
|
347
|
-
test("should handle empty input efficiently", () => {
|
|
348
|
-
expect(splitToWords("")).toEqual([]);
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
test("should handle whitespace-only input efficiently", () => {
|
|
352
|
-
expect(splitToWords(" \n\t ")).toEqual([]);
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
test("should handle special characters only efficiently", () => {
|
|
356
|
-
expect(splitToWords("!@#$%^&*()_+-=[]{}|;:,.<>?")).toEqual([]);
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
});
|