@simplysm/core-common 13.0.0-beta.4 → 13.0.0-beta.41
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 +191 -815
- package/dist/common.types.js +4 -4
- package/dist/env.js +2 -2
- package/dist/env.js.map +2 -2
- package/dist/errors/argument-error.js +1 -1
- package/dist/errors/not-implemented-error.js +1 -1
- package/dist/errors/timeout-error.js +1 -1
- package/dist/extensions/arr-ext.helpers.js +4 -4
- package/dist/extensions/arr-ext.js +9 -9
- package/dist/features/debounce-queue.d.ts.map +1 -1
- package/dist/features/debounce-queue.js +4 -4
- package/dist/features/debounce-queue.js.map +2 -2
- package/dist/features/serial-queue.d.ts.map +1 -1
- package/dist/features/serial-queue.js +5 -5
- package/dist/features/serial-queue.js.map +2 -2
- package/dist/index.js +30 -30
- package/dist/types/date-only.js +2 -2
- package/dist/types/date-time.js +2 -2
- package/dist/types/lazy-gc-map.d.ts.map +1 -1
- package/dist/types/lazy-gc-map.js +2 -2
- package/dist/types/lazy-gc-map.js.map +2 -2
- package/dist/types/time.js +2 -2
- package/dist/types/uuid.js +1 -1
- package/dist/utils/bytes.js +1 -1
- package/dist/utils/json.js +8 -8
- package/dist/utils/obj.js +5 -5
- package/dist/utils/primitive.js +5 -5
- package/dist/utils/transferable.js +4 -4
- package/dist/utils/wait.js +1 -1
- package/docs/extensions.md +381 -0
- package/docs/features.md +94 -0
- package/docs/types.md +338 -0
- package/docs/utils.md +631 -0
- package/package.json +8 -4
- package/.cache/typecheck-browser.tsbuildinfo +0 -1
- package/.cache/typecheck-node.tsbuildinfo +0 -1
- package/.cache/typecheck-tests-browser.tsbuildinfo +0 -1
- package/.cache/typecheck-tests-node.tsbuildinfo +0 -1
- package/src/common.types.ts +0 -91
- package/src/env.ts +0 -11
- package/src/errors/argument-error.ts +0 -40
- package/src/errors/not-implemented-error.ts +0 -32
- package/src/errors/sd-error.ts +0 -53
- package/src/errors/timeout-error.ts +0 -36
- package/src/extensions/arr-ext.helpers.ts +0 -53
- package/src/extensions/arr-ext.ts +0 -777
- package/src/extensions/arr-ext.types.ts +0 -258
- package/src/extensions/map-ext.ts +0 -86
- package/src/extensions/set-ext.ts +0 -68
- package/src/features/debounce-queue.ts +0 -116
- package/src/features/event-emitter.ts +0 -112
- package/src/features/serial-queue.ts +0 -94
- package/src/globals.ts +0 -12
- package/src/index.ts +0 -55
- package/src/types/date-only.ts +0 -329
- package/src/types/date-time.ts +0 -294
- package/src/types/lazy-gc-map.ts +0 -244
- package/src/types/time.ts +0 -210
- package/src/types/uuid.ts +0 -113
- package/src/utils/bytes.ts +0 -160
- package/src/utils/date-format.ts +0 -239
- package/src/utils/json.ts +0 -230
- package/src/utils/num.ts +0 -97
- package/src/utils/obj.ts +0 -956
- package/src/utils/path.ts +0 -40
- package/src/utils/primitive.ts +0 -33
- package/src/utils/str.ts +0 -252
- package/src/utils/template-strings.ts +0 -132
- package/src/utils/transferable.ts +0 -269
- package/src/utils/wait.ts +0 -40
- package/src/utils/xml.ts +0 -105
- package/src/zip/sd-zip.ts +0 -218
- package/tests/errors/errors.spec.ts +0 -196
- package/tests/extensions/array-extension.spec.ts +0 -790
- package/tests/extensions/map-extension.spec.ts +0 -147
- package/tests/extensions/set-extension.spec.ts +0 -74
- package/tests/types/date-only.spec.ts +0 -636
- package/tests/types/date-time.spec.ts +0 -391
- package/tests/types/lazy-gc-map.spec.ts +0 -692
- package/tests/types/time.spec.ts +0 -559
- package/tests/types/types.spec.ts +0 -55
- package/tests/types/uuid.spec.ts +0 -91
- package/tests/utils/bytes-utils.spec.ts +0 -230
- package/tests/utils/date-format.spec.ts +0 -371
- package/tests/utils/debounce-queue.spec.ts +0 -272
- package/tests/utils/json.spec.ts +0 -475
- package/tests/utils/number.spec.ts +0 -184
- package/tests/utils/object.spec.ts +0 -827
- package/tests/utils/path.spec.ts +0 -78
- package/tests/utils/primitive.spec.ts +0 -55
- package/tests/utils/sd-event-emitter.spec.ts +0 -216
- package/tests/utils/serial-queue.spec.ts +0 -365
- package/tests/utils/string.spec.ts +0 -294
- package/tests/utils/template-strings.spec.ts +0 -96
- package/tests/utils/transferable.spec.ts +0 -698
- package/tests/utils/wait.spec.ts +0 -145
- package/tests/utils/xml.spec.ts +0 -146
- package/tests/zip/sd-zip.spec.ts +0 -234
package/docs/utils.md
ADDED
|
@@ -0,0 +1,631 @@
|
|
|
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
|
+
```
|
|
26
|
+
|
|
27
|
+
### objMerge
|
|
28
|
+
|
|
29
|
+
Deep merge (source + target, array processing option).
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { objMerge } from "@simplysm/core-common";
|
|
33
|
+
|
|
34
|
+
objMerge({ a: 1, b: { c: 2 } }, { b: { d: 3 } });
|
|
35
|
+
// { a: 1, b: { c: 2, d: 3 } }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### objMerge3
|
|
39
|
+
|
|
40
|
+
3-way merge with conflict detection.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { objMerge3 } from "@simplysm/core-common";
|
|
44
|
+
|
|
45
|
+
const { conflict, result } = objMerge3(
|
|
46
|
+
{ a: 1, b: 2 }, // source (change #1)
|
|
47
|
+
{ a: 1, b: 1 }, // origin (base)
|
|
48
|
+
{ a: 2, b: 1 }, // target (change #2)
|
|
49
|
+
);
|
|
50
|
+
// conflict: false, result: { a: 2, b: 2 }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### objOmit
|
|
54
|
+
|
|
55
|
+
Exclude specific keys.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { objOmit } from "@simplysm/core-common";
|
|
59
|
+
|
|
60
|
+
objOmit(user, ["password", "email"]);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### objPick
|
|
64
|
+
|
|
65
|
+
Select specific keys.
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { objPick } from "@simplysm/core-common";
|
|
69
|
+
|
|
70
|
+
objPick(user, ["name", "age"]);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### objGetChainValue
|
|
74
|
+
|
|
75
|
+
Query value by chain path (`"a.b[0].c"`).
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { objGetChainValue } from "@simplysm/core-common";
|
|
79
|
+
|
|
80
|
+
objGetChainValue(obj, "a.b[0].c");
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### objSetChainValue
|
|
84
|
+
|
|
85
|
+
Set value by chain path.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { objSetChainValue } from "@simplysm/core-common";
|
|
89
|
+
|
|
90
|
+
objSetChainValue(obj, "a.b[0].c", "value");
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### objDeleteChainValue
|
|
94
|
+
|
|
95
|
+
Delete value by chain path.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { objDeleteChainValue } from "@simplysm/core-common";
|
|
99
|
+
|
|
100
|
+
objDeleteChainValue(obj, "a.b[0].c");
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### objKeys
|
|
104
|
+
|
|
105
|
+
Type-safe `Object.keys`.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { objKeys } from "@simplysm/core-common";
|
|
109
|
+
|
|
110
|
+
objKeys(obj); // (keyof typeof obj)[]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### objEntries
|
|
114
|
+
|
|
115
|
+
Type-safe `Object.entries`.
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { objEntries } from "@simplysm/core-common";
|
|
119
|
+
|
|
120
|
+
objEntries(obj); // [keyof typeof obj, typeof obj[keyof typeof obj]][]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### objFromEntries
|
|
124
|
+
|
|
125
|
+
Type-safe `Object.fromEntries`.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { objFromEntries } from "@simplysm/core-common";
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### objMap
|
|
132
|
+
|
|
133
|
+
Transform each entry of object and return new object.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { objMap } from "@simplysm/core-common";
|
|
137
|
+
|
|
138
|
+
objMap(colors, (key, rgb) => [null, `rgb(${rgb})`]); // Transform values only (keep keys)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## JSON utilities (json)
|
|
144
|
+
|
|
145
|
+
Serializes/restores `DateTime`, `DateOnly`, `Time`, `Uuid`, `Date`, `Set`, `Map`, `Error`, `Uint8Array` types using `__type__` metadata.
|
|
146
|
+
|
|
147
|
+
### jsonStringify
|
|
148
|
+
|
|
149
|
+
JSON serialization with custom type support.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { jsonStringify, DateTime, Uuid } from "@simplysm/core-common";
|
|
153
|
+
|
|
154
|
+
const data = {
|
|
155
|
+
createdAt: new DateTime(2025, 1, 15),
|
|
156
|
+
id: Uuid.new(),
|
|
157
|
+
tags: new Set(["a", "b"]),
|
|
158
|
+
meta: new Map([["key", "value"]]),
|
|
159
|
+
file: new Uint8Array([1, 2, 3]),
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// Serialization (preserves custom types)
|
|
163
|
+
const json = jsonStringify(data, { space: 2 });
|
|
164
|
+
|
|
165
|
+
// For logging: hide binary data
|
|
166
|
+
jsonStringify(data, { redactBytes: true });
|
|
167
|
+
// Uint8Array content replaced with "__hidden__"
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### jsonParse
|
|
171
|
+
|
|
172
|
+
JSON deserialization with custom type restoration.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { jsonParse } from "@simplysm/core-common";
|
|
176
|
+
|
|
177
|
+
// Deserialization (restores custom types)
|
|
178
|
+
const parsed = jsonParse(json);
|
|
179
|
+
// parsed.createdAt instanceof DateTime === true
|
|
180
|
+
// parsed.id instanceof Uuid === true
|
|
181
|
+
// parsed.tags instanceof Set === true
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## XML utilities (xml)
|
|
187
|
+
|
|
188
|
+
### xmlParse
|
|
189
|
+
|
|
190
|
+
Parse XML string to object (attributes: `$`, text: `_`).
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import { xmlParse } from "@simplysm/core-common";
|
|
194
|
+
|
|
195
|
+
const obj = xmlParse('<root id="1"><item>hello</item></root>');
|
|
196
|
+
// { root: { $: { id: "1" }, item: [{ _: "hello" }] } }
|
|
197
|
+
|
|
198
|
+
// Remove namespace prefix
|
|
199
|
+
xmlParse('<ns:root><ns:item>text</ns:item></ns:root>', { stripTagPrefix: true });
|
|
200
|
+
// { root: { item: [{ _: "text" }] } }
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### xmlStringify
|
|
204
|
+
|
|
205
|
+
Serialize object to XML string.
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import { xmlStringify } from "@simplysm/core-common";
|
|
209
|
+
|
|
210
|
+
const xml = xmlStringify(obj);
|
|
211
|
+
// '<root id="1"><item>hello</item></root>'
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## String utilities (str)
|
|
217
|
+
|
|
218
|
+
### strGetSuffix
|
|
219
|
+
|
|
220
|
+
Korean postposition handling (을/를, 은/는, 이/가, 과/와, 이랑/랑, 으로/로, 이라/라).
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { strGetSuffix } from "@simplysm/core-common";
|
|
224
|
+
|
|
225
|
+
strGetSuffix("사과", "을"); // "를"
|
|
226
|
+
strGetSuffix("책", "이"); // "이"
|
|
227
|
+
strGetSuffix("서울", "로"); // "로" (ㄹ final consonant uses "로")
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### strReplaceFullWidth
|
|
231
|
+
|
|
232
|
+
Convert full-width characters to half-width.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { strReplaceFullWidth } from "@simplysm/core-common";
|
|
236
|
+
|
|
237
|
+
strReplaceFullWidth("A123(株)"); // "A123(株)"
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### strToPascalCase
|
|
241
|
+
|
|
242
|
+
PascalCase conversion.
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import { strToPascalCase } from "@simplysm/core-common";
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### strToCamelCase
|
|
249
|
+
|
|
250
|
+
camelCase conversion.
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import { strToCamelCase } from "@simplysm/core-common";
|
|
254
|
+
|
|
255
|
+
strToCamelCase("hello-world"); // "helloWorld"
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### strToKebabCase
|
|
259
|
+
|
|
260
|
+
kebab-case conversion.
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { strToKebabCase } from "@simplysm/core-common";
|
|
264
|
+
|
|
265
|
+
strToKebabCase("HelloWorld"); // "hello-world"
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### strToSnakeCase
|
|
269
|
+
|
|
270
|
+
snake_case conversion.
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import { strToSnakeCase } from "@simplysm/core-common";
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### strIsNullOrEmpty
|
|
277
|
+
|
|
278
|
+
Check for undefined/null/empty string (type guard).
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { strIsNullOrEmpty } from "@simplysm/core-common";
|
|
282
|
+
|
|
283
|
+
if (strIsNullOrEmpty(name)) {
|
|
284
|
+
// name: "" | undefined
|
|
285
|
+
} else {
|
|
286
|
+
// name: string (non-empty string)
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### strInsert
|
|
291
|
+
|
|
292
|
+
Insert at specific position in string.
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import { strInsert } from "@simplysm/core-common";
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Number utilities (num)
|
|
301
|
+
|
|
302
|
+
### numParseInt
|
|
303
|
+
|
|
304
|
+
Parse string to integer (remove non-digit characters).
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import { numParseInt } from "@simplysm/core-common";
|
|
308
|
+
|
|
309
|
+
numParseInt("12,345원"); // 12345
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### numParseFloat
|
|
313
|
+
|
|
314
|
+
Parse string to float.
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
import { numParseFloat } from "@simplysm/core-common";
|
|
318
|
+
|
|
319
|
+
numParseFloat("3.14%"); // 3.14
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### numParseRoundedInt
|
|
323
|
+
|
|
324
|
+
Round float and return integer.
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
import { numParseRoundedInt } from "@simplysm/core-common";
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### numFormat
|
|
331
|
+
|
|
332
|
+
Thousands separator formatting.
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import { numFormat } from "@simplysm/core-common";
|
|
336
|
+
|
|
337
|
+
numFormat(1234567, { max: 2 }); // "1,234,567"
|
|
338
|
+
numFormat(1234, { min: 2, max: 2 }); // "1,234.00"
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### numIsNullOrEmpty
|
|
342
|
+
|
|
343
|
+
Check for undefined/null/0 (type guard).
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
import { numIsNullOrEmpty } from "@simplysm/core-common";
|
|
347
|
+
|
|
348
|
+
if (numIsNullOrEmpty(count)) {
|
|
349
|
+
// count: 0 | undefined
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## Date/time formatting (date-format)
|
|
356
|
+
|
|
357
|
+
### formatDate
|
|
358
|
+
|
|
359
|
+
Convert date/time to string according to format string. Supports the same format strings as C#.
|
|
360
|
+
|
|
361
|
+
| Format | Description | Example |
|
|
362
|
+
|------|------|------|
|
|
363
|
+
| `yyyy` | 4-digit year | 2024 |
|
|
364
|
+
| `yy` | 2-digit year | 24 |
|
|
365
|
+
| `MM` | 0-padded month | 01~12 |
|
|
366
|
+
| `M` | Month | 1~12 |
|
|
367
|
+
| `ddd` | Day of week (Korean) | 일, 월, 화, 수, 목, 금, 토 |
|
|
368
|
+
| `dd` | 0-padded day | 01~31 |
|
|
369
|
+
| `d` | Day | 1~31 |
|
|
370
|
+
| `tt` | AM/PM | 오전, 오후 |
|
|
371
|
+
| `HH` | 0-padded 24-hour | 00~23 |
|
|
372
|
+
| `hh` | 0-padded 12-hour | 01~12 |
|
|
373
|
+
| `mm` | 0-padded minute | 00~59 |
|
|
374
|
+
| `ss` | 0-padded second | 00~59 |
|
|
375
|
+
| `fff` | Millisecond (3 digits) | 000~999 |
|
|
376
|
+
| `zzz` | Timezone offset | +09:00 |
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
import { formatDate } from "@simplysm/core-common";
|
|
380
|
+
|
|
381
|
+
formatDate("yyyy-MM-dd", { year: 2024, month: 3, day: 15 });
|
|
382
|
+
// "2024-03-15"
|
|
383
|
+
|
|
384
|
+
formatDate("yyyy년 M월 d일 (ddd)", { year: 2024, month: 3, day: 15 });
|
|
385
|
+
// "2024년 3월 15일 (금)"
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### normalizeMonth
|
|
389
|
+
|
|
390
|
+
Normalize year/month/day when setting month.
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
import { normalizeMonth } from "@simplysm/core-common";
|
|
394
|
+
|
|
395
|
+
normalizeMonth(2025, 13, 15); // { year: 2026, month: 1, day: 15 }
|
|
396
|
+
normalizeMonth(2025, 2, 31); // { year: 2025, month: 2, day: 28 }
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
## Byte utilities (bytes)
|
|
402
|
+
|
|
403
|
+
### bytesConcat
|
|
404
|
+
|
|
405
|
+
Concatenate multiple Uint8Arrays.
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
import { bytesConcat } from "@simplysm/core-common";
|
|
409
|
+
|
|
410
|
+
bytesConcat([new Uint8Array([1, 2]), new Uint8Array([3, 4])]);
|
|
411
|
+
// Uint8Array([1, 2, 3, 4])
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### bytesToHex
|
|
415
|
+
|
|
416
|
+
Convert Uint8Array to hex string.
|
|
417
|
+
|
|
418
|
+
```typescript
|
|
419
|
+
import { bytesToHex } from "@simplysm/core-common";
|
|
420
|
+
|
|
421
|
+
bytesToHex(new Uint8Array([255, 0, 127])); // "ff007f"
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
### bytesFromHex
|
|
425
|
+
|
|
426
|
+
Convert hex string to Uint8Array.
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
import { bytesFromHex } from "@simplysm/core-common";
|
|
430
|
+
|
|
431
|
+
bytesFromHex("ff007f"); // Uint8Array([255, 0, 127])
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### bytesToBase64
|
|
435
|
+
|
|
436
|
+
Convert Uint8Array to base64 string.
|
|
437
|
+
|
|
438
|
+
```typescript
|
|
439
|
+
import { bytesToBase64 } from "@simplysm/core-common";
|
|
440
|
+
|
|
441
|
+
bytesToBase64(new Uint8Array([72, 101, 108, 108, 111])); // "SGVsbG8="
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### bytesFromBase64
|
|
445
|
+
|
|
446
|
+
Convert base64 string to Uint8Array.
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
import { bytesFromBase64 } from "@simplysm/core-common";
|
|
450
|
+
|
|
451
|
+
bytesFromBase64("SGVsbG8="); // Uint8Array([72, 101, 108, 108, 111])
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
---
|
|
455
|
+
|
|
456
|
+
## Async wait (wait)
|
|
457
|
+
|
|
458
|
+
### waitTime
|
|
459
|
+
|
|
460
|
+
Wait for specified time.
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
import { waitTime } from "@simplysm/core-common";
|
|
464
|
+
|
|
465
|
+
await waitTime(1000); // Wait 1 second
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
### waitUntil
|
|
469
|
+
|
|
470
|
+
Wait until condition is true (max attempts limit).
|
|
471
|
+
|
|
472
|
+
```typescript
|
|
473
|
+
import { waitUntil } from "@simplysm/core-common";
|
|
474
|
+
|
|
475
|
+
// Wait for condition (100ms interval, max 50 attempts = 5 seconds)
|
|
476
|
+
await waitUntil(() => isReady, 100, 50);
|
|
477
|
+
// Throws TimeoutError after 50 attempts
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
482
|
+
## Worker data conversion (transferable)
|
|
483
|
+
|
|
484
|
+
### transferableEncode
|
|
485
|
+
|
|
486
|
+
Serialize custom types into Worker-transferable form.
|
|
487
|
+
|
|
488
|
+
```typescript
|
|
489
|
+
import { transferableEncode } from "@simplysm/core-common";
|
|
490
|
+
|
|
491
|
+
// Send to Worker
|
|
492
|
+
const { result, transferList } = transferableEncode(data);
|
|
493
|
+
worker.postMessage(result, transferList);
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
### transferableDecode
|
|
497
|
+
|
|
498
|
+
Deserialize Worker-received data to custom types.
|
|
499
|
+
|
|
500
|
+
```typescript
|
|
501
|
+
import { transferableDecode } from "@simplysm/core-common";
|
|
502
|
+
|
|
503
|
+
// Receive from Worker
|
|
504
|
+
const decoded = transferableDecode(event.data);
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
---
|
|
508
|
+
|
|
509
|
+
## Path utilities (path)
|
|
510
|
+
|
|
511
|
+
Replacement for Node.js `path` module. Supports POSIX-style paths (`/`) only.
|
|
512
|
+
|
|
513
|
+
### pathJoin
|
|
514
|
+
|
|
515
|
+
Combine paths (`path.join` replacement).
|
|
516
|
+
|
|
517
|
+
```typescript
|
|
518
|
+
import { pathJoin } from "@simplysm/core-common";
|
|
519
|
+
|
|
520
|
+
pathJoin("/home", "user", "file.txt"); // "/home/user/file.txt"
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### pathBasename
|
|
524
|
+
|
|
525
|
+
Extract filename (`path.basename` replacement).
|
|
526
|
+
|
|
527
|
+
```typescript
|
|
528
|
+
import { pathBasename } from "@simplysm/core-common";
|
|
529
|
+
|
|
530
|
+
pathBasename("/home/user/file.txt"); // "file.txt"
|
|
531
|
+
pathBasename("file.txt", ".txt"); // "file"
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
### pathExtname
|
|
535
|
+
|
|
536
|
+
Extract extension (`path.extname` replacement).
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
import { pathExtname } from "@simplysm/core-common";
|
|
540
|
+
|
|
541
|
+
pathExtname("file.txt"); // ".txt"
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
---
|
|
545
|
+
|
|
546
|
+
## Template literal tags (template-strings)
|
|
547
|
+
|
|
548
|
+
Tag functions for IDE code highlighting. Actual behavior is string combination + indentation cleanup.
|
|
549
|
+
|
|
550
|
+
### js
|
|
551
|
+
|
|
552
|
+
JavaScript code highlighting.
|
|
553
|
+
|
|
554
|
+
```typescript
|
|
555
|
+
import { js } from "@simplysm/core-common";
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
### ts
|
|
559
|
+
|
|
560
|
+
TypeScript code highlighting.
|
|
561
|
+
|
|
562
|
+
```typescript
|
|
563
|
+
import { ts } from "@simplysm/core-common";
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
### html
|
|
567
|
+
|
|
568
|
+
HTML markup highlighting.
|
|
569
|
+
|
|
570
|
+
```typescript
|
|
571
|
+
import { html } from "@simplysm/core-common";
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
### tsql
|
|
575
|
+
|
|
576
|
+
MSSQL T-SQL highlighting.
|
|
577
|
+
|
|
578
|
+
```typescript
|
|
579
|
+
import { tsql } from "@simplysm/core-common";
|
|
580
|
+
|
|
581
|
+
const query = tsql`
|
|
582
|
+
SELECT TOP 10 *
|
|
583
|
+
FROM Users
|
|
584
|
+
WHERE Name LIKE '%${keyword}%'
|
|
585
|
+
`;
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### mysql
|
|
589
|
+
|
|
590
|
+
MySQL SQL highlighting.
|
|
591
|
+
|
|
592
|
+
```typescript
|
|
593
|
+
import { mysql } from "@simplysm/core-common";
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
### pgsql
|
|
597
|
+
|
|
598
|
+
PostgreSQL SQL highlighting.
|
|
599
|
+
|
|
600
|
+
```typescript
|
|
601
|
+
import { pgsql } from "@simplysm/core-common";
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
---
|
|
605
|
+
|
|
606
|
+
## Other utilities
|
|
607
|
+
|
|
608
|
+
### getPrimitiveTypeStr
|
|
609
|
+
|
|
610
|
+
Infer `PrimitiveTypeStr` from runtime value.
|
|
611
|
+
|
|
612
|
+
```typescript
|
|
613
|
+
import { getPrimitiveTypeStr } from "@simplysm/core-common";
|
|
614
|
+
|
|
615
|
+
getPrimitiveTypeStr("hello"); // "string"
|
|
616
|
+
getPrimitiveTypeStr(123); // "number"
|
|
617
|
+
getPrimitiveTypeStr(new DateTime()); // "DateTime"
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
### env
|
|
621
|
+
|
|
622
|
+
Environment variable object (`DEV`, `VER`, etc.).
|
|
623
|
+
|
|
624
|
+
```typescript
|
|
625
|
+
import { env } from "@simplysm/core-common";
|
|
626
|
+
|
|
627
|
+
if (env.DEV) {
|
|
628
|
+
console.log("Development mode");
|
|
629
|
+
}
|
|
630
|
+
console.log(`Version: ${env.VER}`);
|
|
631
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/core-common",
|
|
3
|
-
"version": "13.0.0-beta.
|
|
3
|
+
"version": "13.0.0-beta.41",
|
|
4
4
|
"description": "심플리즘 패키지 - 코어 모듈 (common)",
|
|
5
5
|
"author": "김석래",
|
|
6
6
|
"repository": {
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "./dist/index.js",
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"docs"
|
|
18
|
+
],
|
|
15
19
|
"sideEffects": [
|
|
16
20
|
"./src/extensions/arr-ext.ts",
|
|
17
21
|
"./src/extensions/map-ext.ts",
|
|
@@ -23,9 +27,9 @@
|
|
|
23
27
|
"./dist/index.js"
|
|
24
28
|
],
|
|
25
29
|
"dependencies": {
|
|
26
|
-
"@zip.js/zip.js": "^2.8.
|
|
30
|
+
"@zip.js/zip.js": "^2.8.20",
|
|
27
31
|
"consola": "^3.4.2",
|
|
28
|
-
"fast-xml-parser": "^5.3.
|
|
32
|
+
"fast-xml-parser": "^5.3.5",
|
|
29
33
|
"yaml": "^2.8.2"
|
|
30
34
|
}
|
|
31
|
-
}
|
|
35
|
+
}
|