@simplysm/core-common 13.0.99 → 14.0.1

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 (181) hide show
  1. package/dist/common.types.d.ts +14 -14
  2. package/dist/common.types.js +2 -1
  3. package/dist/common.types.js.map +1 -6
  4. package/dist/env.d.ts +5 -0
  5. package/dist/env.d.ts.map +1 -1
  6. package/dist/env.js +12 -8
  7. package/dist/env.js.map +1 -6
  8. package/dist/errors/argument-error.d.ts +10 -10
  9. package/dist/errors/argument-error.d.ts.map +1 -1
  10. package/dist/errors/argument-error.js +31 -14
  11. package/dist/errors/argument-error.js.map +1 -6
  12. package/dist/errors/not-implemented-error.d.ts +8 -8
  13. package/dist/errors/not-implemented-error.js +30 -12
  14. package/dist/errors/not-implemented-error.js.map +1 -6
  15. package/dist/errors/sd-error.d.ts +10 -10
  16. package/dist/errors/sd-error.d.ts.map +1 -1
  17. package/dist/errors/sd-error.js +45 -24
  18. package/dist/errors/sd-error.js.map +1 -6
  19. package/dist/errors/timeout-error.d.ts +10 -10
  20. package/dist/errors/timeout-error.js +34 -15
  21. package/dist/errors/timeout-error.js.map +1 -6
  22. package/dist/extensions/arr-ext.d.ts +2 -2
  23. package/dist/extensions/arr-ext.helpers.d.ts +10 -10
  24. package/dist/extensions/arr-ext.helpers.js +112 -89
  25. package/dist/extensions/arr-ext.helpers.js.map +1 -6
  26. package/dist/extensions/arr-ext.js +458 -422
  27. package/dist/extensions/arr-ext.js.map +1 -6
  28. package/dist/extensions/arr-ext.types.d.ts +57 -57
  29. package/dist/extensions/arr-ext.types.d.ts.map +1 -1
  30. package/dist/extensions/arr-ext.types.js +6 -1
  31. package/dist/extensions/arr-ext.types.js.map +1 -6
  32. package/dist/extensions/map-ext.d.ts +16 -16
  33. package/dist/extensions/map-ext.js +27 -22
  34. package/dist/extensions/map-ext.js.map +1 -6
  35. package/dist/extensions/set-ext.d.ts +11 -11
  36. package/dist/extensions/set-ext.js +32 -25
  37. package/dist/extensions/set-ext.js.map +1 -6
  38. package/dist/features/debounce-queue.d.ts +17 -17
  39. package/dist/features/debounce-queue.js +98 -70
  40. package/dist/features/debounce-queue.js.map +1 -6
  41. package/dist/features/event-emitter.d.ts +20 -20
  42. package/dist/features/event-emitter.js +101 -78
  43. package/dist/features/event-emitter.js.map +1 -6
  44. package/dist/features/serial-queue.d.ts +11 -11
  45. package/dist/features/serial-queue.js +78 -57
  46. package/dist/features/serial-queue.js.map +1 -6
  47. package/dist/globals.d.ts +4 -4
  48. package/dist/globals.js +9 -1
  49. package/dist/globals.js.map +1 -6
  50. package/dist/index.js +28 -27
  51. package/dist/index.js.map +1 -6
  52. package/dist/types/date-only.d.ts +64 -64
  53. package/dist/types/date-only.d.ts.map +1 -1
  54. package/dist/types/date-only.js +263 -252
  55. package/dist/types/date-only.js.map +1 -6
  56. package/dist/types/date-time.d.ts +36 -36
  57. package/dist/types/date-time.d.ts.map +1 -1
  58. package/dist/types/date-time.js +196 -288
  59. package/dist/types/date-time.js.map +1 -6
  60. package/dist/types/lazy-gc-map.d.ts +26 -26
  61. package/dist/types/lazy-gc-map.d.ts.map +1 -1
  62. package/dist/types/lazy-gc-map.js +202 -159
  63. package/dist/types/lazy-gc-map.js.map +1 -6
  64. package/dist/types/time.d.ts +23 -23
  65. package/dist/types/time.d.ts.map +1 -1
  66. package/dist/types/time.js +169 -158
  67. package/dist/types/time.js.map +1 -6
  68. package/dist/types/uuid.d.ts +11 -11
  69. package/dist/types/uuid.d.ts.map +1 -1
  70. package/dist/types/uuid.js +95 -70
  71. package/dist/types/uuid.js.map +1 -6
  72. package/dist/utils/bytes.d.ts +17 -17
  73. package/dist/utils/bytes.js +137 -81
  74. package/dist/utils/bytes.js.map +1 -6
  75. package/dist/utils/date-format.d.ts +40 -40
  76. package/dist/utils/date-format.js +187 -101
  77. package/dist/utils/date-format.js.map +1 -6
  78. package/dist/utils/error.d.ts +4 -4
  79. package/dist/utils/error.js +11 -6
  80. package/dist/utils/error.js.map +1 -6
  81. package/dist/utils/json.d.ts +19 -19
  82. package/dist/utils/json.js +187 -135
  83. package/dist/utils/json.js.map +1 -6
  84. package/dist/utils/num.d.ts +20 -20
  85. package/dist/utils/num.js +76 -34
  86. package/dist/utils/num.js.map +1 -6
  87. package/dist/utils/obj.d.ts +111 -111
  88. package/dist/utils/obj.d.ts.map +1 -1
  89. package/dist/utils/obj.js +706 -496
  90. package/dist/utils/obj.js.map +1 -6
  91. package/dist/utils/path.d.ts +10 -10
  92. package/dist/utils/path.js +35 -18
  93. package/dist/utils/path.js.map +1 -6
  94. package/dist/utils/primitive.d.ts +5 -5
  95. package/dist/utils/primitive.js +34 -14
  96. package/dist/utils/primitive.js.map +1 -6
  97. package/dist/utils/str.d.ts +38 -38
  98. package/dist/utils/str.js +217 -113
  99. package/dist/utils/str.js.map +1 -6
  100. package/dist/utils/template-strings.d.ts +26 -26
  101. package/dist/utils/template-strings.js +113 -40
  102. package/dist/utils/template-strings.js.map +1 -6
  103. package/dist/utils/transferable.d.ts +18 -18
  104. package/dist/utils/transferable.js +218 -151
  105. package/dist/utils/transferable.js.map +1 -6
  106. package/dist/utils/wait.d.ts +9 -9
  107. package/dist/utils/wait.js +30 -15
  108. package/dist/utils/wait.js.map +1 -6
  109. package/dist/utils/xml.d.ts +13 -13
  110. package/dist/utils/xml.js +84 -46
  111. package/dist/utils/xml.js.map +1 -6
  112. package/dist/utils/zip.d.ts +22 -22
  113. package/dist/utils/zip.js +172 -148
  114. package/dist/utils/zip.js.map +1 -6
  115. package/package.json +5 -7
  116. package/src/common.types.ts +14 -14
  117. package/src/env.ts +9 -1
  118. package/src/errors/argument-error.ts +15 -15
  119. package/src/errors/not-implemented-error.ts +9 -9
  120. package/src/errors/sd-error.ts +12 -12
  121. package/src/errors/timeout-error.ts +12 -12
  122. package/src/extensions/arr-ext.helpers.ts +16 -16
  123. package/src/extensions/arr-ext.ts +35 -35
  124. package/src/extensions/arr-ext.types.ts +57 -57
  125. package/src/extensions/map-ext.ts +16 -16
  126. package/src/extensions/set-ext.ts +11 -11
  127. package/src/features/debounce-queue.ts +23 -23
  128. package/src/features/event-emitter.ts +25 -25
  129. package/src/features/serial-queue.ts +13 -13
  130. package/src/globals.ts +4 -4
  131. package/src/index.ts +5 -5
  132. package/src/types/date-only.ts +84 -83
  133. package/src/types/date-time.ts +43 -42
  134. package/src/types/lazy-gc-map.ts +44 -44
  135. package/src/types/time.ts +29 -29
  136. package/src/types/uuid.ts +15 -15
  137. package/src/utils/bytes.ts +35 -35
  138. package/src/utils/date-format.ts +59 -59
  139. package/src/utils/error.ts +4 -4
  140. package/src/utils/json.ts +41 -41
  141. package/src/utils/num.ts +20 -20
  142. package/src/utils/obj.ts +138 -138
  143. package/src/utils/path.ts +10 -10
  144. package/src/utils/primitive.ts +6 -6
  145. package/src/utils/str.ts +48 -48
  146. package/src/utils/template-strings.ts +29 -29
  147. package/src/utils/transferable.ts +38 -38
  148. package/src/utils/wait.ts +10 -10
  149. package/src/utils/xml.ts +19 -19
  150. package/src/utils/zip.ts +25 -25
  151. package/README.md +0 -160
  152. package/docs/errors.md +0 -119
  153. package/docs/extensions.md +0 -387
  154. package/docs/features.md +0 -143
  155. package/docs/types.md +0 -287
  156. package/docs/utils.md +0 -757
  157. package/tests/errors/errors.spec.ts +0 -80
  158. package/tests/extensions/array-extension.spec.ts +0 -654
  159. package/tests/extensions/map-extension.spec.ts +0 -117
  160. package/tests/extensions/set-extension.spec.ts +0 -67
  161. package/tests/types/date-only.spec.ts +0 -533
  162. package/tests/types/date-time.spec.ts +0 -246
  163. package/tests/types/lazy-gc-map.spec.ts +0 -606
  164. package/tests/types/time.spec.ts +0 -428
  165. package/tests/types/uuid.spec.ts +0 -74
  166. package/tests/utils/bytes-utils.spec.ts +0 -197
  167. package/tests/utils/date-format.spec.ts +0 -350
  168. package/tests/utils/debounce-queue.spec.ts +0 -226
  169. package/tests/utils/json.spec.ts +0 -400
  170. package/tests/utils/number.spec.ts +0 -136
  171. package/tests/utils/object.spec.ts +0 -810
  172. package/tests/utils/path.spec.ts +0 -70
  173. package/tests/utils/primitive.spec.ts +0 -43
  174. package/tests/utils/sd-event-emitter.spec.ts +0 -189
  175. package/tests/utils/serial-queue.spec.ts +0 -305
  176. package/tests/utils/string.spec.ts +0 -265
  177. package/tests/utils/template-strings.spec.ts +0 -48
  178. package/tests/utils/transferable.spec.ts +0 -639
  179. package/tests/utils/wait.spec.ts +0 -123
  180. package/tests/utils/xml.spec.ts +0 -146
  181. package/tests/utils/zip.spec.ts +0 -221
