@simplysm/core-common 13.0.97 → 13.0.99
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/README.md +160 -0
- package/docs/errors.md +119 -0
- package/docs/extensions.md +387 -0
- package/docs/features.md +143 -0
- package/docs/types.md +287 -0
- package/docs/utils.md +757 -0
- package/package.json +2 -2
package/docs/utils.md
ADDED
|
@@ -0,0 +1,757 @@
|
|
|
1
|
+
# Utilities
|
|
2
|
+
|
|
3
|
+
Utility namespaces and directly exported functions.
|
|
4
|
+
|
|
5
|
+
Source: `src/utils/*.ts`
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Namespace: `obj`
|
|
10
|
+
|
|
11
|
+
Object manipulation utilities. Source: `src/utils/obj.ts`
|
|
12
|
+
|
|
13
|
+
### `obj.clone`
|
|
14
|
+
|
|
15
|
+
Deep clone. Supports circular references and custom types (DateTime, DateOnly, Time, Uuid, Uint8Array, Error, Map, Set, RegExp). Functions and Symbols maintain references. Prototype chain is maintained.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
export function clone<TObj>(source: TObj): TObj;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### `obj.equal`
|
|
22
|
+
|
|
23
|
+
Deep equality comparison. Supports DateTime, DateOnly, Time, Uuid, Date, RegExp, Map, Set, Array, and plain objects.
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
export function equal(source: unknown, target: unknown, options?: EqualOptions): boolean;
|
|
27
|
+
|
|
28
|
+
export interface EqualOptions {
|
|
29
|
+
/** List of keys to compare (applies only to top level) */
|
|
30
|
+
topLevelIncludes?: string[];
|
|
31
|
+
/** List of keys to exclude from comparison (applies only to top level) */
|
|
32
|
+
topLevelExcludes?: string[];
|
|
33
|
+
/** Whether to ignore array order. O(n^2) complexity when true */
|
|
34
|
+
ignoreArrayIndex?: boolean;
|
|
35
|
+
/** Whether to do shallow comparison. Only compare 1 level (reference comparison) when true */
|
|
36
|
+
shallow?: boolean;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### `obj.merge`
|
|
41
|
+
|
|
42
|
+
Deep merge (merge target into source as base). Returns a new object without modifying originals.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
export function merge<TSource, TMergeTarget>(
|
|
46
|
+
source: TSource,
|
|
47
|
+
target: TMergeTarget,
|
|
48
|
+
opt?: MergeOptions,
|
|
49
|
+
): TSource & TMergeTarget;
|
|
50
|
+
|
|
51
|
+
export interface MergeOptions {
|
|
52
|
+
/** Array processing method. "replace": replace with target (default), "concat": merge (deduplicate) */
|
|
53
|
+
arrayProcess?: "replace" | "concat";
|
|
54
|
+
/** Whether to delete the key when target is null */
|
|
55
|
+
useDelTargetNull?: boolean;
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### `obj.merge3`
|
|
60
|
+
|
|
61
|
+
3-way merge. Compares source, origin, and target to produce a merged result with conflict detection.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
export function merge3<
|
|
65
|
+
S extends Record<string, unknown>,
|
|
66
|
+
O extends Record<string, unknown>,
|
|
67
|
+
T extends Record<string, unknown>,
|
|
68
|
+
>(
|
|
69
|
+
source: S,
|
|
70
|
+
origin: O,
|
|
71
|
+
target: T,
|
|
72
|
+
optionsObj?: Record<string, Merge3KeyOptions>,
|
|
73
|
+
): { conflict: boolean; result: O & S & T };
|
|
74
|
+
|
|
75
|
+
export interface Merge3KeyOptions {
|
|
76
|
+
/** List of sub-keys to compare (same as equal's topLevelIncludes) */
|
|
77
|
+
keys?: string[];
|
|
78
|
+
/** List of sub-keys to exclude from comparison */
|
|
79
|
+
excludes?: string[];
|
|
80
|
+
/** Whether to ignore array order */
|
|
81
|
+
ignoreArrayIndex?: boolean;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### `obj.omit`
|
|
86
|
+
|
|
87
|
+
Exclude specific keys from object.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
export function omit<T extends Record<string, unknown>, K extends keyof T>(item: T, omitKeys: K[]): Omit<T, K>;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### `obj.omitByFilter`
|
|
94
|
+
|
|
95
|
+
Exclude keys matching condition.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
export function omitByFilter<T extends Record<string, unknown>>(item: T, omitKeyFn: (key: keyof T) => boolean): T;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### `obj.pick`
|
|
102
|
+
|
|
103
|
+
Select specific keys from object.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
export function pick<T extends Record<string, unknown>, K extends keyof T>(item: T, pickKeys: K[]): Pick<T, K>;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `obj.getChainValue`
|
|
110
|
+
|
|
111
|
+
Get value by chain path (e.g., `"a.b[0].c"`).
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
export function getChainValue(obj: unknown, chain: string): unknown;
|
|
115
|
+
export function getChainValue(obj: unknown, chain: string, optional: true): unknown | undefined;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### `obj.getChainValueByDepth`
|
|
119
|
+
|
|
120
|
+
Descend by the same key for depth levels.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
export function getChainValueByDepth<TObject, TKey extends keyof TObject>(
|
|
124
|
+
obj: TObject, key: TKey, depth: number,
|
|
125
|
+
): TObject[TKey];
|
|
126
|
+
export function getChainValueByDepth<TObject, TKey extends keyof TObject>(
|
|
127
|
+
obj: TObject, key: TKey, depth: number, optional: true,
|
|
128
|
+
): TObject[TKey] | undefined;
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### `obj.setChainValue`
|
|
132
|
+
|
|
133
|
+
Set value by chain path.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
export function setChainValue(obj: unknown, chain: string, value: unknown): void;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### `obj.deleteChainValue`
|
|
140
|
+
|
|
141
|
+
Delete value by chain path.
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
export function deleteChainValue(obj: unknown, chain: string): void;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### `obj.clearUndefined`
|
|
148
|
+
|
|
149
|
+
Delete keys with `undefined` values from object. Mutates the original.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
export function clearUndefined<T extends object>(obj: T): T;
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### `obj.clear`
|
|
156
|
+
|
|
157
|
+
Delete all keys from object. Mutates the original.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
export function clear<T extends Record<string, unknown>>(obj: T): Record<string, never>;
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### `obj.nullToUndefined`
|
|
164
|
+
|
|
165
|
+
Convert `null` to `undefined` recursively. Mutates the original.
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
export function nullToUndefined<TObject>(obj: TObject): TObject | undefined;
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### `obj.unflatten`
|
|
172
|
+
|
|
173
|
+
Convert flattened object to nested object.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
export function unflatten(flatObj: Record<string, unknown>): Record<string, unknown>;
|
|
177
|
+
// Example: unflatten({ "a.b.c": 1 }) => { a: { b: { c: 1 } } }
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### `obj.keys`
|
|
181
|
+
|
|
182
|
+
Type-safe `Object.keys`.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
export function keys<T extends object>(obj: T): (keyof T)[];
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### `obj.entries`
|
|
189
|
+
|
|
190
|
+
Type-safe `Object.entries`.
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
export function entries<T extends object>(obj: T): { [K in keyof T]: [K, T[K]] }[keyof T][];
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### `obj.fromEntries`
|
|
197
|
+
|
|
198
|
+
Type-safe `Object.fromEntries`.
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
export function fromEntries<T extends [string, unknown]>(entryPairs: T[]): { [K in T[0]]: T[1] };
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### `obj.map`
|
|
205
|
+
|
|
206
|
+
Transform each entry of object and return new object.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
export function map<TSource extends object, TNewKey extends string, TNewValue>(
|
|
210
|
+
obj: TSource,
|
|
211
|
+
fn: (key: keyof TSource, value: TSource[keyof TSource]) => [TNewKey | null, TNewValue],
|
|
212
|
+
): Record<TNewKey | Extract<keyof TSource, string>, TNewValue>;
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Example:**
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
const colors = { primary: "255, 0, 0", secondary: "0, 255, 0" };
|
|
219
|
+
|
|
220
|
+
// Transform only values (pass null for key to keep original)
|
|
221
|
+
obj.map(colors, (key, rgb) => [null, `rgb(${rgb})`]);
|
|
222
|
+
// { primary: "rgb(255, 0, 0)", secondary: "rgb(0, 255, 0)" }
|
|
223
|
+
|
|
224
|
+
// Transform both keys and values
|
|
225
|
+
obj.map(colors, (key, rgb) => [`${key}Light`, `rgb(${rgb})`]);
|
|
226
|
+
// { primaryLight: "rgb(255, 0, 0)", secondaryLight: "rgb(0, 255, 0)" }
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Type utilities from `obj`
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
/** Convert properties with undefined to optional */
|
|
233
|
+
export type UndefToOptional<TObject> = {
|
|
234
|
+
[K in keyof TObject as undefined extends TObject[K] ? K : never]?: TObject[K];
|
|
235
|
+
} & { [K in keyof TObject as undefined extends TObject[K] ? never : K]: TObject[K] };
|
|
236
|
+
|
|
237
|
+
/** Convert optional properties to required + undefined union */
|
|
238
|
+
export type OptionalToUndef<TObject> = {
|
|
239
|
+
[K in keyof TObject]-?: {} extends Pick<TObject, K> ? TObject[K] | undefined : TObject[K];
|
|
240
|
+
};
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Namespace: `str`
|
|
246
|
+
|
|
247
|
+
String utility functions. Source: `src/utils/str.ts`
|
|
248
|
+
|
|
249
|
+
### `str.getKoreanSuffix`
|
|
250
|
+
|
|
251
|
+
Return the appropriate Korean particle based on the final consonant (jongseong).
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
export function getKoreanSuffix(
|
|
255
|
+
text: string,
|
|
256
|
+
type: "을" | "은" | "이" | "와" | "랑" | "로" | "라",
|
|
257
|
+
): string;
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
| Type | With final consonant | Without final consonant |
|
|
261
|
+
|------|---------------------|------------------------|
|
|
262
|
+
| `"을"` | 을 | 를 |
|
|
263
|
+
| `"은"` | 은 | 는 |
|
|
264
|
+
| `"이"` | 이 | 가 |
|
|
265
|
+
| `"와"` | 과 | 와 |
|
|
266
|
+
| `"랑"` | 이랑 | 랑 |
|
|
267
|
+
| `"로"` | 으로 | 로 |
|
|
268
|
+
| `"라"` | 이라 | 라 |
|
|
269
|
+
|
|
270
|
+
### `str.replaceFullWidth`
|
|
271
|
+
|
|
272
|
+
Convert full-width characters to half-width (A-Z, a-z, 0-9, space, parentheses).
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
export function replaceFullWidth(str: string): string;
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### `str.toPascalCase`
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
export function toPascalCase(str: string): string;
|
|
282
|
+
// "hello-world" -> "HelloWorld"
|
|
283
|
+
// "hello_world" -> "HelloWorld"
|
|
284
|
+
// "hello.world" -> "HelloWorld"
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### `str.toCamelCase`
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
export function toCamelCase(str: string): string;
|
|
291
|
+
// "hello-world" -> "helloWorld"
|
|
292
|
+
// "hello_world" -> "helloWorld"
|
|
293
|
+
// "HelloWorld" -> "helloWorld"
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### `str.toKebabCase`
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
export function toKebabCase(str: string): string;
|
|
300
|
+
// "HelloWorld" -> "hello-world"
|
|
301
|
+
// "helloWorld" -> "hello-world"
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### `str.toSnakeCase`
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
export function toSnakeCase(str: string): string;
|
|
308
|
+
// "HelloWorld" -> "hello_world"
|
|
309
|
+
// "helloWorld" -> "hello_world"
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### `str.isNullOrEmpty`
|
|
313
|
+
|
|
314
|
+
Check if string is `undefined`, `null`, or empty (type guard).
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
export function isNullOrEmpty(str: string | undefined): str is "" | undefined;
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### `str.insert`
|
|
321
|
+
|
|
322
|
+
Insert a string at a specific position.
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
export function insert(str: string, index: number, insertString: string): string;
|
|
326
|
+
// insert("Hello World", 5, ",") => "Hello, World"
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## Namespace: `num`
|
|
332
|
+
|
|
333
|
+
Number utility functions. Source: `src/utils/num.ts`
|
|
334
|
+
|
|
335
|
+
### `num.parseInt`
|
|
336
|
+
|
|
337
|
+
Parse string to integer. Removes non-numeric characters before parsing.
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
export function parseInt(text: unknown): number | undefined;
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### `num.parseRoundedInt`
|
|
344
|
+
|
|
345
|
+
Parse string to float, then round and return integer.
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
export function parseRoundedInt(text: unknown): number | undefined;
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### `num.parseFloat`
|
|
352
|
+
|
|
353
|
+
Parse string to float. Removes non-numeric characters before parsing.
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
export function parseFloat(text: unknown): number | undefined;
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### `num.isNullOrEmpty`
|
|
360
|
+
|
|
361
|
+
Check `undefined`, `null`, `0` (type guard).
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
export function isNullOrEmpty(val: number | undefined): val is 0 | undefined;
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### `num.format`
|
|
368
|
+
|
|
369
|
+
Format number to string with thousand separators.
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
export function format(val: number, digit?: { max?: number; min?: number }): string;
|
|
373
|
+
export function format(val: number | undefined, digit?: { max?: number; min?: number }): string | undefined;
|
|
374
|
+
// num.format(1234.567, { max: 2 }) => "1,234.57"
|
|
375
|
+
// num.format(1234, { min: 2 }) => "1,234.00"
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Namespace: `bytes`
|
|
381
|
+
|
|
382
|
+
Uint8Array utility functions. Source: `src/utils/bytes.ts`
|
|
383
|
+
|
|
384
|
+
### `bytes.concat`
|
|
385
|
+
|
|
386
|
+
Concatenate multiple Uint8Arrays.
|
|
387
|
+
|
|
388
|
+
```typescript
|
|
389
|
+
export function concat(arrays: Bytes[]): Bytes;
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### `bytes.toHex`
|
|
393
|
+
|
|
394
|
+
Convert to lowercase hex string.
|
|
395
|
+
|
|
396
|
+
```typescript
|
|
397
|
+
export function toHex(bytes: Bytes): string;
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### `bytes.fromHex`
|
|
401
|
+
|
|
402
|
+
Convert from hex string to Uint8Array.
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
export function fromHex(hex: string): Bytes;
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### `bytes.toBase64`
|
|
409
|
+
|
|
410
|
+
Convert Bytes to base64 string.
|
|
411
|
+
|
|
412
|
+
```typescript
|
|
413
|
+
export function toBase64(bytes: Bytes): string;
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### `bytes.fromBase64`
|
|
417
|
+
|
|
418
|
+
Convert base64 string to Bytes.
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
export function fromBase64(base64: string): Bytes;
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## Namespace: `path`
|
|
427
|
+
|
|
428
|
+
Path utility functions. Replacement for Node.js `path` module (supports browser environments). POSIX style paths only (slash `/`).
|
|
429
|
+
|
|
430
|
+
Source: `src/utils/path.ts`
|
|
431
|
+
|
|
432
|
+
### `path.join`
|
|
433
|
+
|
|
434
|
+
Combine paths.
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
export function join(...segments: string[]): string;
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### `path.basename`
|
|
441
|
+
|
|
442
|
+
Extract filename.
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
export function basename(filePath: string, ext?: string): string;
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### `path.extname`
|
|
449
|
+
|
|
450
|
+
Extract file extension. Hidden files (e.g., `.gitignore`) return empty string.
|
|
451
|
+
|
|
452
|
+
```typescript
|
|
453
|
+
export function extname(filePath: string): string;
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## Namespace: `json`
|
|
459
|
+
|
|
460
|
+
JSON serialization/deserialization supporting custom types (DateTime, DateOnly, Time, Uuid, Set, Map, Error, Uint8Array).
|
|
461
|
+
|
|
462
|
+
Source: `src/utils/json.ts`
|
|
463
|
+
|
|
464
|
+
### `json.stringify`
|
|
465
|
+
|
|
466
|
+
Serialize object to JSON string. Supports custom types via `__type__` markers.
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
export function stringify(
|
|
470
|
+
obj: unknown,
|
|
471
|
+
options?: {
|
|
472
|
+
space?: string | number;
|
|
473
|
+
replacer?: (key: string | undefined, value: unknown) => unknown;
|
|
474
|
+
redactBytes?: boolean;
|
|
475
|
+
},
|
|
476
|
+
): string;
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### `json.parse`
|
|
480
|
+
|
|
481
|
+
Deserialize JSON string to object. Restores custom types from `__type__` markers. All JSON `null` values are converted to `undefined`.
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
export function parse<TResult = unknown>(json: string): TResult;
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
---
|
|
488
|
+
|
|
489
|
+
## Namespace: `xml`
|
|
490
|
+
|
|
491
|
+
XML conversion utility using fast-xml-parser.
|
|
492
|
+
|
|
493
|
+
Source: `src/utils/xml.ts`
|
|
494
|
+
|
|
495
|
+
### `xml.parse`
|
|
496
|
+
|
|
497
|
+
Parse XML string into an object. Attributes grouped in `$`, text nodes in `_`, child elements as arrays.
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
export function parse(str: string, options?: { stripTagPrefix?: boolean }): unknown;
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### `xml.stringify`
|
|
504
|
+
|
|
505
|
+
Serialize object to XML string.
|
|
506
|
+
|
|
507
|
+
```typescript
|
|
508
|
+
export function stringify(obj: unknown, options?: XmlBuilderOptions): string;
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
## Namespace: `wait`
|
|
514
|
+
|
|
515
|
+
Wait utility functions. Source: `src/utils/wait.ts`
|
|
516
|
+
|
|
517
|
+
### `wait.until`
|
|
518
|
+
|
|
519
|
+
Wait until a condition becomes true.
|
|
520
|
+
|
|
521
|
+
```typescript
|
|
522
|
+
export async function until(
|
|
523
|
+
forwarder: () => boolean | Promise<boolean>,
|
|
524
|
+
milliseconds?: number,
|
|
525
|
+
maxCount?: number,
|
|
526
|
+
): Promise<void>;
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
- `milliseconds`: Check interval (default: 100ms)
|
|
530
|
+
- `maxCount`: Maximum number of attempts (`undefined` for unlimited)
|
|
531
|
+
- Throws `TimeoutError` when maximum number of attempts is exceeded
|
|
532
|
+
|
|
533
|
+
### `wait.time`
|
|
534
|
+
|
|
535
|
+
Wait for a specified amount of time.
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
export async function time(millisecond: number): Promise<void>;
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
## Namespace: `transfer`
|
|
544
|
+
|
|
545
|
+
Transferable conversion utility for Worker data transfer. Handles custom types that `structuredClone` does not support.
|
|
546
|
+
|
|
547
|
+
Source: `src/utils/transferable.ts`
|
|
548
|
+
|
|
549
|
+
Supported types: Date, DateTime, DateOnly, Time, Uuid, RegExp, Error (including cause, code, detail), Uint8Array, Array, Map, Set, plain objects.
|
|
550
|
+
|
|
551
|
+
### `transfer.encode`
|
|
552
|
+
|
|
553
|
+
Convert objects using Simplysm types to plain objects for Worker transfer.
|
|
554
|
+
|
|
555
|
+
```typescript
|
|
556
|
+
export function encode(obj: unknown): {
|
|
557
|
+
result: unknown;
|
|
558
|
+
transferList: Transferable[];
|
|
559
|
+
};
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### `transfer.decode`
|
|
563
|
+
|
|
564
|
+
Convert serialized objects back to Simplysm types.
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
export function decode(obj: unknown): unknown;
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
**Example:**
|
|
571
|
+
|
|
572
|
+
```typescript
|
|
573
|
+
const { result, transferList } = transfer.encode(data);
|
|
574
|
+
worker.postMessage(result, transferList);
|
|
575
|
+
|
|
576
|
+
// In worker:
|
|
577
|
+
const decoded = transfer.decode(event.data);
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
---
|
|
581
|
+
|
|
582
|
+
## Namespace: `err`
|
|
583
|
+
|
|
584
|
+
Error utility. Source: `src/utils/error.ts`
|
|
585
|
+
|
|
586
|
+
### `err.message`
|
|
587
|
+
|
|
588
|
+
Extract message from unknown type error. Returns `message` property for `Error` instances, otherwise `String(err)`.
|
|
589
|
+
|
|
590
|
+
```typescript
|
|
591
|
+
export function message(err: unknown): string;
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
---
|
|
595
|
+
|
|
596
|
+
## Namespace: `dt`
|
|
597
|
+
|
|
598
|
+
Date format utilities. Source: `src/utils/date-format.ts`
|
|
599
|
+
|
|
600
|
+
### `dt.normalizeMonth`
|
|
601
|
+
|
|
602
|
+
Normalize year/month/day when setting month. Adjusts year for out-of-range months, clamps day to last day of month.
|
|
603
|
+
|
|
604
|
+
```typescript
|
|
605
|
+
export function normalizeMonth(year: number, month: number, day: number): DtNormalizedMonth;
|
|
606
|
+
|
|
607
|
+
export interface DtNormalizedMonth {
|
|
608
|
+
year: number;
|
|
609
|
+
month: number;
|
|
610
|
+
day: number;
|
|
611
|
+
}
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
### `dt.convert12To24`
|
|
615
|
+
|
|
616
|
+
Convert 12-hour format to 24-hour format.
|
|
617
|
+
|
|
618
|
+
```typescript
|
|
619
|
+
export function convert12To24(rawHour: number, isPM: boolean): number;
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
### `dt.format`
|
|
623
|
+
|
|
624
|
+
Convert date/time components to string according to format string. Supports C#-style format specifiers:
|
|
625
|
+
|
|
626
|
+
| Format | Description | Example |
|
|
627
|
+
|--------|-------------|---------|
|
|
628
|
+
| `yyyy` | 4-digit year | 2024 |
|
|
629
|
+
| `yy` | 2-digit year | 24 |
|
|
630
|
+
| `MM` | Zero-padded month | 01-12 |
|
|
631
|
+
| `M` | Month | 1-12 |
|
|
632
|
+
| `ddd` | Day of week (Korean) | 일, 월, 화, 수, 목, 금, 토 |
|
|
633
|
+
| `dd` | Zero-padded day | 01-31 |
|
|
634
|
+
| `d` | Day | 1-31 |
|
|
635
|
+
| `tt` | AM/PM | AM, PM |
|
|
636
|
+
| `hh` / `h` | 12-hour (zero-padded / plain) | 01-12 / 1-12 |
|
|
637
|
+
| `HH` / `H` | 24-hour (zero-padded / plain) | 00-23 / 0-23 |
|
|
638
|
+
| `mm` / `m` | Minute (zero-padded / plain) | 00-59 / 0-59 |
|
|
639
|
+
| `ss` / `s` | Second (zero-padded / plain) | 00-59 / 0-59 |
|
|
640
|
+
| `fff` / `ff` / `f` | Milliseconds (3/2/1 digits) | 000-999 |
|
|
641
|
+
| `zzz` / `zz` / `z` | Timezone offset | +09:00 / +09 / +9 |
|
|
642
|
+
|
|
643
|
+
```typescript
|
|
644
|
+
export function format(
|
|
645
|
+
formatString: string,
|
|
646
|
+
args: {
|
|
647
|
+
year?: number;
|
|
648
|
+
month?: number;
|
|
649
|
+
day?: number;
|
|
650
|
+
hour?: number;
|
|
651
|
+
minute?: number;
|
|
652
|
+
second?: number;
|
|
653
|
+
millisecond?: number;
|
|
654
|
+
timezoneOffsetMinutes?: number;
|
|
655
|
+
},
|
|
656
|
+
): string;
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
---
|
|
660
|
+
|
|
661
|
+
## Namespace: `primitive`
|
|
662
|
+
|
|
663
|
+
Primitive type inference. Source: `src/utils/primitive.ts`
|
|
664
|
+
|
|
665
|
+
### `primitive.typeStr`
|
|
666
|
+
|
|
667
|
+
Infer `PrimitiveTypeStr` from a value at runtime.
|
|
668
|
+
|
|
669
|
+
```typescript
|
|
670
|
+
export function typeStr(value: PrimitiveTypeMap[PrimitiveTypeStr]): PrimitiveTypeStr;
|
|
671
|
+
// primitive.typeStr("hello") => "string"
|
|
672
|
+
// primitive.typeStr(new DateTime()) => "DateTime"
|
|
673
|
+
// primitive.typeStr(new Uint8Array()) => "Bytes"
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
---
|
|
677
|
+
|
|
678
|
+
## Direct Exports: Template Tag Functions
|
|
679
|
+
|
|
680
|
+
Template string tag functions for IDE code highlighting support. Actual behavior is string concatenation with indent normalization (leading/trailing blank lines removed, common indentation stripped).
|
|
681
|
+
|
|
682
|
+
Source: `src/utils/template-strings.ts`
|
|
683
|
+
|
|
684
|
+
```typescript
|
|
685
|
+
export function js(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
686
|
+
export function ts(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
687
|
+
export function html(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
688
|
+
export function tsql(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
689
|
+
export function mysql(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
690
|
+
export function pgsql(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
**Example:**
|
|
694
|
+
|
|
695
|
+
```typescript
|
|
696
|
+
const query = tsql`
|
|
697
|
+
SELECT TOP 10 *
|
|
698
|
+
FROM Users
|
|
699
|
+
WHERE Name LIKE '%${keyword}%'
|
|
700
|
+
`;
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
---
|
|
704
|
+
|
|
705
|
+
## Direct Export: `ZipArchive`
|
|
706
|
+
|
|
707
|
+
ZIP archive processing class. Handles reading, writing, compression, and decompression of ZIP files. Uses internal caching to prevent duplicate decompression. Supports `await using` (`Symbol.asyncDispose`).
|
|
708
|
+
|
|
709
|
+
Source: `src/utils/zip.ts`
|
|
710
|
+
|
|
711
|
+
```typescript
|
|
712
|
+
export class ZipArchive {
|
|
713
|
+
/**
|
|
714
|
+
* @param data ZIP data (omit to create a new archive)
|
|
715
|
+
*/
|
|
716
|
+
constructor(data?: Blob | Bytes);
|
|
717
|
+
|
|
718
|
+
/** Extract all files with optional progress callback */
|
|
719
|
+
async extractAll(progressCallback?: (progress: ZipArchiveProgress) => void): Promise<Map<string, Bytes | undefined>>;
|
|
720
|
+
|
|
721
|
+
/** Extract specific file */
|
|
722
|
+
async get(fileName: string): Promise<Bytes | undefined>;
|
|
723
|
+
|
|
724
|
+
/** Check if file exists */
|
|
725
|
+
async exists(fileName: string): Promise<boolean>;
|
|
726
|
+
|
|
727
|
+
/** Write file (store in cache) */
|
|
728
|
+
write(fileName: string, bytes: Bytes): void;
|
|
729
|
+
|
|
730
|
+
/** Compress cached files to ZIP */
|
|
731
|
+
async compress(): Promise<Bytes>;
|
|
732
|
+
|
|
733
|
+
/** Close reader and clear cache */
|
|
734
|
+
async close(): Promise<void>;
|
|
735
|
+
|
|
736
|
+
async [Symbol.asyncDispose](): Promise<void>;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
export interface ZipArchiveProgress {
|
|
740
|
+
fileName: string;
|
|
741
|
+
totalSize: number;
|
|
742
|
+
extractedSize: number;
|
|
743
|
+
}
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
**Example:**
|
|
747
|
+
|
|
748
|
+
```typescript
|
|
749
|
+
// Read
|
|
750
|
+
await using archive = new ZipArchive(zipBytes);
|
|
751
|
+
const content = await archive.get("file.txt");
|
|
752
|
+
|
|
753
|
+
// Create
|
|
754
|
+
await using archive = new ZipArchive();
|
|
755
|
+
archive.write("file.txt", textBytes);
|
|
756
|
+
const zipBytes = await archive.compress();
|
|
757
|
+
```
|