@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.
- package/README.md +66 -267
- package/dist/common.types.d.ts +14 -14
- package/dist/errors/argument-error.d.ts +10 -10
- package/dist/errors/argument-error.d.ts.map +1 -1
- package/dist/errors/argument-error.js +2 -2
- package/dist/errors/argument-error.js.map +1 -1
- package/dist/errors/not-implemented-error.d.ts +8 -8
- package/dist/errors/not-implemented-error.js +2 -2
- package/dist/errors/not-implemented-error.js.map +1 -1
- package/dist/errors/sd-error.d.ts +10 -10
- package/dist/errors/sd-error.d.ts.map +1 -1
- package/dist/errors/timeout-error.d.ts +10 -10
- package/dist/errors/timeout-error.js +3 -3
- package/dist/errors/timeout-error.js.map +1 -1
- package/dist/extensions/arr-ext.d.ts +2 -2
- package/dist/extensions/arr-ext.helpers.d.ts +8 -8
- package/dist/extensions/arr-ext.helpers.js +1 -1
- package/dist/extensions/arr-ext.helpers.js.map +1 -1
- package/dist/extensions/arr-ext.js +13 -13
- package/dist/extensions/arr-ext.js.map +1 -1
- package/dist/extensions/arr-ext.types.d.ts +57 -57
- package/dist/extensions/arr-ext.types.d.ts.map +1 -1
- package/dist/extensions/map-ext.d.ts +16 -16
- package/dist/extensions/set-ext.d.ts +11 -11
- package/dist/features/debounce-queue.d.ts +17 -15
- package/dist/features/debounce-queue.d.ts.map +1 -1
- package/dist/features/debounce-queue.js +6 -6
- package/dist/features/debounce-queue.js.map +1 -1
- package/dist/features/event-emitter.d.ts +20 -20
- package/dist/features/event-emitter.js +17 -17
- package/dist/features/serial-queue.d.ts +11 -11
- package/dist/features/serial-queue.js +5 -5
- package/dist/features/serial-queue.js.map +1 -1
- package/dist/globals.d.ts +4 -4
- package/dist/types/date-only.d.ts +64 -64
- package/dist/types/date-only.d.ts.map +1 -1
- package/dist/types/date-only.js +63 -63
- package/dist/types/date-time.d.ts +37 -37
- package/dist/types/date-time.d.ts.map +1 -1
- package/dist/types/date-time.js +54 -37
- package/dist/types/date-time.js.map +1 -1
- package/dist/types/lazy-gc-map.d.ts +26 -26
- package/dist/types/lazy-gc-map.d.ts.map +1 -1
- package/dist/types/lazy-gc-map.js +26 -26
- package/dist/types/lazy-gc-map.js.map +1 -1
- package/dist/types/time.d.ts +25 -25
- package/dist/types/time.d.ts.map +1 -1
- package/dist/types/time.js +25 -25
- package/dist/types/time.js.map +1 -1
- package/dist/types/uuid.d.ts +11 -11
- package/dist/types/uuid.d.ts.map +1 -1
- package/dist/types/uuid.js +12 -12
- package/dist/types/uuid.js.map +1 -1
- package/dist/utils/bytes.d.ts +17 -17
- package/dist/utils/bytes.js +4 -4
- package/dist/utils/bytes.js.map +1 -1
- package/dist/utils/date-format.d.ts +45 -45
- package/dist/utils/date-format.js +1 -1
- package/dist/utils/date-format.js.map +1 -1
- package/dist/utils/error.d.ts +4 -4
- package/dist/utils/json.d.ts +17 -17
- package/dist/utils/json.js +3 -3
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/num.d.ts +23 -23
- package/dist/utils/obj.d.ts +111 -111
- package/dist/utils/obj.d.ts.map +1 -1
- package/dist/utils/obj.js +3 -3
- package/dist/utils/obj.js.map +1 -1
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/primitive.d.ts +5 -5
- package/dist/utils/primitive.js +1 -1
- package/dist/utils/primitive.js.map +1 -1
- package/dist/utils/str.d.ts +46 -46
- package/dist/utils/str.d.ts.map +1 -1
- package/dist/utils/str.js +5 -5
- package/dist/utils/str.js.map +1 -1
- package/dist/utils/template-strings.d.ts +26 -26
- package/dist/utils/transferable.d.ts +18 -18
- package/dist/utils/transferable.js +1 -1
- package/dist/utils/transferable.js.map +1 -1
- package/dist/utils/wait.d.ts +9 -9
- package/dist/utils/xml.d.ts +13 -13
- package/dist/utils/xml.d.ts.map +1 -1
- package/dist/utils/xml.js +1 -0
- package/dist/utils/xml.js.map +1 -1
- package/dist/zip/sd-zip.d.ts +22 -22
- package/dist/zip/sd-zip.js +16 -16
- package/package.json +4 -4
- package/src/common.types.ts +17 -17
- package/src/errors/argument-error.ts +15 -15
- package/src/errors/not-implemented-error.ts +9 -9
- package/src/errors/sd-error.ts +12 -12
- package/src/errors/timeout-error.ts +12 -12
- package/src/extensions/arr-ext.helpers.ts +10 -10
- package/src/extensions/arr-ext.ts +57 -57
- package/src/extensions/arr-ext.types.ts +59 -59
- package/src/extensions/map-ext.ts +16 -16
- package/src/extensions/set-ext.ts +11 -11
- package/src/features/debounce-queue.ts +21 -19
- package/src/features/event-emitter.ts +25 -25
- package/src/features/serial-queue.ts +13 -13
- package/src/globals.ts +4 -4
- package/src/index.ts +1 -1
- package/src/types/date-only.ts +83 -83
- package/src/types/date-time.ts +64 -44
- package/src/types/lazy-gc-map.ts +45 -45
- package/src/types/time.ts +34 -34
- package/src/types/uuid.ts +17 -17
- package/src/utils/bytes.ts +35 -35
- package/src/utils/date-format.ts +65 -65
- package/src/utils/error.ts +4 -4
- package/src/utils/json.ts +39 -39
- package/src/utils/num.ts +23 -23
- package/src/utils/obj.ts +138 -138
- package/src/utils/path.ts +10 -10
- package/src/utils/primitive.ts +6 -6
- package/src/utils/str.ts +260 -261
- package/src/utils/template-strings.ts +29 -29
- package/src/utils/transferable.ts +284 -284
- package/src/utils/wait.ts +10 -10
- package/src/utils/xml.ts +20 -19
- package/src/zip/sd-zip.ts +25 -25
- package/tests/errors/errors.spec.ts +80 -0
- package/tests/extensions/array-extension.spec.ts +796 -0
- package/tests/extensions/map-extension.spec.ts +147 -0
- package/tests/extensions/set-extension.spec.ts +74 -0
- package/tests/types/date-only.spec.ts +638 -0
- package/tests/types/date-time.spec.ts +391 -0
- package/tests/types/lazy-gc-map.spec.ts +692 -0
- package/tests/types/time.spec.ts +559 -0
- package/tests/types/uuid.spec.ts +74 -0
- package/tests/utils/bytes-utils.spec.ts +230 -0
- package/tests/utils/date-format.spec.ts +373 -0
- package/tests/utils/debounce-queue.spec.ts +272 -0
- package/tests/utils/json.spec.ts +486 -0
- package/tests/utils/number.spec.ts +157 -0
- package/tests/utils/object.spec.ts +829 -0
- package/tests/utils/path.spec.ts +78 -0
- package/tests/utils/primitive.spec.ts +43 -0
- package/tests/utils/sd-event-emitter.spec.ts +216 -0
- package/tests/utils/serial-queue.spec.ts +365 -0
- package/tests/utils/string.spec.ts +281 -0
- package/tests/utils/template-strings.spec.ts +57 -0
- package/tests/utils/transferable.spec.ts +703 -0
- package/tests/utils/wait.spec.ts +145 -0
- package/tests/utils/xml.spec.ts +146 -0
- package/tests/zip/sd-zip.spec.ts +238 -0
- package/docs/extensions.md +0 -503
- package/docs/features.md +0 -109
- package/docs/types.md +0 -486
- package/docs/utils.md +0 -780
package/README.md
CHANGED
|
@@ -1,277 +1,76 @@
|
|
|
1
1
|
# @simplysm/core-common
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Simplysm package - Core module (common)
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
```bash
|
|
8
|
-
npm install @simplysm/core-common
|
|
9
|
-
# or
|
|
10
7
|
pnpm add @simplysm/core-common
|
|
11
|
-
```
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
###
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
###
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
### XML Utilities
|
|
79
|
-
|
|
80
|
-
- [`xmlParse`](docs/utils.md#xmlparse) - Parse XML string to object
|
|
81
|
-
- [`xmlStringify`](docs/utils.md#xmlstringify) - Serialize object to XML string
|
|
82
|
-
|
|
83
|
-
### String Utilities
|
|
84
|
-
|
|
85
|
-
- [`strGetSuffix`](docs/utils.md#strgetsuffix) - Korean postposition handling
|
|
86
|
-
- [`strReplaceFullWidth`](docs/utils.md#strreplacefullwidth) - Convert full-width to half-width
|
|
87
|
-
- [`strToPascalCase`](docs/utils.md#strtopascalcase) - PascalCase conversion
|
|
88
|
-
- [`strToCamelCase`](docs/utils.md#strtocamelcase) - camelCase conversion
|
|
89
|
-
- [`strToKebabCase`](docs/utils.md#strtokebabcase) - kebab-case conversion
|
|
90
|
-
- [`strToSnakeCase`](docs/utils.md#strtosnakecase) - snake_case conversion
|
|
91
|
-
- [`strIsNullOrEmpty`](docs/utils.md#strisnullorempty) - Check for undefined/null/empty (type guard)
|
|
92
|
-
- [`strInsert`](docs/utils.md#strinsert) - Insert at position in string
|
|
93
|
-
|
|
94
|
-
### Number Utilities
|
|
95
|
-
|
|
96
|
-
- [`numParseInt`](docs/utils.md#numparseint) - Parse string to integer
|
|
97
|
-
- [`numParseFloat`](docs/utils.md#numparsefloat) - Parse string to float
|
|
98
|
-
- [`numParseRoundedInt`](docs/utils.md#numparseroundedint) - Round float and return integer
|
|
99
|
-
- [`numFormat`](docs/utils.md#numformat) - Thousands separator formatting
|
|
100
|
-
- [`numIsNullOrEmpty`](docs/utils.md#numisnullorempty) - Check for undefined/null/0 (type guard)
|
|
101
|
-
|
|
102
|
-
### Date/Time Formatting
|
|
103
|
-
|
|
104
|
-
- [`formatDate`](docs/utils.md#formatdate) - Convert date/time to formatted string
|
|
105
|
-
- [`normalizeMonth`](docs/utils.md#normalizemonth) - Normalize year/month/day when setting month
|
|
106
|
-
- [`convert12To24`](docs/utils.md#convert12to24) - Convert 12-hour to 24-hour format
|
|
107
|
-
|
|
108
|
-
### Byte Utilities
|
|
109
|
-
|
|
110
|
-
- [`bytesConcat`](docs/utils.md#bytesconcat) - Concatenate multiple Uint8Arrays
|
|
111
|
-
- [`bytesToHex`](docs/utils.md#bytestohex) - Convert Uint8Array to hex string
|
|
112
|
-
- [`bytesFromHex`](docs/utils.md#bytesfromhex) - Convert hex string to Uint8Array
|
|
113
|
-
- [`bytesToBase64`](docs/utils.md#bytestobase64) - Convert Uint8Array to base64 string
|
|
114
|
-
- [`bytesFromBase64`](docs/utils.md#bytesfrombase64) - Convert base64 string to Uint8Array
|
|
115
|
-
|
|
116
|
-
### Async Wait
|
|
117
|
-
|
|
118
|
-
- [`waitTime`](docs/utils.md#waittime) - Wait for specified time
|
|
119
|
-
- [`waitUntil`](docs/utils.md#waituntil) - Wait until condition is true
|
|
120
|
-
|
|
121
|
-
### Worker Data Conversion
|
|
122
|
-
|
|
123
|
-
- [`transferableEncode`](docs/utils.md#transferableencode) - Serialize custom types for Worker transfer
|
|
124
|
-
- [`transferableDecode`](docs/utils.md#transferabledecode) - Deserialize Worker data to custom types
|
|
125
|
-
|
|
126
|
-
### Path Utilities
|
|
127
|
-
|
|
128
|
-
- [`pathJoin`](docs/utils.md#pathjoin) - Combine paths (POSIX-style only)
|
|
129
|
-
- [`pathBasename`](docs/utils.md#pathbasename) - Extract filename
|
|
130
|
-
- [`pathExtname`](docs/utils.md#pathextname) - Extract extension
|
|
131
|
-
|
|
132
|
-
### Template Literal Tags
|
|
133
|
-
|
|
134
|
-
- [`js`](docs/utils.md#js) - JavaScript code highlighting
|
|
135
|
-
- [`ts`](docs/utils.md#ts) - TypeScript code highlighting
|
|
136
|
-
- [`html`](docs/utils.md#html) - HTML markup highlighting
|
|
137
|
-
- [`tsql`](docs/utils.md#tsql) - MSSQL T-SQL highlighting
|
|
138
|
-
- [`mysql`](docs/utils.md#mysql) - MySQL SQL highlighting
|
|
139
|
-
- [`pgsql`](docs/utils.md#pgsql) - PostgreSQL SQL highlighting
|
|
140
|
-
|
|
141
|
-
### Other Utilities
|
|
142
|
-
|
|
143
|
-
- [`getPrimitiveTypeStr`](docs/utils.md#getprimitivetypestr) - Infer `PrimitiveTypeStr` from runtime value
|
|
144
|
-
- [`env`](docs/utils.md#env) - Environment variable object
|
|
145
|
-
|
|
146
|
-
### Array Extensions
|
|
147
|
-
|
|
148
|
-
#### Query
|
|
149
|
-
- [`single`](docs/extensions.md#single) - Return single element (error if 2+)
|
|
150
|
-
- [`first`](docs/extensions.md#first) - Return first element
|
|
151
|
-
- [`last`](docs/extensions.md#last) - Return last element
|
|
152
|
-
|
|
153
|
-
#### Filtering
|
|
154
|
-
- [`filterExists`](docs/extensions.md#filterexists) - Remove `null`/`undefined`
|
|
155
|
-
- [`ofType`](docs/extensions.md#oftype) - Filter by type
|
|
156
|
-
- [`filterAsync`](docs/extensions.md#filterasync) - Async filter
|
|
157
|
-
|
|
158
|
-
#### Mapping/Transformation
|
|
159
|
-
- [`mapAsync`](docs/extensions.md#mapasync) - Async mapping (sequential)
|
|
160
|
-
- [`mapMany`](docs/extensions.md#mapmany) - Flatten nested arrays and remove null/undefined
|
|
161
|
-
- [`mapManyAsync`](docs/extensions.md#mapmanyasync) - Async mapMany
|
|
162
|
-
- [`parallelAsync`](docs/extensions.md#parallelasync) - Parallel async mapping
|
|
163
|
-
|
|
164
|
-
#### Grouping
|
|
165
|
-
- [`groupBy`](docs/extensions.md#groupby) - Group by key
|
|
166
|
-
- [`toMap`](docs/extensions.md#tomap) - Convert to Map
|
|
167
|
-
- [`toMapAsync`](docs/extensions.md#tomapasync) - Async Map conversion
|
|
168
|
-
- [`toArrayMap`](docs/extensions.md#toarraymap) - Convert to `Map<K, V[]>`
|
|
169
|
-
- [`toSetMap`](docs/extensions.md#tosetmap) - Convert to `Map<K, Set<V>>`
|
|
170
|
-
- [`toMapValues`](docs/extensions.md#tomapvalues) - Aggregate Map by group
|
|
171
|
-
- [`toObject`](docs/extensions.md#toobject) - Convert to `Record<string, V>`
|
|
172
|
-
- [`toTree`](docs/extensions.md#totree) - Convert to tree structure
|
|
173
|
-
|
|
174
|
-
#### Deduplication
|
|
175
|
-
- [`distinct`](docs/extensions.md#distinct) - Remove duplicates (new array)
|
|
176
|
-
- [`distinctThis`](docs/extensions.md#distinctthis) - Remove duplicates (modify original)
|
|
177
|
-
|
|
178
|
-
#### Sorting
|
|
179
|
-
- [`orderBy`](docs/extensions.md#orderby) - Ascending sort (new array)
|
|
180
|
-
- [`orderByDesc`](docs/extensions.md#orderbydesc) - Descending sort (new array)
|
|
181
|
-
- [`orderByThis`](docs/extensions.md#orderbythis) - Ascending sort (modify original)
|
|
182
|
-
- [`orderByDescThis`](docs/extensions.md#orderbydescthis) - Descending sort (modify original)
|
|
183
|
-
|
|
184
|
-
#### Comparison/Merging
|
|
185
|
-
- [`diffs`](docs/extensions.md#diffs) - Compare differences between arrays
|
|
186
|
-
- [`oneWayDiffs`](docs/extensions.md#onewaydiffs) - One-way diff comparison
|
|
187
|
-
- [`merge`](docs/extensions.md#merge) - Merge arrays
|
|
188
|
-
|
|
189
|
-
#### Aggregation
|
|
190
|
-
- [`sum`](docs/extensions.md#sum) - Sum
|
|
191
|
-
- [`min`](docs/extensions.md#min) - Minimum
|
|
192
|
-
- [`max`](docs/extensions.md#max) - Maximum
|
|
193
|
-
|
|
194
|
-
#### Mutation
|
|
195
|
-
- [`insert`](docs/extensions.md#insert) - Insert at specific position
|
|
196
|
-
- [`remove`](docs/extensions.md#remove) - Remove item or items matching predicate
|
|
197
|
-
- [`toggle`](docs/extensions.md#toggle) - Toggle item
|
|
198
|
-
- [`clear`](docs/extensions.md#clear) - Remove all items
|
|
199
|
-
- [`shuffle`](docs/extensions.md#shuffle) - Shuffle array
|
|
200
|
-
|
|
201
|
-
### Map Extensions
|
|
202
|
-
|
|
203
|
-
- [`getOrCreate`](docs/extensions.md#getorcreate) - Get or create and return value
|
|
204
|
-
- [`update`](docs/extensions.md#update) - Update value using function
|
|
205
|
-
|
|
206
|
-
### Set Extensions
|
|
207
|
-
|
|
208
|
-
- [`adds`](docs/extensions.md#adds) - Add multiple values at once
|
|
209
|
-
- [`toggle`](docs/extensions.md#toggle-1) - Toggle value (add/remove/force)
|
|
210
|
-
|
|
211
|
-
## Types
|
|
212
|
-
|
|
213
|
-
- [`Bytes`](docs/types.md#bytes) - Alias for `Uint8Array`
|
|
214
|
-
- [`PrimitiveTypeStr`](docs/types.md#primitivetypestr) - Primitive type string keys
|
|
215
|
-
- [`PrimitiveTypeMap`](docs/types.md#primitivetypemap) - Mapping from type string to type
|
|
216
|
-
- [`PrimitiveType`](docs/types.md#primitivetype) - Union of all primitive types (includes `undefined`)
|
|
217
|
-
- [`DeepPartial`](docs/types.md#deeppartial) - Recursively convert properties to optional
|
|
218
|
-
- [`Type`](docs/types.md#type) - Constructor type
|
|
219
|
-
- [`ObjUndefToOptional`](docs/types.md#objundeftooptional) - Convert `undefined` properties to optional
|
|
220
|
-
- [`ObjOptionalToUndef`](docs/types.md#objoptionaltoundef) - Convert optional properties to `required + undefined`
|
|
221
|
-
- [`EqualOptions`](docs/types.md#equaloptions) - Options for `objEqual`
|
|
222
|
-
- [`ObjMergeOptions`](docs/types.md#objmergeoptions) - Options for `objMerge`
|
|
223
|
-
- [`ObjMerge3KeyOptions`](docs/types.md#objmerge3keyoptions) - Per-key options for `objMerge3`
|
|
224
|
-
- [`DtNormalizedMonth`](docs/types.md#dtnormalizedmonth) - Return type of `normalizeMonth`
|
|
225
|
-
- [`ZipArchiveProgress`](docs/types.md#ziparchiveprogress) - Progress info for `ZipArchive.extractAll`
|
|
226
|
-
- [`ArrayDiffsResult`](docs/types.md#arraydiffsresult) - Result type of `Array.diffs()`
|
|
227
|
-
- [`ArrayDiffs2Result`](docs/types.md#arraydiffs2result) - Result type of `Array.oneWayDiffs()`
|
|
228
|
-
- [`TreeArray`](docs/types.md#treearray) - Result type of `Array.toTree()`
|
|
229
|
-
- [`ComparableType`](docs/types.md#comparabletype) - Union of types usable for sorting/comparison
|
|
230
|
-
|
|
231
|
-
## Caveats
|
|
232
|
-
|
|
233
|
-
### Prototype Extension Conflicts
|
|
234
|
-
|
|
235
|
-
This package extends Array, Map, and Set prototypes.
|
|
236
|
-
Conflicts may occur when used with other libraries that extend the same method names.
|
|
237
|
-
In case of conflict, the last defined implementation is applied based on load order.
|
|
238
|
-
|
|
239
|
-
### Timezone Handling
|
|
240
|
-
|
|
241
|
-
When using `DateOnly.parse()`, `DateTime.parse()`:
|
|
242
|
-
- `yyyy-MM-dd`, `yyyyMMdd` format: parse directly from string (no timezone influence)
|
|
243
|
-
- ISO 8601 format (`2024-01-15T00:00:00Z`): interpret as UTC then convert to local
|
|
244
|
-
|
|
245
|
-
When server and client timezones differ, actively use `yyyy-MM-dd` format.
|
|
246
|
-
|
|
247
|
-
### Memory Management (LazyGcMap)
|
|
248
|
-
|
|
249
|
-
`LazyGcMap` has an internal GC timer, so it must be cleaned up.
|
|
250
|
-
|
|
251
|
-
```typescript
|
|
252
|
-
// using statement (recommended)
|
|
253
|
-
// gcInterval: GC execution interval (ms), expireTime: item expiration time (ms)
|
|
254
|
-
using map = new LazyGcMap({ gcInterval: 10000, expireTime: 60000 }); // GC every 10 seconds, expire after 60 seconds
|
|
255
|
-
|
|
256
|
-
// Or explicit dispose() call
|
|
257
|
-
const map = new LazyGcMap({ gcInterval: 10000, expireTime: 60000 }); // GC every 10 seconds, expire after 60 seconds
|
|
258
|
-
try {
|
|
259
|
-
// ... use
|
|
260
|
-
} finally {
|
|
261
|
-
map.dispose();
|
|
262
|
-
}
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
### jsonStringify's __type__ Reserved Word
|
|
266
|
-
|
|
267
|
-
`jsonStringify`/`jsonParse` uses objects with `__type__` and `data` keys for type restoration.
|
|
268
|
-
Be careful as user data in the form `{ __type__: "DateTime", data: "..." }` may be unintentionally type-converted.
|
|
269
|
-
|
|
270
|
-
### Circular References
|
|
271
|
-
|
|
272
|
-
- `objClone`: supports circular references (tracked with WeakMap)
|
|
273
|
-
- `jsonStringify`: throws TypeError on circular reference
|
|
274
|
-
- `transferableEncode`: throws TypeError on circular reference (includes path information)
|
|
9
|
+
## Source Index
|
|
10
|
+
|
|
11
|
+
### (top-level)
|
|
12
|
+
|
|
13
|
+
| Source | Exports | Description | Test |
|
|
14
|
+
|--------|---------|-------------|------|
|
|
15
|
+
| `src/env.ts` | `env` | Runtime environment configuration object | - |
|
|
16
|
+
| `src/extensions/arr-ext.ts` | `ArrayDiffsResult`, `ArrayDiffs2Result`, `TreeArray`, `ComparableType` | Array diff, tree, and comparison utilities via prototype augmentation | `array-extension.spec.ts` |
|
|
17
|
+
|
|
18
|
+
### errors
|
|
19
|
+
|
|
20
|
+
| Source | Exports | Description | Test |
|
|
21
|
+
|--------|---------|-------------|------|
|
|
22
|
+
| `src/errors/sd-error.ts` | `SdError` | Base error class with name-based error chain support | `errors.spec.ts` |
|
|
23
|
+
| `src/errors/argument-error.ts` | `ArgumentError` | Error thrown when a function receives an invalid argument | `errors.spec.ts` |
|
|
24
|
+
| `src/errors/not-implemented-error.ts` | `NotImplementedError` | Error indicating an unimplemented method or feature | `errors.spec.ts` |
|
|
25
|
+
| `src/errors/timeout-error.ts` | `TimeoutError` | Error thrown when an operation exceeds its time limit | `errors.spec.ts` |
|
|
26
|
+
|
|
27
|
+
### types
|
|
28
|
+
|
|
29
|
+
| Source | Exports | Description | Test |
|
|
30
|
+
|--------|---------|-------------|------|
|
|
31
|
+
| `src/types/uuid.ts` | `Uuid` | UUID v4 generation and validation utility class | `uuid.spec.ts` |
|
|
32
|
+
| `src/types/lazy-gc-map.ts` | `LazyGcMap` | Map with lazy initialization and automatic garbage collection of unused entries | `lazy-gc-map.spec.ts` |
|
|
33
|
+
| `src/types/date-time.ts` | `DateTime` | Immutable date-time class with formatting, arithmetic, and comparison | `date-time.spec.ts` |
|
|
34
|
+
| `src/types/date-only.ts` | `DateOnly` | Immutable date-only class (year, month, day) without time component | `date-only.spec.ts` |
|
|
35
|
+
| `src/types/time.ts` | `Time` | Immutable time-of-day class (hour, minute, second) | `time.spec.ts` |
|
|
36
|
+
|
|
37
|
+
### features
|
|
38
|
+
|
|
39
|
+
| Source | Exports | Description | Test |
|
|
40
|
+
|--------|---------|-------------|------|
|
|
41
|
+
| `src/features/debounce-queue.ts` | `DebounceQueue` | Queue that debounces rapid calls into a single delayed execution | `debounce-queue.spec.ts` |
|
|
42
|
+
| `src/features/serial-queue.ts` | `SerialQueue` | Queue that serializes async operations to run one at a time | `serial-queue.spec.ts` |
|
|
43
|
+
| `src/features/event-emitter.ts` | `EventEmitter` | Type-safe event emitter with on/off/emit pattern | `sd-event-emitter.spec.ts` |
|
|
44
|
+
|
|
45
|
+
### utils
|
|
46
|
+
|
|
47
|
+
| Source | Exports | Description | Test |
|
|
48
|
+
|--------|---------|-------------|------|
|
|
49
|
+
| `src/utils/date-format.ts` | `DtNormalizedMonth`, `normalizeMonth`, `convert12To24`, `formatDate` | Date formatting and month normalization utilities | `date-format.spec.ts` |
|
|
50
|
+
| `src/utils/bytes.ts` | `bytesConcat`, `bytesToHex`, `bytesFromHex`, `bytesToBase64`, `bytesFromBase64` | Binary conversion utilities (hex, base64, concat) | `bytes-utils.spec.ts` |
|
|
51
|
+
| `src/utils/json.ts` | `jsonStringify`, `jsonParse` | JSON stringify/parse with custom type support (DateTime, DateOnly, etc.) | `json.spec.ts` |
|
|
52
|
+
| `src/utils/num.ts` | `numParseInt`, `numParseRoundedInt`, `numParseFloat`, `numIsNullOrEmpty`, `numFormat` | Number parsing and formatting utilities | `number.spec.ts` |
|
|
53
|
+
| `src/utils/obj.ts` | `objClone`, `EqualOptions`, `objEqual`, `ObjMergeOptions`, `objMerge`, `ObjMerge3KeyOptions`, `objMerge3`, `objOmit`, `objOmitByFilter`, `objPick`, `objGetChainValue`, `objGetChainValueByDepth`, `objSetChainValue`, `objDeleteChainValue`, `objClearUndefined`, `objClear`, `objNullToUndefined`, `objUnflatten`, `ObjUndefToOptional`, `ObjOptionalToUndef`, `objKeys`, `objEntries`, `objFromEntries`, `objMap` | Deep object utilities (clone, equal, merge, pick, omit, chain access) | `object.spec.ts` |
|
|
54
|
+
| `src/utils/primitive.ts` | `getPrimitiveTypeStr` | Primitive type string detection utility | `primitive.spec.ts` |
|
|
55
|
+
| `src/utils/str.ts` | `koreanGetSuffix`, `strReplaceFullWidth`, `strToPascalCase`, `strToCamelCase`, `strToKebabCase`, `strToSnakeCase`, `strIsNullOrEmpty`, `strInsert` | String utilities (case conversion, Korean suffix, full-width replacement) | `string.spec.ts` |
|
|
56
|
+
| `src/utils/template-strings.ts` | `js`, `ts`, `html`, `tsql`, `mysql`, `pgsql` | Tagged template literals for JS, TS, HTML, SQL syntax highlighting | `template-strings.spec.ts` |
|
|
57
|
+
| `src/utils/transferable.ts` | `transferableEncode`, `transferableDecode` | Encode/decode objects with Transferable types for structured clone | `transferable.spec.ts` |
|
|
58
|
+
| `src/utils/wait.ts` | `waitUntil`, `waitTime` | Async wait utilities (until condition, timed delay) | `wait.spec.ts` |
|
|
59
|
+
| `src/utils/xml.ts` | `xmlParse`, `xmlStringify` | XML parse and stringify utilities | `xml.spec.ts` |
|
|
60
|
+
| `src/utils/path.ts` | `pathJoin`, `pathBasename`, `pathExtname` | Platform-independent path join, basename, and extension utilities | `path.spec.ts` |
|
|
61
|
+
| `src/utils/error.ts` | `errorMessage` | Extract error message string from unknown error values | - |
|
|
62
|
+
|
|
63
|
+
### zip
|
|
64
|
+
|
|
65
|
+
| Source | Exports | Description | Test |
|
|
66
|
+
|--------|---------|-------------|------|
|
|
67
|
+
| `src/zip/sd-zip.ts` | `ZipArchiveProgress`, `ZipArchive` | ZIP archive creation and extraction with progress callback | `sd-zip.spec.ts` |
|
|
68
|
+
|
|
69
|
+
### type utilities
|
|
70
|
+
|
|
71
|
+
| Source | Exports | Description | Test |
|
|
72
|
+
|--------|---------|-------------|------|
|
|
73
|
+
| `src/common.types.ts` | `Bytes`, `PrimitiveTypeMap`, `PrimitiveTypeStr`, `PrimitiveType`, `DeepPartial`, `Type` | Common type utilities (Bytes, PrimitiveType, DeepPartial, Type) | - |
|
|
275
74
|
|
|
276
75
|
## License
|
|
277
76
|
|
package/dist/common.types.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { DateOnly } from "./types/date-only";
|
|
|
3
3
|
import { Time } from "./types/time";
|
|
4
4
|
import { Uuid } from "./types/uuid";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Binary type used instead of Buffer
|
|
7
7
|
*/
|
|
8
8
|
export type Bytes = Uint8Array;
|
|
9
9
|
/**
|
|
10
|
-
* Primitive
|
|
11
|
-
* orm-common
|
|
10
|
+
* Primitive type mapping
|
|
11
|
+
* Shared with orm-common
|
|
12
12
|
*/
|
|
13
13
|
export type PrimitiveTypeMap = {
|
|
14
14
|
string: string;
|
|
@@ -21,19 +21,19 @@ export type PrimitiveTypeMap = {
|
|
|
21
21
|
Bytes: Bytes;
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* Primitive
|
|
24
|
+
* Primitive type string key
|
|
25
25
|
*/
|
|
26
26
|
export type PrimitiveTypeStr = keyof PrimitiveTypeMap;
|
|
27
27
|
/**
|
|
28
|
-
* Primitive
|
|
28
|
+
* Primitive type union
|
|
29
29
|
*/
|
|
30
30
|
export type PrimitiveType = PrimitiveTypeMap[PrimitiveTypeStr] | undefined;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Deep Partial type
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
* Primitive
|
|
36
|
-
*
|
|
34
|
+
* Recursively makes all properties of an object optional.
|
|
35
|
+
* Primitive types (string, number, boolean, etc.) are kept as-is,
|
|
36
|
+
* only object/array types have Partial applied recursively.
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
39
|
* ```typescript
|
|
@@ -45,7 +45,7 @@ export type PrimitiveType = PrimitiveTypeMap[PrimitiveTypeStr] | undefined;
|
|
|
45
45
|
* };
|
|
46
46
|
* }
|
|
47
47
|
*
|
|
48
|
-
* //
|
|
48
|
+
* // All properties at every depth become optional
|
|
49
49
|
* const partial: DeepPartial<User> = {
|
|
50
50
|
* profile: { address: {} }
|
|
51
51
|
* };
|
|
@@ -55,10 +55,10 @@ export type DeepPartial<TObject> = Partial<{
|
|
|
55
55
|
[K in keyof TObject]: TObject[K] extends PrimitiveType ? TObject[K] : DeepPartial<TObject[K]>;
|
|
56
56
|
}>;
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* Constructor type
|
|
59
59
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* Used to represent a class constructor as a type.
|
|
61
|
+
* Primarily used in dependency injection, factory patterns, and instanceof checks.
|
|
62
62
|
*
|
|
63
63
|
* @example
|
|
64
64
|
* function create<T>(ctor: Type<T>): T {
|
|
@@ -66,7 +66,7 @@ export type DeepPartial<TObject> = Partial<{
|
|
|
66
66
|
* }
|
|
67
67
|
*
|
|
68
68
|
* class MyClass { name = "test"; }
|
|
69
|
-
* const instance = create(MyClass); // MyClass
|
|
69
|
+
* const instance = create(MyClass); // MyClass instance
|
|
70
70
|
*/
|
|
71
71
|
export interface Type<TInstance> extends Function {
|
|
72
72
|
new (...args: unknown[]): TInstance;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { SdError } from "./sd-error";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Argument error
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* An error thrown when invalid arguments are received.
|
|
6
|
+
* Includes the argument object in YAML format in the message to facilitate debugging.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* //
|
|
9
|
+
* // Passing only the argument object
|
|
10
10
|
* throw new ArgumentError({ userId: 123, name: null });
|
|
11
|
-
* //
|
|
11
|
+
* // Result message: "Invalid arguments.\n\nuserId: 123\nname: null"
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
* //
|
|
15
|
-
* throw new ArgumentError("
|
|
16
|
-
* //
|
|
14
|
+
* // Passing a custom message and argument object
|
|
15
|
+
* throw new ArgumentError("Invalid user", { userId: 123 });
|
|
16
|
+
* // Result message: "Invalid user\n\nuserId: 123"
|
|
17
17
|
*/
|
|
18
18
|
export declare class ArgumentError extends SdError {
|
|
19
|
-
/**
|
|
19
|
+
/** Output argument object in YAML format with default message ("Invalid arguments.") */
|
|
20
20
|
constructor(argObj: Record<string, unknown>);
|
|
21
|
-
/**
|
|
21
|
+
/** Output argument object in YAML format with a custom message */
|
|
22
22
|
constructor(message: string, argObj: Record<string, unknown>);
|
|
23
23
|
constructor(arg1: Record<string, unknown> | string, arg2?: Record<string, unknown>);
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"argument-error.d.ts","sourceRoot":"","sources":["../../src/errors/argument-error.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,
|
|
1
|
+
{"version":3,"file":"argument-error.d.ts","sourceRoot":"","sources":["../../src/errors/argument-error.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,wFAAwF;gBAC5E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3C,kEAAkE;gBACtD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAChD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAYnF"}
|
|
@@ -5,9 +5,9 @@ class ArgumentError extends SdError {
|
|
|
5
5
|
const message = typeof arg1 === "string" ? arg1 : void 0;
|
|
6
6
|
const argObj = typeof arg1 === "string" ? arg2 : arg1;
|
|
7
7
|
if (argObj != null) {
|
|
8
|
-
super((message ?? "
|
|
8
|
+
super((message ?? "Invalid arguments.") + "\n\n" + YAML.stringify(argObj));
|
|
9
9
|
} else {
|
|
10
|
-
super(message ?? "
|
|
10
|
+
super(message ?? "Invalid arguments.");
|
|
11
11
|
}
|
|
12
12
|
this.name = "ArgumentError";
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/errors/argument-error.ts"],
|
|
4
|
-
"mappings": "AAGA,OAAO,UAAU;AACjB,SAAS,eAAe;AAkBjB,MAAM,sBAAsB,QAAQ;AAAA,EAMzC,YAAY,MAAwC,MAAgC;AAClF,UAAM,UAAU,OAAO,SAAS,WAAW,OAAO;AAClD,UAAM,SAAS,OAAO,SAAS,WAAW,OAAO;AAEjD,QAAI,UAAU,MAAM;AAClB,aAAO,WAAW,
|
|
4
|
+
"mappings": "AAGA,OAAO,UAAU;AACjB,SAAS,eAAe;AAkBjB,MAAM,sBAAsB,QAAQ;AAAA,EAMzC,YAAY,MAAwC,MAAgC;AAClF,UAAM,UAAU,OAAO,SAAS,WAAW,OAAO;AAClD,UAAM,SAAS,OAAO,SAAS,WAAW,OAAO;AAEjD,QAAI,UAAU,MAAM;AAClB,aAAO,WAAW,wBAAwB,SAAS,KAAK,UAAU,MAAM,CAAC;AAAA,IAC3E,OAAO;AACL,YAAM,WAAW,oBAAoB;AAAA,IACvC;AACA,SAAK,OAAO;AAAA,EACd;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { SdError } from "./sd-error";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Not implemented error
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* An error thrown when a feature that has not yet been implemented is called.
|
|
6
|
+
* Used for abstract method stubs, branches planned for future implementation, etc.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* //
|
|
9
|
+
* // Before abstract method implementation
|
|
10
10
|
* class BaseService {
|
|
11
11
|
* process(): void {
|
|
12
|
-
* throw new NotImplementedError("
|
|
12
|
+
* throw new NotImplementedError("Implementation required in subclass");
|
|
13
13
|
* }
|
|
14
14
|
* }
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
|
-
* //
|
|
17
|
+
* // Branch planned for future implementation
|
|
18
18
|
* switch (type) {
|
|
19
19
|
* case "A": return handleA();
|
|
20
|
-
* case "B": throw new NotImplementedError(
|
|
20
|
+
* case "B": throw new NotImplementedError(`Handling for type ${type}`);
|
|
21
21
|
* }
|
|
22
22
|
*/
|
|
23
23
|
export declare class NotImplementedError extends SdError {
|
|
24
24
|
/**
|
|
25
|
-
* @param message
|
|
25
|
+
* @param message Additional description message
|
|
26
26
|
*/
|
|
27
27
|
constructor(message?: string);
|
|
28
28
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SdError } from "./sd-error.js";
|
|
2
2
|
class NotImplementedError extends SdError {
|
|
3
3
|
/**
|
|
4
|
-
* @param message
|
|
4
|
+
* @param message Additional description message
|
|
5
5
|
*/
|
|
6
6
|
constructor(message) {
|
|
7
|
-
super("
|
|
7
|
+
super("Not implemented" + (message != null ? ": " + message : ""));
|
|
8
8
|
this.name = "NotImplementedError";
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/errors/not-implemented-error.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,eAAe;AAuBjB,MAAM,4BAA4B,QAAQ;AAAA;AAAA;AAAA;AAAA,EAI/C,YAAY,SAAkB;AAC5B,UAAM,
|
|
4
|
+
"mappings": "AAAA,SAAS,eAAe;AAuBjB,MAAM,4BAA4B,QAAQ;AAAA;AAAA;AAAA;AAAA,EAI/C,YAAY,SAAkB;AAC5B,UAAM,qBAAqB,WAAW,OAAO,OAAO,UAAU,GAAG;AACjE,SAAK,OAAO;AAAA,EACd;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* ES2024 cause
|
|
2
|
+
* Error class supporting Tree structure composition
|
|
3
|
+
* Utilizes ES2024 cause property
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* //
|
|
6
|
+
* // Wrap a cause error
|
|
7
7
|
* try {
|
|
8
8
|
* await fetch(url);
|
|
9
9
|
* } catch (err) {
|
|
10
|
-
* throw new SdError(err, "API
|
|
10
|
+
* throw new SdError(err, "API call failed", "User load failed");
|
|
11
11
|
* }
|
|
12
|
-
* //
|
|
12
|
+
* // Result message: "User load failed => API call failed => original error message"
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* //
|
|
16
|
-
* throw new SdError("
|
|
17
|
-
* //
|
|
15
|
+
* // Create with message only
|
|
16
|
+
* throw new SdError("invalid state", "processing not possible");
|
|
17
|
+
* // Result message: "processing not possible => invalid state"
|
|
18
18
|
*/
|
|
19
19
|
export declare class SdError extends Error {
|
|
20
20
|
cause?: Error;
|
|
21
|
-
/**
|
|
21
|
+
/** Create by wrapping a cause error. Messages are joined in reverse order (upper message => lower message => cause message) */
|
|
22
22
|
constructor(cause: Error, ...messages: string[]);
|
|
23
|
-
/**
|
|
23
|
+
/** Create with messages only. Messages are joined in reverse order (upper message => lower message) */
|
|
24
24
|
constructor(...messages: string[]);
|
|
25
25
|
constructor(arg1?: unknown, ...messages: string[]);
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sd-error.d.ts","sourceRoot":"","sources":["../../src/errors/sd-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,OAAQ,SAAQ,KAAK;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;IAEvB
|
|
1
|
+
{"version":3,"file":"sd-error.d.ts","sourceRoot":"","sources":["../../src/errors/sd-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,OAAQ,SAAQ,KAAK;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;IAEvB,+HAA+H;gBACnH,KAAK,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE;IAC/C,uGAAuG;gBAC3F,GAAG,QAAQ,EAAE,MAAM,EAAE;gBACrB,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE;CAoClD"}
|