package/src/utils/xml.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * XML conversion utility
2
+ * XML 변환 유틸리티
3
3
  */
4
4
  import type { XmlBuilderOptions } from "fast-xml-parser";
5
5
  import { XMLBuilder, XMLParser } from "fast-xml-parser";
@@ -7,14 +7,14 @@ import { XMLBuilder, XMLParser } from "fast-xml-parser";
7
7
  //#region parse
8
8
 
9
9
  /**
10
- * Parse XML string into an object
11
- * @param str XML string
12
- * @param options Options
13
- * @param options.stripTagPrefix Whether to remove tag prefix (namespace)
14
- * @returns Parsed object. Structure:
15
- * - Attributes: grouped in `$` object
16
- * - Text nodes: stored in `_` key
17
- * - Child elements: converted to array (except root element)
10
+ * XML 문자열을 객체로 파싱
11
+ * @param str XML 문자열
12
+ * @param options 옵션
13
+ * @param options.stripTagPrefix 태그 접두사(네임스페이스) 제거 여부
14
+ * @returns 파싱된 객체. 구조:
15
+ * - 속성: `$` 객체에 그룹화
16
+ * - 텍스트 노드: `_` key에 저장
17
+ * - 자식 요소: array로 변환 (루트 요소 제외)
18
18
  * @example
19
19
  * xmlParse('<root id="1"><item>hello</item></root>');
20
20
  * // { root: { $: { id: "1" }, item: [{ _: "hello" }] } }
@@ -40,10 +40,10 @@ export function parse(str: string, options?: { stripTagPrefix?: boolean }): unkn
40
40
  //#region stringify
41
41
 
42
42
  /**
43
- * Serialize object to XML string
44
- * @param obj Object to serialize
45
- * @param options fast-xml-parser XmlBuilderOptions (optional)
46
- * @returns XML string
43
+ * 객체를 XML 문자열로 직렬화
44
+ * @param obj 직렬화할 객체
45
+ * @param options fast-xml-parser XmlBuilderOptions (선택사항)
46
+ * @returns XML 문자열
47
47
  * @example
48
48
  * xmlStringify({
49
49
  * root: {
@@ -69,10 +69,10 @@ export function stringify(obj: unknown, options?: XmlBuilderOptions): string {
69
69
  //#region private
70
70
 
71
71
  /**
72
- * Remove namespace prefix from tag name
73
- * @note Removes the namespace prefix in the format "ns:tag" from XML parsing results, leaving only the tag name.
74
- * This allows consistent access to XML data without considering namespace.
75
- * However, attributes are kept with their prefix.
72
+ * 태그 이름에서 네임스페이스 접두사 제거
73
+ * @note XML 파싱 결과에서 "ns:tag" 형식의 네임스페이스 접두사를 제거하여 태그 이름만 남김.
74
+ * 네임스페이스를 고려하지 않고 XML 데이터에 일관되게 접근 가능.
75
+ * 단, 속성은 접두사가 유지됨.
76
76
  */
