@simplysm/core-common 13.0.69 → 13.0.71

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 (151) hide show
  1. package/README.md +66 -267
  2. package/dist/common.types.d.ts +14 -14
  3. package/dist/errors/argument-error.d.ts +10 -10
  4. package/dist/errors/argument-error.d.ts.map +1 -1
  5. package/dist/errors/argument-error.js +2 -2
  6. package/dist/errors/argument-error.js.map +1 -1
  7. package/dist/errors/not-implemented-error.d.ts +8 -8
  8. package/dist/errors/not-implemented-error.js +2 -2
  9. package/dist/errors/not-implemented-error.js.map +1 -1
  10. package/dist/errors/sd-error.d.ts +10 -10
  11. package/dist/errors/sd-error.d.ts.map +1 -1
  12. package/dist/errors/timeout-error.d.ts +10 -10
  13. package/dist/errors/timeout-error.js +3 -3
  14. package/dist/errors/timeout-error.js.map +1 -1
  15. package/dist/extensions/arr-ext.d.ts +2 -2
  16. package/dist/extensions/arr-ext.helpers.d.ts +8 -8
  17. package/dist/extensions/arr-ext.helpers.js +1 -1
  18. package/dist/extensions/arr-ext.helpers.js.map +1 -1
  19. package/dist/extensions/arr-ext.js +13 -13
  20. package/dist/extensions/arr-ext.js.map +1 -1
  21. package/dist/extensions/arr-ext.types.d.ts +57 -57
  22. package/dist/extensions/arr-ext.types.d.ts.map +1 -1
  23. package/dist/extensions/map-ext.d.ts +16 -16
  24. package/dist/extensions/set-ext.d.ts +11 -11
  25. package/dist/features/debounce-queue.d.ts +17 -15
  26. package/dist/features/debounce-queue.d.ts.map +1 -1
  27. package/dist/features/debounce-queue.js +6 -6
  28. package/dist/features/debounce-queue.js.map +1 -1
  29. package/dist/features/event-emitter.d.ts +20 -20
  30. package/dist/features/event-emitter.js +17 -17
  31. package/dist/features/serial-queue.d.ts +11 -11
  32. package/dist/features/serial-queue.js +5 -5
  33. package/dist/features/serial-queue.js.map +1 -1
  34. package/dist/globals.d.ts +4 -4
  35. package/dist/types/date-only.d.ts +64 -64
  36. package/dist/types/date-only.d.ts.map +1 -1
  37. package/dist/types/date-only.js +63 -63
  38. package/dist/types/date-time.d.ts +37 -37
  39. package/dist/types/date-time.d.ts.map +1 -1
  40. package/dist/types/date-time.js +54 -37
  41. package/dist/types/date-time.js.map +1 -1
  42. package/dist/types/lazy-gc-map.d.ts +26 -26
  43. package/dist/types/lazy-gc-map.d.ts.map +1 -1
  44. package/dist/types/lazy-gc-map.js +26 -26
  45. package/dist/types/lazy-gc-map.js.map +1 -1
  46. package/dist/types/time.d.ts +25 -25
  47. package/dist/types/time.d.ts.map +1 -1
  48. package/dist/types/time.js +25 -25
  49. package/dist/types/time.js.map +1 -1
  50. package/dist/types/uuid.d.ts +11 -11
  51. package/dist/types/uuid.d.ts.map +1 -1
  52. package/dist/types/uuid.js +12 -12
  53. package/dist/types/uuid.js.map +1 -1
  54. package/dist/utils/bytes.d.ts +17 -17
  55. package/dist/utils/bytes.js +4 -4
  56. package/dist/utils/bytes.js.map +1 -1
  57. package/dist/utils/date-format.d.ts +45 -45
  58. package/dist/utils/date-format.js +1 -1
  59. package/dist/utils/date-format.js.map +1 -1
  60. package/dist/utils/error.d.ts +4 -4
  61. package/dist/utils/json.d.ts +17 -17
  62. package/dist/utils/json.js +3 -3
  63. package/dist/utils/json.js.map +1 -1
  64. package/dist/utils/num.d.ts +23 -23
  65. package/dist/utils/obj.d.ts +111 -111
  66. package/dist/utils/obj.d.ts.map +1 -1
  67. package/dist/utils/obj.js +3 -3
  68. package/dist/utils/obj.js.map +1 -1
  69. package/dist/utils/path.d.ts +10 -10
  70. package/dist/utils/primitive.d.ts +5 -5
  71. package/dist/utils/primitive.js +1 -1
  72. package/dist/utils/primitive.js.map +1 -1
  73. package/dist/utils/str.d.ts +46 -46
  74. package/dist/utils/str.d.ts.map +1 -1
  75. package/dist/utils/str.js +5 -5
  76. package/dist/utils/str.js.map +1 -1
  77. package/dist/utils/template-strings.d.ts +26 -26
  78. package/dist/utils/transferable.d.ts +18 -18
  79. package/dist/utils/transferable.js +1 -1
  80. package/dist/utils/transferable.js.map +1 -1
  81. package/dist/utils/wait.d.ts +9 -9
  82. package/dist/utils/xml.d.ts +13 -13
  83. package/dist/utils/xml.d.ts.map +1 -1
  84. package/dist/utils/xml.js +1 -0
  85. package/dist/utils/xml.js.map +1 -1
  86. package/dist/zip/sd-zip.d.ts +22 -22
  87. package/dist/zip/sd-zip.js +16 -16
  88. package/package.json +4 -4
  89. package/src/common.types.ts +17 -17
  90. package/src/errors/argument-error.ts +15 -15
  91. package/src/errors/not-implemented-error.ts +9 -9
  92. package/src/errors/sd-error.ts +12 -12
  93. package/src/errors/timeout-error.ts +12 -12
  94. package/src/extensions/arr-ext.helpers.ts +10 -10
  95. package/src/extensions/arr-ext.ts +57 -57
  96. package/src/extensions/arr-ext.types.ts +59 -59
  97. package/src/extensions/map-ext.ts +16 -16
  98. package/src/extensions/set-ext.ts +11 -11
  99. package/src/features/debounce-queue.ts +21 -19
  100. package/src/features/event-emitter.ts +25 -25
  101. package/src/features/serial-queue.ts +13 -13
  102. package/src/globals.ts +4 -4
  103. package/src/index.ts +1 -1
  104. package/src/types/date-only.ts +83 -83
  105. package/src/types/date-time.ts +64 -44
  106. package/src/types/lazy-gc-map.ts +45 -45
  107. package/src/types/time.ts +34 -34
  108. package/src/types/uuid.ts +17 -17
  109. package/src/utils/bytes.ts +35 -35
  110. package/src/utils/date-format.ts +65 -65
  111. package/src/utils/error.ts +4 -4
  112. package/src/utils/json.ts +39 -39
  113. package/src/utils/num.ts +23 -23
  114. package/src/utils/obj.ts +138 -138
  115. package/src/utils/path.ts +10 -10
  116. package/src/utils/primitive.ts +6 -6
  117. package/src/utils/str.ts +260 -261
  118. package/src/utils/template-strings.ts +29 -29
  119. package/src/utils/transferable.ts +284 -284
  120. package/src/utils/wait.ts +10 -10
  121. package/src/utils/xml.ts +20 -19
  122. package/src/zip/sd-zip.ts +25 -25
  123. package/tests/errors/errors.spec.ts +80 -0
  124. package/tests/extensions/array-extension.spec.ts +796 -0
  125. package/tests/extensions/map-extension.spec.ts +147 -0
  126. package/tests/extensions/set-extension.spec.ts +74 -0
  127. package/tests/types/date-only.spec.ts +638 -0
  128. package/tests/types/date-time.spec.ts +391 -0
  129. package/tests/types/lazy-gc-map.spec.ts +692 -0
  130. package/tests/types/time.spec.ts +559 -0
  131. package/tests/types/uuid.spec.ts +74 -0
  132. package/tests/utils/bytes-utils.spec.ts +230 -0
  133. package/tests/utils/date-format.spec.ts +373 -0
  134. package/tests/utils/debounce-queue.spec.ts +272 -0
  135. package/tests/utils/json.spec.ts +486 -0
  136. package/tests/utils/number.spec.ts +157 -0
  137. package/tests/utils/object.spec.ts +829 -0
  138. package/tests/utils/path.spec.ts +78 -0
  139. package/tests/utils/primitive.spec.ts +43 -0
  140. package/tests/utils/sd-event-emitter.spec.ts +216 -0
  141. package/tests/utils/serial-queue.spec.ts +365 -0
  142. package/tests/utils/string.spec.ts +281 -0
  143. package/tests/utils/template-strings.spec.ts +57 -0
  144. package/tests/utils/transferable.spec.ts +703 -0
  145. package/tests/utils/wait.spec.ts +145 -0
  146. package/tests/utils/xml.spec.ts +146 -0
  147. package/tests/zip/sd-zip.spec.ts +238 -0
  148. package/docs/extensions.md +0 -503
  149. package/docs/features.md +0 -109
  150. package/docs/types.md +0 -486
  151. package/docs/utils.md +0 -780
