@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
package/docs/utils.md DELETED
@@ -1,780 +0,0 @@
1
- # Utilities
2
-
3
- ## Object utilities (obj)
4
-
5
- ### objClone
6
-
7
- Deep clone (supports circular references, custom types like `DateTime`, `Uuid`).
8
-
9
- ```typescript
10
- import { objClone } from "@simplysm/core-common";
11
-
12
- const cloned = objClone({ date: new DateTime(), nested: { arr: [1, 2] } });
13
- ```
14
-
15
- ### objEqual
16
-
17
- Deep comparison with include/exclude keys and array order ignore option.
18
-
19
- ```typescript
20
- import { objEqual } from "@simplysm/core-common";
21
-
22
- objEqual({ a: 1, b: [2] }, { a: 1, b: [2] }); // true
23
- objEqual(arr1, arr2, { ignoreArrayIndex: true }); // Ignore array order
24
- objEqual(obj1, obj2, { topLevelExcludes: ["updatedAt"] }); // Exclude specific keys
25
- objEqual(obj1, obj2, { topLevelIncludes: ["id", "name"] }); // Only compare these keys
26
- objEqual(obj1, obj2, { onlyOneDepth: true }); // Shallow (reference) comparison
27
- ```
28
-
29
- ### objMerge
30
-
31
- Deep merge (source + target, array processing option).
32
-
33
- ```typescript
34
- import { objMerge } from "@simplysm/core-common";
35
-
36
- objMerge({ a: 1, b: { c: 2 } }, { b: { d: 3 } });
37
- // { a: 1, b: { c: 2, d: 3 } }
38
-
39
- // Concat arrays instead of replacing
40
- objMerge({ tags: ["a"] }, { tags: ["b"] }, { arrayProcess: "concat" });
41
- // { tags: ["a", "b"] }
42
-
43
- // Delete key when target value is null
44
- objMerge({ a: 1, b: 2 }, { b: null }, { useDelTargetNull: true });
45
- // { a: 1 }
46
- ```
47
-
48
- ### objMerge3
49
-
50
- 3-way merge with conflict detection.
51
-
52
- ```typescript
53
- import { objMerge3 } from "@simplysm/core-common";
54
-
55
- const { conflict, result } = objMerge3(
56
- { a: 1, b: 2 }, // source (change #1)
57
- { a: 1, b: 1 }, // origin (base)
58
- { a: 2, b: 1 }, // target (change #2)
59
- );
60
- // conflict: false, result: { a: 2, b: 2 }
61
- ```
62
-
63
- ### objOmit
64
-
65
- Exclude specific keys.
66
-
67
- ```typescript
68
- import { objOmit } from "@simplysm/core-common";
69
-
70
- objOmit(user, ["password", "email"]);
71
- ```
72
-
73
- ### objOmitByFilter
74
-
75
- Exclude keys matching a predicate function.
76
-
77
- ```typescript
78
- import { objOmitByFilter } from "@simplysm/core-common";
79
-
80
- // Remove all keys starting with "_"
81
- objOmitByFilter(data, (key) => String(key).startsWith("_"));
82
- // { name: "Alice", age: 30 } (private _internal key removed)
83
- ```
84
-
85
- ### objPick
86
-
87
- Select specific keys.
88
-
89
- ```typescript
90
- import { objPick } from "@simplysm/core-common";
91
-
92
- objPick(user, ["name", "age"]);
93
- ```
94
-
95
- ### objGetChainValue
96
-
97
- Query value by chain path (`"a.b[0].c"`).
98
-
99
- ```typescript
100
- import { objGetChainValue } from "@simplysm/core-common";
101
-
102
- objGetChainValue(obj, "a.b[0].c");
103
-
104
- // Optional: returns undefined instead of throwing when intermediate path is missing
105
- objGetChainValue(obj, "a.b[0].c", true);
106
- ```
107
-
108
- ### objGetChainValueByDepth
109
-
110
- Descend the same key repeatedly to a given depth and return the value.
111
-
112
- ```typescript
113
- import { objGetChainValueByDepth } from "@simplysm/core-common";
114
-
115
- const nested = { parent: { parent: { name: "root" } } };
116
- objGetChainValueByDepth(nested, "parent", 2); // { name: "root" }
117
-
118
- // Optional: returns undefined instead of throwing when path is missing
119
- objGetChainValueByDepth(nested, "parent", 5, true); // undefined
120
- ```
121
-
122
- ### objSetChainValue
123
-
124
- Set value by chain path.
125
-
126
- ```typescript
127
- import { objSetChainValue } from "@simplysm/core-common";
128
-
129
- objSetChainValue(obj, "a.b[0].c", "value");
130
- ```
131
-
132
- ### objDeleteChainValue
133
-
134
- Delete value by chain path.
135
-
136
- ```typescript
137
- import { objDeleteChainValue } from "@simplysm/core-common";
138
-
139
- objDeleteChainValue(obj, "a.b[0].c");
140
- ```
141
-
142
- ### objClearUndefined
143
-
144
- Delete keys with `undefined` values from an object (mutates the original).
145
-
146
- ```typescript
147
- import { objClearUndefined } from "@simplysm/core-common";
148
-
149
- const obj = { a: 1, b: undefined, c: "hello" };
150
- objClearUndefined(obj); // { a: 1, c: "hello" }
151
- ```
152
-
153
- ### objClear
154
-
155
- Delete all keys from an object (mutates the original).
156
-
157
- ```typescript
158
- import { objClear } from "@simplysm/core-common";
159
-
160
- const obj = { a: 1, b: 2 };
161
- objClear(obj); // {}
162
- ```
163
-
164
- ### objNullToUndefined
165
-
166
- Recursively convert `null` values to `undefined` (mutates the original object/array).
167
-
168
- ```typescript
169
- import { objNullToUndefined } from "@simplysm/core-common";
170
-
171
- const data = { a: null, b: { c: null }, d: [null, 1] };
172
- objNullToUndefined(data);
173
- // { a: undefined, b: { c: undefined }, d: [undefined, 1] }
174
- ```
175
-
176
- ### objUnflatten
177
-
178
- Convert a flat object with dot-notation keys into a nested object.
179
-
180
- ```typescript
181
- import { objUnflatten } from "@simplysm/core-common";
182
-
183
- objUnflatten({ "a.b.c": 1, "a.b.d": 2, "e": 3 });
184
- // { a: { b: { c: 1, d: 2 } }, e: 3 }
185
- ```
186
-
187
- ### objKeys
188
-
189
- Type-safe `Object.keys`.
190
-
191
- ```typescript
192
- import { objKeys } from "@simplysm/core-common";
193
-
194
- objKeys(obj); // (keyof typeof obj)[]
195
- ```
196
-
197
- ### objEntries
198
-
199
- Type-safe `Object.entries`.
200
-
201
- ```typescript
202
- import { objEntries } from "@simplysm/core-common";
203
-
204
- objEntries(obj); // [keyof typeof obj, typeof obj[keyof typeof obj]][]
205
- ```
206
-
207
- ### objFromEntries
208
-
209
- Type-safe `Object.fromEntries`.
210
-
211
- ```typescript
212
- import { objFromEntries } from "@simplysm/core-common";
213
-
214
- const entries: ["a" | "b", number][] = [["a", 1], ["b", 2]];
215
- objFromEntries(entries); // { a: number; b: number }
216
- ```
217
-
218
- ### objMap
219
-
220
- Transform each entry of object and return new object.
221
-
222
- ```typescript
223
- import { objMap } from "@simplysm/core-common";
224
-
225
- // Transform values only (pass null as new key to keep original key)
226
- objMap(colors, (key, rgb) => [null, `rgb(${rgb})`]);
227
-
228
- // Transform both keys and values
229
- objMap(colors, (key, rgb) => [`${key}Light`, `rgb(${rgb})`]);
230
- ```
231
-
232
- ---
233
-
234
- ## JSON utilities (json)
235
-
236
- Serializes/restores `DateTime`, `DateOnly`, `Time`, `Uuid`, `Date`, `Set`, `Map`, `Error`, `Uint8Array` types using `__type__` metadata.
237
-
238
- ### jsonStringify
239
-
240
- JSON serialization with custom type support.
241
-
242
- ```typescript
243
- import { jsonStringify, DateTime, Uuid } from "@simplysm/core-common";
244
-
245
- const data = {
246
- createdAt: new DateTime(2025, 1, 15),
247
- id: Uuid.new(),
248
- tags: new Set(["a", "b"]),
249
- meta: new Map([["key", "value"]]),
250
- file: new Uint8Array([1, 2, 3]),
251
- };
252
-
253
- // Serialization (preserves custom types)
254
- const json = jsonStringify(data, { space: 2 });
255
-
256
- // For logging: hide binary data
257
- jsonStringify(data, { redactBytes: true });
258
- // Uint8Array content replaced with "__hidden__"
259
-
260
- // Custom replacer (called before built-in type conversion)
261
- jsonStringify(data, {
262
- replacer: (key, value) => (key === "secret" ? undefined : value),
263
- });
264
- ```
265
-
266
- ### jsonParse
267
-
268
- JSON deserialization with custom type restoration.
269
-
270
- ```typescript
271
- import { jsonParse } from "@simplysm/core-common";
272
-
273
- // Deserialization (restores custom types)
274
- const parsed = jsonParse(json);
275
- // parsed.createdAt instanceof DateTime === true
276
- // parsed.id instanceof Uuid === true
277
- // parsed.tags instanceof Set === true
278
- ```
279
-
280
- ---
281
-
282
- ## XML utilities (xml)
283
-
284
- ### xmlParse
285
-
286
- Parse XML string to object (attributes: `$`, text: `_`).
287
-
288
- ```typescript
289
- import { xmlParse } from "@simplysm/core-common";
290
-
291
- const obj = xmlParse('<root id="1"><item>hello</item></root>');
292
- // { root: { $: { id: "1" }, item: [{ _: "hello" }] } }
293
-
294
- // Remove namespace prefix
295
- xmlParse('<ns:root><ns:item>text</ns:item></ns:root>', { stripTagPrefix: true });
296
- // { root: { item: [{ _: "text" }] } }
297
- ```
298
-
299
- ### xmlStringify
300
-
301
- Serialize object to XML string.
302
-
303
- ```typescript
304
- import { xmlStringify } from "@simplysm/core-common";
305
-
306
- const xml = xmlStringify(obj);
307
- // '<root id="1"><item>hello</item></root>'
308
- ```
309
-
310
- ---
311
-
312
- ## String utilities (str)
313
-
314
- ### strGetSuffix
315
-
316
- Korean postposition handling (을/를, 은/는, 이/가, 과/와, 이랑/랑, 으로/로, 이라/라).
317
-
318
- ```typescript
319
- import { strGetSuffix } from "@simplysm/core-common";
320
-
321
- strGetSuffix("사과", "을"); // "를"
322
- strGetSuffix("책", "이"); // "이"
323
- strGetSuffix("서울", "로"); // "로" (ㄹ final consonant uses "로")
324
- ```
325
-
326
- ### strReplaceFullWidth
327
-
328
- Convert full-width characters to half-width.
329
-
330
- ```typescript
331
- import { strReplaceFullWidth } from "@simplysm/core-common";
332
-
333
- strReplaceFullWidth("A123(株)"); // "A123(株)"
334
- ```
335
-
336
- ### strToPascalCase
337
-
338
- PascalCase conversion.
339
-
340
- ```typescript
341
- import { strToPascalCase } from "@simplysm/core-common";
342
-
343
- strToPascalCase("hello-world"); // "HelloWorld"
344
- strToPascalCase("hello_world"); // "HelloWorld"
345
- ```
346
-
347
- ### strToCamelCase
348
-
349
- camelCase conversion.
350
-
351
- ```typescript
352
- import { strToCamelCase } from "@simplysm/core-common";
353
-
354
- strToCamelCase("hello-world"); // "helloWorld"
355
- strToCamelCase("HelloWorld"); // "helloWorld"
356
- ```
357
-
358
- ### strToKebabCase
359
-
360
- kebab-case conversion.
361
-
362
- ```typescript
363
- import { strToKebabCase } from "@simplysm/core-common";
364
-
365
- strToKebabCase("HelloWorld"); // "hello-world"
366
- ```
367
-
368
- ### strToSnakeCase
369
-
370
- snake_case conversion.
371
-
372
- ```typescript
373
- import { strToSnakeCase } from "@simplysm/core-common";
374
-
375
- strToSnakeCase("HelloWorld"); // "hello_world"
376
- ```
377
-
378
- ### strIsNullOrEmpty
379
-
380
- Check for undefined/null/empty string (type guard).
381
-
382
- ```typescript
383
- import { strIsNullOrEmpty } from "@simplysm/core-common";
384
-
385
- if (strIsNullOrEmpty(name)) {
386
- // name: "" | undefined
387
- } else {
388
- // name: string (non-empty string)
389
- }
390
- ```
391
-
392
- ### strInsert
393
-
394
- Insert at specific position in string.
395
-
396
- ```typescript
397
- import { strInsert } from "@simplysm/core-common";
398
-
399
- strInsert("Hello World", 5, ","); // "Hello, World"
400
- strInsert("abc", 0, "X"); // "Xabc"
401
- strInsert("abc", 3, "X"); // "abcX"
402
- ```
403
-
404
- ---
405
-
406
- ## Number utilities (num)
407
-
408
- ### numParseInt
409
-
410
- Parse string to integer (remove non-digit characters).
411
-
412
- ```typescript
413
- import { numParseInt } from "@simplysm/core-common";
414
-
415
- numParseInt("12,345원"); // 12345
416
- numParseInt(3.7); // 3 (truncated, not rounded)
417
- ```
418
-
419
- ### numParseFloat
420
-
421
- Parse string to float.
422
-
423
- ```typescript
424
- import { numParseFloat } from "@simplysm/core-common";
425
-
426
- numParseFloat("3.14%"); // 3.14
427
- ```
428
-
429
- ### numParseRoundedInt
430
-
431
- Round float and return integer.
432
-
433
- ```typescript
434
- import { numParseRoundedInt } from "@simplysm/core-common";
435
-
436
- numParseRoundedInt("3.7"); // 4
437
- numParseRoundedInt("3.2"); // 3
438
- ```
439
-
440
- ### numFormat
441
-
442
- Thousands separator formatting.
443
-
444
- ```typescript
445
- import { numFormat } from "@simplysm/core-common";
446
-
447
- numFormat(1234567, { max: 2 }); // "1,234,567"
448
- numFormat(1234, { min: 2, max: 2 }); // "1,234.00"
449
- numFormat(undefined); // undefined
450
- ```
451
-
452
- ### numIsNullOrEmpty
453
-
454
- Check for undefined/null/0 (type guard).
455
-
456
- ```typescript
457
- import { numIsNullOrEmpty } from "@simplysm/core-common";
458
-
459
- if (numIsNullOrEmpty(count)) {
460
- // count: 0 | undefined
461
- }
462
- ```
463
-
464
- ---
465
-
466
- ## Date/time formatting (date-format)
467
-
468
- ### formatDate
469
-
470
- Convert date/time to string according to format string. Supports the same format strings as C#.
471
-
472
- | Format | Description | Example |
473
- |------|------|------|
474
- | `yyyy` | 4-digit year | 2024 |
475
- | `yy` | 2-digit year | 24 |
476
- | `MM` | 0-padded month | 01~12 |
477
- | `M` | Month | 1~12 |
478
- | `ddd` | Day of week (Korean) | 일, 월, 화, 수, 목, 금, 토 |
479
- | `dd` | 0-padded day | 01~31 |
480
- | `d` | Day | 1~31 |
481
- | `tt` | AM/PM | 오전, 오후 |
482
- | `hh` | 0-padded 12-hour | 01~12 |
483
- | `h` | 12-hour | 1~12 |
484
- | `HH` | 0-padded 24-hour | 00~23 |
485
- | `H` | 24-hour | 0~23 |
486
- | `mm` | 0-padded minute | 00~59 |
487
- | `m` | Minute | 0~59 |
488
- | `ss` | 0-padded second | 00~59 |
489
- | `s` | Second | 0~59 |
490
- | `fff` | Millisecond (3 digits) | 000~999 |
491
- | `ff` | Millisecond (2 digits) | 00~99 |
492
- | `f` | Millisecond (1 digit) | 0~9 |
493
- | `zzz` | Timezone offset (±HH:mm) | +09:00 |
494
- | `zz` | Timezone offset (±HH) | +09 |
495
- | `z` | Timezone offset (±H) | +9 |
496
-
497
- ```typescript
498
- import { formatDate } from "@simplysm/core-common";
499
-
500
- formatDate("yyyy-MM-dd", { year: 2024, month: 3, day: 15 });
501
- // "2024-03-15"
502
-
503
- formatDate("yyyy년 M월 d일 (ddd)", { year: 2024, month: 3, day: 15 });
504
- // "2024년 3월 15일 (금)"
505
-
506
- formatDate("tt h:mm:ss", { hour: 14, minute: 30, second: 45 });
507
- // "오후 2:30:45"
508
- ```
509
-
510
- ### normalizeMonth
511
-
512
- Normalize year/month/day when setting month. Handles month overflow and day clamping.
513
-
514
- ```typescript
515
- import { normalizeMonth } from "@simplysm/core-common";
516
-
517
- normalizeMonth(2025, 13, 15); // { year: 2026, month: 1, day: 15 }
518
- normalizeMonth(2025, 2, 31); // { year: 2025, month: 2, day: 28 }
519
- normalizeMonth(2025, 0, 1); // { year: 2024, month: 12, day: 1 }
520
- ```
521
-
522
- ### convert12To24
523
-
524
- Convert 12-hour (AM/PM) to 24-hour format.
525
-
526
- ```typescript
527
- import { convert12To24 } from "@simplysm/core-common";
528
-
529
- convert12To24(12, false); // 0 (12 AM = midnight)
530
- convert12To24(12, true); // 12 (12 PM = noon)
531
- convert12To24(1, false); // 1 (1 AM)
532
- convert12To24(1, true); // 13 (1 PM)
533
- ```
534
-
535
- ---
536
-
537
- ## Byte utilities (bytes)
538
-
539
- ### bytesConcat
540
-
541
- Concatenate multiple Uint8Arrays.
542
-
543
- ```typescript
544
- import { bytesConcat } from "@simplysm/core-common";
545
-
546
- bytesConcat([new Uint8Array([1, 2]), new Uint8Array([3, 4])]);
547
- // Uint8Array([1, 2, 3, 4])
548
- ```
549
-
550
- ### bytesToHex
551
-
552
- Convert Uint8Array to hex string.
553
-
554
- ```typescript
555
- import { bytesToHex } from "@simplysm/core-common";
556
-
557
- bytesToHex(new Uint8Array([255, 0, 127])); // "ff007f"
558
- ```
559
-
560
- ### bytesFromHex
561
-
562
- Convert hex string to Uint8Array.
563
-
564
- ```typescript
565
- import { bytesFromHex } from "@simplysm/core-common";
566
-
567
- bytesFromHex("ff007f"); // Uint8Array([255, 0, 127])
568
- ```
569
-
570
- ### bytesToBase64
571
-
572
- Convert Uint8Array to base64 string.
573
-
574
- ```typescript
575
- import { bytesToBase64 } from "@simplysm/core-common";
576
-
577
- bytesToBase64(new Uint8Array([72, 101, 108, 108, 111])); // "SGVsbG8="
578
- ```
579
-
580
- ### bytesFromBase64
581
-
582
- Convert base64 string to Uint8Array.
583
-
584
- ```typescript
585
- import { bytesFromBase64 } from "@simplysm/core-common";
586
-
587
- bytesFromBase64("SGVsbG8="); // Uint8Array([72, 101, 108, 108, 111])
588
- ```
589
-
590
- ---
591
-
592
- ## Async wait (wait)
593
-
594
- ### waitTime
595
-
596
- Wait for specified time.
597
-
598
- ```typescript
599
- import { waitTime } from "@simplysm/core-common";
600
-
601
- await waitTime(1000); // Wait 1 second
602
- ```
603
-
604
- ### waitUntil
605
-
606
- Wait until condition is true (max attempts limit).
607
-
608
- ```typescript
609
- import { waitUntil } from "@simplysm/core-common";
610
-
611
- // Wait for condition (100ms interval, max 50 attempts = 5 seconds)
612
- await waitUntil(() => isReady, 100, 50);
613
- // Throws TimeoutError after 50 attempts
614
-
615
- // Unlimited wait (omit maxCount)
616
- await waitUntil(() => isReady, 200);
617
- ```
618
-
619
- ---
620
-
621
- ## Worker data conversion (transferable)
622
-
623
- ### transferableEncode
624
-
625
- Serialize custom types into Worker-transferable form. Returns `{ result, transferList }` where `transferList` contains `ArrayBuffer` instances for zero-copy transfer.
626
-
627
- ```typescript
628
- import { transferableEncode } from "@simplysm/core-common";
629
-
630
- // Send to Worker
631
- const { result, transferList } = transferableEncode(data);
632
- worker.postMessage(result, transferList);
633
- ```
634
-
635
- ### transferableDecode
636
-
637
- Deserialize Worker-received data to custom types.
638
-
639
- ```typescript
640
- import { transferableDecode } from "@simplysm/core-common";
641
-
642
- // Receive from Worker
643
- const decoded = transferableDecode(event.data);
644
- ```
645
-
646
- ---
647
-
648
- ## Path utilities (path)
649
-
650
- Replacement for Node.js `path` module. Supports POSIX-style paths (`/`) only.
651
-
652
- ### pathJoin
653
-
654
- Combine paths (`path.join` replacement).
655
-
656
- ```typescript
657
- import { pathJoin } from "@simplysm/core-common";
658
-
659
- pathJoin("/home", "user", "file.txt"); // "/home/user/file.txt"
660
- pathJoin("a/", "/b/", "/c"); // "a/b/c"
661
- ```
662
-
663
- ### pathBasename
664
-
665
- Extract filename (`path.basename` replacement).
666
-
667
- ```typescript
668
- import { pathBasename } from "@simplysm/core-common";
669
-
670
- pathBasename("/home/user/file.txt"); // "file.txt"
671
- pathBasename("file.txt", ".txt"); // "file"
672
- ```
673
-
674
- ### pathExtname
675
-
676
- Extract extension (`path.extname` replacement). Returns empty string for hidden files (e.g., `.gitignore`).
677
-
678
- ```typescript
679
- import { pathExtname } from "@simplysm/core-common";
680
-
681
- pathExtname("file.txt"); // ".txt"
682
- pathExtname(".gitignore"); // ""
683
- pathExtname("archive.tar.gz"); // ".gz"
684
- ```
685
-
686
- ---
687
-
688
- ## Template literal tags (template-strings)
689
-
690
- Tag functions for IDE code highlighting. Actual behavior is string combination + leading/trailing blank line removal + common indentation removal.
691
-
692
- ### js
693
-
694
- JavaScript code highlighting.
695
-
696
- ```typescript
697
- import { js } from "@simplysm/core-common";
698
-
699
- const code = js`
700
- function hello() {
701
- return "world";
702
- }
703
- `;
704
- ```
705
-
706
- ### ts
707
-
708
- TypeScript code highlighting.
709
-
710
- ```typescript
711
- import { ts } from "@simplysm/core-common";
712
- ```
713
-
714
- ### html
715
-
716
- HTML markup highlighting.
717
-
718
- ```typescript
719
- import { html } from "@simplysm/core-common";
720
- ```
721
-
722
- ### tsql
723
-
724
- MSSQL T-SQL highlighting.
725
-
726
- ```typescript
727
- import { tsql } from "@simplysm/core-common";
728
-
729
- const query = tsql`
730
- SELECT TOP 10 *
731
- FROM Users
732
- WHERE Name LIKE '%${keyword}%'
733
- `;
734
- ```
735
-
736
- ### mysql
737
-
738
- MySQL SQL highlighting.
739
-
740
- ```typescript
741
- import { mysql } from "@simplysm/core-common";
742
- ```
743
-
744
- ### pgsql
745
-
746
- PostgreSQL SQL highlighting.
747
-
748
- ```typescript
749
- import { pgsql } from "@simplysm/core-common";
750
- ```
751
-
752
- ---
753
-
754
- ## Other utilities
755
-
756
- ### getPrimitiveTypeStr
757
-
758
- Infer `PrimitiveTypeStr` from runtime value.
759
-
760
- ```typescript
761
- import { getPrimitiveTypeStr } from "@simplysm/core-common";
762
-
763
- getPrimitiveTypeStr("hello"); // "string"
764
- getPrimitiveTypeStr(123); // "number"
765
- getPrimitiveTypeStr(new DateTime()); // "DateTime"
766
- getPrimitiveTypeStr(new Uint8Array()); // "Bytes"
767
- ```
768
-
769
- ### env
770
-
771
- Environment variable object (`DEV`, `VER`, etc.).
772
-
773
- ```typescript
774
- import { env } from "@simplysm/core-common";
775
-
776
- if (env.DEV) {
777
- console.log("Development mode");
778
- }
779
- console.log(`Version: ${env.VER}`);
780
- ```