77
77
  function stripTagPrefix(obj: unknown): unknown {
78
78
  if (Array.isArray(obj)) {
@@ -86,11 +86,11 @@ function stripTagPrefix(obj: unknown): unknown {
86
86
  for (const key of Object.keys(record)) {
87
87
  const value = record[key];
88
88
 
89
- // Attributes must not have prefix removed
89
+ // 속성은 접두사를 제거하면
90
90
  if (key === "$") {
91
91
  newObj[key] = value;
92
92
  } else {
93
- // Remove prefix from tag names only, based on first ":"
93
+ // 번째 ":"를 기준으로 태그 이름에서만 접두사 제거
94
94
  const colonIndex = key.indexOf(":");
95
95
  const cleanKey = colonIndex !== -1 ? key.slice(colonIndex + 1) : key;
96
96
  newObj[cleanKey] = stripTagPrefix(value);
package/src/utils/zip.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * ZIP file processing utility
2
+ * ZIP 파일 처리 유틸리티
3
3
  */
4
4
  import type { FileEntry } from "@zip.js/zip.js";
5
5
  import {
@@ -18,25 +18,25 @@ export interface ZipArchiveProgress {
18
18
  }
19
19
 
20
20
  /**
21
- * ZIP archive processing class
21
+ * ZIP 아카이브 처리 클래스
22
22
  *
23
- * Handles reading, writing, compression, and decompression of ZIP files.
24
- * Uses internal caching to prevent duplicate decompression of the same file.
23
+ * ZIP 파일의 읽기, 쓰기, 압축, 해제를 처리.
24
+ * 동일 파일의 중복 해제를 방지하기 위해 내부 캐싱 사용.
25
25
  *
26
26
  * @example
27
- * // Read ZIP file
27
+ * // ZIP 파일 읽기
28
28
  * await using archive = new ZipArchive(zipBytes);
29
29
  * const content = await archive.get("file.txt");
30
30
  *
31
31
  * @example
32
- * // Create ZIP file
32
+ * // ZIP 파일 생성
33
33
  * await using archive = new ZipArchive();
34
34
  * archive.write("file.txt", textBytes);
35
35
  * archive.write("data.json", jsonBytes);
36
36
  * const zipBytes = await archive.compress();
37
37
  *
38
38
  * @example
39
- * // Extract all files (with progress reporting)
39
+ * // 모든 파일 추출 (진행률 보고 포함)
40
40
  * await using archive = new ZipArchive(zipBytes);
41
41
  * const files = await archive.extractAll((progress) => {
42
42
  * console.log(`${progress.fileName}: ${progress.extractedSize}/${progress.totalSize}`);
@@ -48,8 +48,8 @@ export class ZipArchive {
48
48
  private _entries?: Awaited<ReturnType<ZipReader<Blob | Bytes>["getEntries"]>>;
49
49
 
50
50
  /**
51
- * Create ZipArchive
52
- * @param data ZIP data (omit to create a new archive)
51
+ * ZipArchive 생성
52
+ * @param data ZIP 데이터 (생략하면 아카이브 생성)
53
53
  */
54
54
  constructor(data?: Blob | Bytes) {
55
55
  if (!data) return;
@@ -70,8 +70,8 @@ export class ZipArchive {
70
70
 
71
71
  //#region extractAll
72
72
  /**
73
- * Extract all files
74
- * @param progressCallback Progress callback
73
+ * 모든 파일 추출
74
+ * @param progressCallback 진행률 콜백
75
75
  */
76
76
  async extractAll(
77
77
  progressCallback?: (progress: ZipArchiveProgress) => void,
@@ -79,7 +79,7 @@ export class ZipArchive {
79
79
  const entries = await this._getEntries();
80
80
  if (entries == null) return this._cache;
81
81
 
82
- // Calculate total size to extract
82
+ // 추출할 전체 크기 계산
83
83
  const totalSize = entries
84
84
  .filter((e) => !e.directory)
85
85
  .reduce((acc, e) => acc + e.uncompressedSize, 0);
@@ -112,7 +112,7 @@ export class ZipArchive {
112
112
 
113
113
  this._cache.set(entry.filename, entryBytes);
114
114
 
115
- // Accumulate when individual file completes
115
+ // 개별 파일 완료 누적
116
116
  totalExtracted += entry.uncompressedSize;
117
117
 
118
118
  progressCallback?.({
@@ -128,8 +128,8 @@ export class ZipArchive {
128
128
 
129
129
  //#region get
130
130
  /**
131
- * Extract specific file
132
- * @param fileName File name
131
+ * 특정 파일 추출
132
+ * @param fileName 파일 이름
133
133
  */
134
134
  async get(fileName: string): Promise<Bytes | undefined> {
135
135
  if (this._cache.has(fileName)) {
@@ -156,8 +156,8 @@ export class ZipArchive {
156
156
 
157
157
  //#region exists
158
158
  /**
159
- * Check if file exists
160
- * @param fileName File name
159
+ * 파일 존재 여부 확인
160
+ * @param fileName 파일 이름
161
161
  */
162
162
  async exists(fileName: string): Promise<boolean> {
163
163
  if (this._cache.has(fileName)) {
@@ -176,9 +176,9 @@ export class ZipArchive {
176
176
 
177
177
  //#region write
178
178
  /**
179
- * Write file (store in cache)
180
- * @param fileName File name
181
- * @param bytes File content
179
+ * 파일 쓰기 (캐시에 저장)
180
+ * @param fileName 파일 이름
181
+ * @param bytes 파일 내용
182
182
  */
183
183
  write(fileName: string, bytes: Bytes): void {
184
184
  this._cache.set(fileName, bytes);
@@ -187,11 +187,11 @@ export class ZipArchive {
187
187
 
188
188
  //#region compress
189
189
  /**
190
- * Compress cached files to ZIP
190
+ * 캐시된 파일을 ZIP으로 압축
191
191
  *
192
192
  * @remarks
193
- * Internally calls `extractAll()` to load all files into memory before compressing.
194
- * Be mindful of memory usage when dealing with large ZIP files.
193
+ * 내부적으로 `extractAll()`을 호출하여 모든 파일을 메모리에 로드한 압축.
194
+ * 대용량 ZIP 파일 처리 메모리 사용량에 주의.
195
195
  */
196
196
  async compress(): Promise<Bytes> {
197
197
  const fileMap = await this.extractAll();
@@ -211,7 +211,7 @@ export class ZipArchive {
211
211
 
212
212
  //#region close
213
213
  /**
214
- * Close reader and clear cache
214
+ * 리더 닫기 캐시 비우기
215
215
  */
216
216
  async close(): Promise<void> {
217
217
  await this._reader?.close();
@@ -219,7 +219,7 @@ export class ZipArchive {
219
219
  }
220
220
 
221
221
  /**
222
- * Support for await using
222
+ * await using 지원
223
223
  */
224
224
  async [Symbol.asyncDispose](): Promise<void> {
225
225
  await this.close();
package/README.md DELETED
@@ -1,160 +0,0 @@
1
- # @simplysm/core-common
2
-
3
- Core module (common) -- platform-neutral core utilities for the Simplysm framework.
4
-
5
- Provides error classes, immutable date/time types, prototype extensions, event handling, and utility namespaces that work in both browser and Node.js environments.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install @simplysm/core-common
11
- ```
12
-
13
- ## Side-Effect Imports
14
-
15
- Importing the package entry point (`@simplysm/core-common`) automatically patches `Array`, `Map`, and `Set` prototypes with extension methods. These are declared as side effects in `package.json`:
16
-
17
- - `extensions/arr-ext` -- Array prototype extensions
18
- - `extensions/map-ext` -- Map prototype extensions
19
- - `extensions/set-ext` -- Set prototype extensions
20
-
21
- If you import only specific modules (e.g., `@simplysm/core-common/dist/types/date-time`), the prototype extensions are **not** applied unless you also import the entry point or the extension modules directly.
22
-
23
- ## API Overview
24
-
25
- ### Errors
26
-
27
- | API | Type | Description |
28
- |-----|------|-------------|
29
- | `SdError` | class | Error with tree-structured cause chaining |
30
- | `ArgumentError` | class | Invalid argument error with YAML-formatted details |
31
- | `NotImplementedError` | class | Unimplemented feature error |
32
- | `TimeoutError` | class | Waiting time exceeded error |
33
-
34
- -> See [docs/errors.md](./docs/errors.md) for details.
35
-
36
- ### Types
37
-
38
- | API | Type | Description |
39
- |-----|------|-------------|
40
- | `Uuid` | class | UUID v4 generation and parsing |
41
- | `DateTime` | class | Immutable date+time (millisecond precision) |
42
- | `DateOnly` | class | Immutable date without time |
43
- | `Time` | class | Immutable time without date (24h wraparound) |
44
- | `LazyGcMap` | class | Map with LRU-based automatic expiration |
45
- | `Bytes` | type alias | `Uint8Array` (replaces `Buffer`) |
46
- | `PrimitiveTypeMap` | type | Mapping of type name strings to types |
47
- | `PrimitiveTypeStr` | type | `keyof PrimitiveTypeMap` |
48
- | `PrimitiveType` | type | Union of all primitive types |
49
- | `DeepPartial<T>` | type | Recursively makes all properties optional |
50
- | `Type<T>` | interface | Constructor type for DI and factory patterns |
51
- | `env` | const | Unified `DEV` / `VER` environment accessor |
52
-
53
- -> See [docs/types.md](./docs/types.md) for details.
54
-
55
- ### Features
56
-
57
- | API | Type | Description |
58
- |-----|------|-------------|
59
- | `EventEmitter` | class | Type-safe event emitter (EventTarget wrapper) |
60
- | `DebounceQueue` | class | Async debounce -- only the last call executes |
61
- | `SerialQueue` | class | Async serial execution queue |
62
-
63
- -> See [docs/features.md](./docs/features.md) for details.
64
-
65
- ### Prototype Extensions (side-effect)
66
-
67
- | API | Type | Description |
68
- |-----|------|-------------|
69
- | `Array` extensions | prototype | 34 methods -- query, transform, diff, sort, mutate |
70
- | `Map` extensions | prototype | `getOrCreate`, `update` |
71
- | `Set` extensions | prototype | `adds`, `toggle` |
72
-
73
- -> See [docs/extensions.md](./docs/extensions.md) for details.
74
-
75
- ### Utilities
76
-
77
- | API | Type | Description |
78
- |-----|------|-------------|
79
- | `obj` | namespace | clone, equal, merge, merge3, omit, pick, chain access |
80
- | `str` | namespace | Korean particles, case conversion, full-width replacement |
81
- | `num` | namespace | parseInt, parseFloat, format with separators |
82
- | `bytes` | namespace | concat, hex, base64 conversion |
83
- | `path` | namespace | POSIX-only join, basename, extname |
84
- | `json` | namespace | Custom-type-aware JSON stringify/parse |
85
- | `xml` | namespace | XML parse/stringify via fast-xml-parser |
86
- | `wait` | namespace | `until` (polling) and `time` (delay) |
87
- | `transfer` | namespace | Worker-safe encode/decode for custom types |
88
- | `err` | namespace | Extract message from unknown error |
89
- | `dt` | namespace | Date format, month normalization, 12h/24h conversion |
90
- | `primitive` | namespace | Infer `PrimitiveTypeStr` from a value |
91
- | `js`, `ts`, `html`, `tsql`, `mysql`, `pgsql` | function | Template tag functions for syntax highlighting |
92
- | `ZipArchive` | class | ZIP read/write/compress with caching |
93
-
94
- -> See [docs/utils.md](./docs/utils.md) for details.
95
-
96
- ## Quick Usage Examples
97
-
98
- ### DateTime (immutable date/time)
99
-
100
- ```typescript
101
- import { DateTime, DateOnly } from "@simplysm/core-common";
102
-
103
- const now = new DateTime();
104
- const tomorrow = now.addDays(1);
105
- const formatted = now.toFormatString("yyyy-MM-dd HH:mm:ss");
106
- const parsed = DateTime.parse("2025-01-15 10:30:00");
107
-
108
- const today = new DateOnly();
109
- const weekInfo = today.getWeekSeqOfYear(); // { year, weekSeq }
110
- ```
111
-
112
- ### Object utilities
113
-
114
- ```typescript
115
- import { obj, json } from "@simplysm/core-common";
116
-
117
- const cloned = obj.clone(deepObject);
118
- const isEqual = obj.equal(a, b, { ignoreArrayIndex: true });
119
- const merged = obj.merge(base, override);
120
- const value = obj.getChainValue(data, "a.b[0].c");
121
-
122
- // Custom-type-aware JSON
123
- const str = json.stringify({ date: new DateTime(), id: Uuid.generate() });
124
- const restored = json.parse(str); // DateTime and Uuid instances restored
125
- ```
126
-
127
- ### Array extensions
128
-
129
- ```typescript
130
- import "@simplysm/core-common";
131
-
132
- const items = [3, 1, 4, 1, 5];
133
- items.distinct(); // [3, 1, 4, 5]
134
- items.orderBy(); // [1, 1, 3, 4, 5]
135
- items.sum(); // 14
136
- items.groupBy((x) => x % 2 === 0 ? "even" : "odd");
137
-
138
- const users = [{ id: 1, name: "A" }, { id: 2, name: "B" }];
139
- users.toMap((u) => u.id); // Map { 1 => {...}, 2 => {...} }
140
- users.single((u) => u.id === 1); // { id: 1, name: "A" }
141
- ```
142
-
143
- ### EventEmitter
144
-
145
- ```typescript
146
- import { EventEmitter } from "@simplysm/core-common";
147
-
148
- interface MyEvents { data: string; done: void }
149
-
150
- class MyService extends EventEmitter<MyEvents> {}
151
-
152
- const svc = new MyService();
153
- svc.on("data", (msg) => console.log(msg));
154
- svc.emit("data", "hello");
155
- svc.emit("done");
156
- ```
157
-
158
- ## License
159
-
160
- Apache-2.0
package/docs/errors.md DELETED
@@ -1,119 +0,0 @@
1
- # Errors
2
-
3
- Error classes for the Simplysm framework. All classes extend `SdError`, which itself extends `Error`.
4
-
5
- Source: `src/errors/*.ts`
6
-
7
- ---
8
-
9
- ## `SdError`
10
-
11
- Error class supporting tree-structured cause chaining. Utilizes ES2024 `cause` property. Messages are joined in reverse order with ` => ` separator, and cause stack traces are appended.
12
-
13
- ```typescript
14
- export class SdError extends Error {
15
- override cause?: Error;
16
-
17
- /** Create by wrapping a cause error. Messages are joined in reverse order (upper message => lower message => cause message) */
18
- constructor(cause: Error, ...messages: string[]);
19
- /** Create with messages only. Messages are joined in reverse order (upper message => lower message) */
20
- constructor(...messages: string[]);
21
- }
22
- ```
23
-
24
- **Example:**
25
-
26
- ```typescript
27
- try {
28
- await fetch(url);
29
- } catch (err) {
30
- throw new SdError(err, "API call failed", "User load failed");
31
- }
32
- // Result message: "User load failed => API call failed => original error message"
33
-
34
- throw new SdError("invalid state", "processing not possible");
35
- // Result message: "processing not possible => invalid state"
36
- ```
37
-
38
- ---
39
-
40
- ## `ArgumentError`
41
-
42
- An error thrown when invalid arguments are received. Includes the argument object in YAML format in the message to facilitate debugging. Extends `SdError`.
43
-
44
- ```typescript
45
- export class ArgumentError extends SdError {
46
- /** Output argument object in YAML format with default message ("Invalid arguments.") */
47
- constructor(argObj: Record<string, unknown>);
48
- /** Output argument object in YAML format with a custom message */
49
- constructor(message: string, argObj: Record<string, unknown>);
50
- }
51
- ```
52
-
53
- **Example:**
54
-
55
- ```typescript
56
- throw new ArgumentError({ userId: 123, name: null });
57
- // Result message: "Invalid arguments.\n\nuserId: 123\nname: null"
58
-
59
- throw new ArgumentError("Invalid user", { userId: 123 });
60
- // Result message: "Invalid user\n\nuserId: 123"
61
- ```
62
-
63
- ---
64
-
65
- ## `NotImplementedError`
66
-
67
- An error thrown when a feature that has not yet been implemented is called. Extends `SdError`.
68
-
69
- ```typescript
70
- export class NotImplementedError extends SdError {
71
- /**
72
- * @param message Additional description message
73
- */
74
- constructor(message?: string);
75
- }
76
- ```
77
-
78
- **Example:**
79
-
80
- ```typescript
81
- class BaseService {
82
- process(): void {
83
- throw new NotImplementedError("Implementation required in subclass");
84
- }
85
- }
86
-
87
- switch (type) {
88
- case "A": return handleA();
89
- case "B": throw new NotImplementedError(`Handling for type ${type}`);
90
- }
91
- ```
92
-
93
- ---
94
-
95
- ## `TimeoutError`
96
-
97
- An error that occurs when the waiting time is exceeded. Automatically thrown when the maximum number of attempts is exceeded in `wait.until()`. Extends `SdError`.
98
-
99
- ```typescript
100
- export class TimeoutError extends SdError {
101
- /**
102
- * @param count Number of attempts
103
- * @param message Additional message
104
- */
105
- constructor(count?: number, message?: string);
106
- }
107
- ```
108
-
109
- **Example:**
110
-
111
- ```typescript
112
- try {
113
- await wait.until(() => isReady, 100, 50);
114
- } catch (err) {
115
- if (err instanceof TimeoutError) {
116
- // "Waiting time exceeded(50 attempts)"
117
- }
118
- }
119
- ```