@@ -0,0 +1,281 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ koreanGetSuffix,
4
+ strReplaceFullWidth,
5
+ strToPascalCase,
6
+ strToCamelCase,
7
+ strToKebabCase,
8
+ strToSnakeCase,
9
+ strInsert,
10
+ } from "@simplysm/core-common";
11
+
12
+ describe("string utils", () => {
13
+ //#region koreanGetSuffix - Korean postposition handling
14
+
15
+ describe("koreanGetSuffix()", () => {
16
+ describe("with final consonant", () => {
17
+ it("'을' type returns '을'", () => {
18
+ expect(koreanGetSuffix("책", "을")).toBe("을");
19
+ });
20
+
21
+ it("'은' type returns '은'", () => {
22
+ expect(koreanGetSuffix("책", "은")).toBe("은");
23
+ });
24
+
25
+ it("'이' type returns '이'", () => {
26
+ expect(koreanGetSuffix("책", "이")).toBe("이");
27
+ });
28
+
29
+ it("'와' type returns '과'", () => {
30
+ expect(koreanGetSuffix("책", "와")).toBe("과");
31
+ });
32
+
33
+ it("'랑' type returns '이랑'", () => {
34
+ expect(koreanGetSuffix("책", "랑")).toBe("이랑");
35
+ });
36
+
37
+ it("'로' type returns '으로'", () => {
38
+ expect(koreanGetSuffix("책", "로")).toBe("으로");
39
+ });
40
+
41
+ it("'라' type returns '이라'", () => {
42
+ expect(koreanGetSuffix("책", "라")).toBe("이라");
43
+ });
44
+ });
45
+
46
+ describe("non-Korean character cases", () => {
47
+ it("treats words ending with English letter as no final consonant", () => {
48
+ expect(koreanGetSuffix("ABC", "을")).toBe("를");
49
+ expect(koreanGetSuffix("test", "은")).toBe("는");
50
+ });
51
+
52
+ it("treats words ending with number as no final consonant", () => {
53
+ expect(koreanGetSuffix("123", "을")).toBe("를");
54
+ expect(koreanGetSuffix("456", "은")).toBe("는");
55
+ });
56
+
57
+ it("empty string treated as no final consonant", () => {
58
+ expect(koreanGetSuffix("", "을")).toBe("를");
59
+ expect(koreanGetSuffix("", "은")).toBe("는");
60
+ });
61
+ });
62
+
63
+ describe("without final consonant", () => {
64
+ it("'을' type returns '를'", () => {
65
+ expect(koreanGetSuffix("나무", "을")).toBe("를");
66
+ });
67
+
68
+ it("'은' type returns '는'", () => {
69
+ expect(koreanGetSuffix("나무", "은")).toBe("는");
70
+ });
71
+
72
+ it("'이' type returns '가'", () => {
73
+ expect(koreanGetSuffix("나무", "이")).toBe("가");
74
+ });
75
+
76
+ it("'와' type returns '와'", () => {
77
+ expect(koreanGetSuffix("나무", "와")).toBe("와");
78
+ });
79
+
80
+ it("'랑' type returns '랑'", () => {
81
+ expect(koreanGetSuffix("나무", "랑")).toBe("랑");
82
+ });
83
+
84
+ it("'로' type returns '로'", () => {
85
+ expect(koreanGetSuffix("나무", "로")).toBe("로");
86
+ });
87
+
88
+ it("'라' type returns '라'", () => {
89
+ expect(koreanGetSuffix("나무", "라")).toBe("라");
90
+ });
91
+ });
92
+
93
+ describe("final consonant ㄹ (special '로' handling)", () => {
94
+ it("'로' type returns '로' for final ㄹ (Seoul)", () => {
95
+ expect(koreanGetSuffix("서울", "로")).toBe("로");
96
+ });
97
+
98
+ it("'로' type returns '로' for final ㄹ (road)", () => {
99
+ expect(koreanGetSuffix("길", "로")).toBe("로");
100
+ });
101
+
102
+ it("'로' type returns '로' for final ㄹ (foot)", () => {
103
+ expect(koreanGetSuffix("발", "로")).toBe("로");
104
+ });
105
+
106
+ it("'로' type returns '로' for final ㄹ (alcohol)", () => {
107
+ expect(koreanGetSuffix("술", "로")).toBe("로");
108
+ });
109
+
110
+ it("'을' type returns '을' for final ㄹ by general rule", () => {
111
+ expect(koreanGetSuffix("서울", "을")).toBe("을");
112
+ });
113
+
114
+ it("'은' type returns '은' for final ㄹ by general rule", () => {
115
+ expect(koreanGetSuffix("서울", "은")).toBe("은");
116
+ });
117
+ });
118
+ });
119
+
120
+ //#endregion
121
+
122
+ //#endregion
123
+
124
+ //#region strReplaceFullWidth - Full-width to half-width conversion
125
+
126
+ describe("strReplaceFullWidth()", () => {
127
+ it("converts full-width alphabet to half-width", () => {
128
+ expect(strReplaceFullWidth("ABCDEFG")).toBe("ABCDEFG");
129
+ expect(strReplaceFullWidth("HIJKLMN")).toBe("HIJKLMN");
130
+ expect(strReplaceFullWidth("OPQRSTU")).toBe("OPQRSTU");
131
+ expect(strReplaceFullWidth("VWXYZ")).toBe("VWXYZ");
132
+ });
133
+
134
+ it("converts full-width number to half-width", () => {
135
+ expect(strReplaceFullWidth("0123456789")).toBe("0123456789");
136
+ });
137
+
138
+ it("converts full-width parenthesis to half-width", () => {
139
+ expect(strReplaceFullWidth("(ABC)")).toBe("(ABC)");
140
+ });
141
+
142
+ it("converts full-width space to half-width space", () => {
143
+ expect(strReplaceFullWidth("A B C")).toBe("A B C");
144
+ });
145
+
146
+ it("converts mixed full-width/half-width string", () => {
147
+ expect(strReplaceFullWidth("ABC123")).toBe("ABC123");
148
+ });
149
+
150
+ it("returns original if no full-width characters", () => {
151
+ expect(strReplaceFullWidth("ABC123")).toBe("ABC123");
152
+ });
153
+ });
154
+
155
+ //#endregion
156
+
157
+ //#endregion
158
+
159
+ //#region Case conversion
160
+
161
+ describe("strToPascalCase()", () => {
162
+ it("converts kebab-case to PascalCase", () => {
163
+ expect(strToPascalCase("hello-world")).toBe("HelloWorld");
164
+ });
165
+
166
+ it("converts dot.case to PascalCase", () => {
167
+ expect(strToPascalCase("hello.world")).toBe("HelloWorld");
168
+ });
169
+
170
+ it("converts snake_case to PascalCase", () => {
171
+ expect(strToPascalCase("hello_world")).toBe("HelloWorld");
172
+ });
173
+
174
+ it("capitalizes first letter of lowercase string", () => {
175
+ expect(strToPascalCase("hello")).toBe("Hello");
176
+ });
177
+
178
+ it("returns as-is if already PascalCase", () => {
179
+ expect(strToPascalCase("HelloWorld")).toBe("HelloWorld");
180
+ });
181
+
182
+ it("handles consecutive hyphens", () => {
183
+ expect(strToPascalCase("hello-world-test")).toBe("HelloWorldTest");
184
+ });
185
+ });
186
+
187
+ describe("strToCamelCase()", () => {
188
+ it("converts kebab-case to camelCase", () => {
189
+ expect(strToCamelCase("hello-world")).toBe("helloWorld");
190
+ });
191
+
192
+ it("converts PascalCase to camelCase", () => {
193
+ expect(strToCamelCase("HelloWorld")).toBe("helloWorld");
194
+ });
195
+
196
+ it("converts dot.case to camelCase", () => {
197
+ expect(strToCamelCase("hello.world")).toBe("helloWorld");
198
+ });
199
+
200
+ it("converts snake_case to camelCase", () => {
201
+ expect(strToCamelCase("hello_world")).toBe("helloWorld");
202
+ });
203
+
204
+ it("returns as-is if already camelCase", () => {
205
+ expect(strToCamelCase("helloWorld")).toBe("helloWorld");
206
+ });
207
+ });
208
+
209
+ describe("strToKebabCase()", () => {
210
+ it("converts PascalCase to kebab-case", () => {
211
+ expect(strToKebabCase("HelloWorld")).toBe("hello-world");
212
+ });
213
+
214
+ it("converts camelCase to kebab-case", () => {
215
+ expect(strToKebabCase("helloWorld")).toBe("hello-world");
216
+ });
217
+
218
+ it("adds hyphen before underscore when present", () => {
219
+ // toKebabCase converts [-_]?[A-Z] to -lowercase, so _W → -_w
220
+ expect(strToKebabCase("Hello_World")).toBe("hello-_world");
221
+ });
222
+
223
+ it("returns as-is if already kebab-case", () => {
224
+ expect(strToKebabCase("hello-world")).toBe("hello-world");
225
+ });
226
+
227
+ it("handles consecutive uppercase letters", () => {
228
+ expect(strToKebabCase("HelloWorldTest")).toBe("hello-world-test");
229
+ });
230
+
231
+ it("handles consecutive uppercase followed by lowercase", () => {
232
+ // each uppercase letter treated as separate word
233
+ expect(strToKebabCase("XMLParser")).toBe("x-m-l-parser");
234
+ expect(strToKebabCase("HTTPSConnection")).toBe("h-t-t-p-s-connection");
235
+ });
236
+ });
237
+
238
+ describe("strToSnakeCase()", () => {
239
+ it("converts PascalCase to snake_case", () => {
240
+ expect(strToSnakeCase("HelloWorld")).toBe("hello_world");
241
+ });
242
+
243
+ it("converts camelCase to snake_case", () => {
244
+ expect(strToSnakeCase("helloWorld")).toBe("hello_world");
245
+ });
246
+
247
+ it("returns as-is if already snake_case", () => {
248
+ expect(strToSnakeCase("hello_world")).toBe("hello_world");
249
+ });
250
+
251
+ it("handles consecutive uppercase letters", () => {
252
+ expect(strToSnakeCase("HelloWorldTest")).toBe("hello_world_test");
253
+ });
254
+ });
255
+
256
+ //#endregion
257
+
258
+ //#endregion
259
+
260
+ //#region Other
261
+
262
+ describe("strInsert()", () => {
263
+ it("inserts at start of string", () => {
264
+ expect(strInsert("world", 0, "hello ")).toBe("hello world");
265
+ });
266
+
267
+ it("inserts in middle of string", () => {
268
+ expect(strInsert("helloworld", 5, " ")).toBe("hello world");
269
+ });
270
+
271
+ it("inserts at end of string", () => {
272
+ expect(strInsert("hello", 5, " world")).toBe("hello world");
273
+ });
274
+
275
+ it("inserts into empty string", () => {
276
+ expect(strInsert("", 0, "hello")).toBe("hello");
277
+ });
278
+ });
279
+
280
+ //#endregion
281
+ });
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { html, js } from "../../src/index.js";
3
+
4
+ describe("template-strings", () => {
5
+ describe("Basic behavior", () => {
6
+ it("String concatenation", () => {
7
+ const name = "test";
8
+ expect(js`const x = "${name}"`).toBe('const x = "test"');
9
+ });
10
+
11
+ it("Removes indentation", () => {
12
+ const result = js`
13
+ const x = 1;
14
+ const y = 2;
15
+ `;
16
+ expect(result).toBe("const x = 1;\nconst y = 2;");
17
+ });
18
+
19
+ it("Removes first/last empty lines", () => {
20
+ const result = html`
21
+ <div>test</div>
22
+ `;
23
+ expect(result).toBe("<div>test</div>");
24
+ });
25
+
26
+ it("Preserves middle empty lines", () => {
27
+ const result = js`
28
+ const x = 1;
29
+
30
+ const y = 2;
31
+ `;
32
+ expect(result).toBe("const x = 1;\n\nconst y = 2;");
33
+ });
34
+ });
35
+
36
+ describe("Value interpolation", () => {
37
+ it("Handles undefined value", () => {
38
+ const value = undefined;
39
+ expect(js`x = ${value}`).toBe("x = ");
40
+ });
41
+
42
+ it("Handles number value", () => {
43
+ expect(js`x = ${42}`).toBe("x = 42");
44
+ });
45
+
46
+ it("Interpolates multiple values", () => {
47
+ const a = 1;
48
+ const b = 2;
49
+ expect(js`${a} + ${b} = ${a + b}`).toBe("1 + 2 = 3");
50
+ });
51
+
52
+ it("Handles object value", () => {
53
+ const obj = { toString: () => "custom" };
54
+ expect(js`value = ${obj}`).toBe("value = custom");
55
+ });
56
+ });
57
+ });