@simplysm/core-common 14.0.4 → 14.0.6
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 +123 -59
- package/docs/array-extensions.md +171 -164
- package/docs/env.md +8 -27
- package/docs/errors.md +15 -51
- package/docs/features.md +52 -68
- package/docs/map-extensions.md +41 -0
- package/docs/set-extensions.md +38 -0
- package/docs/template-strings-and-zip.md +87 -0
- package/docs/type-utilities.md +19 -35
- package/docs/types.md +111 -111
- package/docs/utilities.md +723 -0
- package/package.json +1 -1
- package/docs/utils.md +0 -641
package/docs/types.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# Types
|
|
2
2
|
|
|
3
|
-
Immutable value types for UUID, date/time, and a self-expiring map.
|
|
4
|
-
|
|
5
3
|
## `Uuid`
|
|
6
4
|
|
|
7
|
-
UUID v4 class.
|
|
5
|
+
UUID v4 class. Generates cryptographically secure UUIDs using `crypto.getRandomValues`.
|
|
8
6
|
|
|
9
7
|
```typescript
|
|
10
8
|
class Uuid {
|
|
@@ -22,32 +20,27 @@ class Uuid {
|
|
|
22
20
|
|
|
23
21
|
| Method | Description |
|
|
24
22
|
|--------|-------------|
|
|
25
|
-
| `generate()` |
|
|
26
|
-
| `fromBytes(bytes)` |
|
|
27
|
-
|
|
28
|
-
### Constructor
|
|
29
|
-
|
|
30
|
-
| Parameter | Type | Description |
|
|
31
|
-
|-----------|------|-------------|
|
|
32
|
-
| `uuid` | `string` | UUID string in format `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`. Throws `ArgumentError` if invalid |
|
|
23
|
+
| `generate()` | Create a new random UUID v4 instance |
|
|
24
|
+
| `fromBytes(bytes)` | Create UUID from a 16-byte `Uint8Array`. Throws `ArgumentError` if length is not 16. |
|
|
33
25
|
|
|
34
26
|
### Instance Methods
|
|
35
27
|
|
|
36
28
|
| Method | Returns | Description |
|
|
37
29
|
|--------|---------|-------------|
|
|
38
|
-
| `toString()` | `string` |
|
|
39
|
-
| `toBytes()` | `Bytes` |
|
|
30
|
+
| `toString()` | `string` | UUID string in `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` format |
|
|
31
|
+
| `toBytes()` | `Bytes` | 16-byte `Uint8Array` representation |
|
|
40
32
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
### Constructor
|
|
34
|
+
|
|
35
|
+
| Parameter | Type | Description |
|
|
36
|
+
|-----------|------|-------------|
|
|
37
|
+
| `uuid` | `string` | UUID string. Must match format `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`. Throws `ArgumentError` if invalid. |
|
|
38
|
+
|
|
39
|
+
---
|
|
47
40
|
|
|
48
41
|
## `LazyGcMap<TKey, TValue>`
|
|
49
42
|
|
|
50
|
-
|
|
43
|
+
Auto-expiring Map with LRU-style access tracking. Items are automatically deleted after the configured expire time if not accessed. Must be disposed after use to stop the GC timer.
|
|
51
44
|
|
|
52
45
|
```typescript
|
|
53
46
|
class LazyGcMap<TKey, TValue> {
|
|
@@ -62,52 +55,46 @@ class LazyGcMap<TKey, TValue> {
|
|
|
62
55
|
get(key: TKey): TValue | undefined;
|
|
63
56
|
set(key: TKey, value: TValue): void;
|
|
64
57
|
delete(key: TKey): boolean;
|
|
65
|
-
getOrCreate(key: TKey, factory: () => TValue): TValue;
|
|
66
58
|
clear(): void;
|
|
67
|
-
|
|
68
|
-
[Symbol.dispose](): void;
|
|
69
|
-
|
|
59
|
+
getOrCreate(key: TKey, factory: () => TValue): TValue;
|
|
70
60
|
values(): IterableIterator<TValue>;
|
|
71
61
|
keys(): IterableIterator<TKey>;
|
|
72
62
|
entries(): IterableIterator<[TKey, TValue]>;
|
|
63
|
+
dispose(): void;
|
|
64
|
+
[Symbol.dispose](): void;
|
|
73
65
|
}
|
|
74
66
|
```
|
|
75
67
|
|
|
76
68
|
### Constructor Options
|
|
77
69
|
|
|
78
|
-
| Option | Type |
|
|
79
|
-
|
|
80
|
-
| `gcInterval` | `number` | `expireTime / 10` (min 1000ms) |
|
|
81
|
-
| `expireTime` | `number` |
|
|
82
|
-
| `onExpire` | `(key, value) => void \| Promise<void>` |
|
|
70
|
+
| Option | Type | Description |
|
|
71
|
+
|--------|------|-------------|
|
|
72
|
+
| `gcInterval` | `number \| undefined` | GC check interval in ms. Default: `expireTime / 10` (min 1000ms). |
|
|
73
|
+
| `expireTime` | `number` | Time in ms after last access before an item is expired. |
|
|
74
|
+
| `onExpire` | `(key, value) => void \| Promise<void>` | Callback invoked when an item expires. Errors are logged, not thrown. |
|
|
83
75
|
|
|
84
76
|
### Methods
|
|
85
77
|
|
|
86
|
-
| Method | Description |
|
|
87
|
-
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
93
|
-
| `clear()` | Remove all
|
|
94
|
-
| `
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
map.set("conn1", createConnection());
|
|
105
|
-
const conn = map.get("conn1"); // refreshes access time
|
|
106
|
-
```
|
|
78
|
+
| Method | Returns | Description |
|
|
79
|
+
|--------|---------|-------------|
|
|
80
|
+
| `size` | `number` | Number of stored items |
|
|
81
|
+
| `has(key)` | `boolean` | Check if key exists (does not refresh access time) |
|
|
82
|
+
| `get(key)` | `TValue \| undefined` | Get value and refresh access time (LRU) |
|
|
83
|
+
| `set(key, value)` | `void` | Store value and start GC timer if needed |
|
|
84
|
+
| `delete(key)` | `boolean` | Remove item. Stops GC timer if map becomes empty. |
|
|
85
|
+
| `clear()` | `void` | Remove all items (instance remains usable) |
|
|
86
|
+
| `getOrCreate(key, factory)` | `TValue` | Get existing value or create via factory, store, and return. Throws if disposed. |
|
|
87
|
+
| `values()` | `IterableIterator<TValue>` | Iterate over values |
|
|
88
|
+
| `keys()` | `IterableIterator<TKey>` | Iterate over keys |
|
|
89
|
+
| `entries()` | `IterableIterator<[TKey, TValue]>` | Iterate over [key, value] pairs |
|
|
90
|
+
| `dispose()` | `void` | Stop GC timer and clear all data |
|
|
91
|
+
| `[Symbol.dispose]()` | `void` | Supports `using` statement |
|
|
92
|
+
|
|
93
|
+
---
|
|
107
94
|
|
|
108
95
|
## `DateTime`
|
|
109
96
|
|
|
110
|
-
Immutable date-time class wrapping JavaScript `Date`.
|
|
97
|
+
Immutable date-time class wrapping JavaScript `Date`. Provides millisecond precision and local timezone operation.
|
|
111
98
|
|
|
112
99
|
```typescript
|
|
113
100
|
class DateTime {
|
|
@@ -122,14 +109,14 @@ class DateTime {
|
|
|
122
109
|
|
|
123
110
|
// Getters
|
|
124
111
|
get year(): number;
|
|
125
|
-
get month(): number;
|
|
112
|
+
get month(): number;
|
|
126
113
|
get day(): number;
|
|
127
114
|
get hour(): number;
|
|
128
115
|
get minute(): number;
|
|
129
116
|
get second(): number;
|
|
130
117
|
get millisecond(): number;
|
|
131
118
|
get tick(): number;
|
|
132
|
-
get dayOfWeek(): number;
|
|
119
|
+
get dayOfWeek(): number;
|
|
133
120
|
get timezoneOffsetMinutes(): number;
|
|
134
121
|
get isValid(): boolean;
|
|
135
122
|
|
|
@@ -153,32 +140,43 @@ class DateTime {
|
|
|
153
140
|
|
|
154
141
|
// Formatting
|
|
155
142
|
toFormatString(formatStr: string): string;
|
|
156
|
-
toString(): string;
|
|
143
|
+
toString(): string;
|
|
157
144
|
}
|
|
158
145
|
```
|
|
159
146
|
|
|
160
|
-
###
|
|
147
|
+
### Static Methods
|
|
148
|
+
|
|
149
|
+
| Method | Description |
|
|
150
|
+
|--------|-------------|
|
|
151
|
+
| `parse(str)` | Parse string to DateTime. Supported formats: `yyyy-MM-dd HH:mm:ss`, `yyyy-MM-dd HH:mm:ss.fff`, `yyyyMMddHHmmss`, `yyyy-MM-dd AM/PM HH:mm:ss`, ISO 8601. Throws `ArgumentError` on failure. |
|
|
152
|
+
|
|
153
|
+
### Getters
|
|
161
154
|
|
|
162
|
-
|
|
|
163
|
-
|
|
164
|
-
| `
|
|
165
|
-
| `
|
|
166
|
-
| `
|
|
167
|
-
| `
|
|
168
|
-
|
|
|
169
|
-
|
|
|
155
|
+
| Property | Type | Description |
|
|
156
|
+
|----------|------|-------------|
|
|
157
|
+
| `year` | `number` | Full year |
|
|
158
|
+
| `month` | `number` | Month (1-12) |
|
|
159
|
+
| `day` | `number` | Day of month (1-31) |
|
|
160
|
+
| `hour` | `number` | Hour (0-23) |
|
|
161
|
+
| `minute` | `number` | Minute (0-59) |
|
|
162
|
+
| `second` | `number` | Second (0-59) |
|
|
163
|
+
| `millisecond` | `number` | Millisecond (0-999) |
|
|
164
|
+
| `tick` | `number` | Milliseconds since epoch |
|
|
165
|
+
| `dayOfWeek` | `number` | Day of week (0=Sunday, 6=Saturday) |
|
|
166
|
+
| `timezoneOffsetMinutes` | `number` | Local timezone offset in minutes (e.g., +540 for KST) |
|
|
167
|
+
| `isValid` | `boolean` | Whether the date is valid |
|
|
170
168
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
169
|
+
### Formatting
|
|
170
|
+
|
|
171
|
+
`toFormatString(formatStr)` uses C#-style format patterns. See `dt.format` in [utilities.md](./utilities.md) for the full pattern table.
|
|
172
|
+
|
|
173
|
+
`toString()` returns `"yyyy-MM-ddTHH:mm:ss.fffzzz"`.
|
|
174
|
+
|
|
175
|
+
---
|
|
178
176
|
|
|
179
177
|
## `DateOnly`
|
|
180
178
|
|
|
181
|
-
Immutable date class (no time component). Local timezone.
|
|
179
|
+
Immutable date-only class (no time component). Local timezone based.
|
|
182
180
|
|
|
183
181
|
```typescript
|
|
184
182
|
class DateOnly {
|
|
@@ -198,10 +196,10 @@ class DateOnly {
|
|
|
198
196
|
|
|
199
197
|
// Getters
|
|
200
198
|
get year(): number;
|
|
201
|
-
get month(): number;
|
|
199
|
+
get month(): number;
|
|
202
200
|
get day(): number;
|
|
203
201
|
get tick(): number;
|
|
204
|
-
get dayOfWeek(): number;
|
|
202
|
+
get dayOfWeek(): number;
|
|
205
203
|
get isValid(): boolean;
|
|
206
204
|
|
|
207
205
|
// Immutable setters
|
|
@@ -214,7 +212,7 @@ class DateOnly {
|
|
|
214
212
|
addMonths(months: number): DateOnly;
|
|
215
213
|
addDays(days: number): DateOnly;
|
|
216
214
|
|
|
217
|
-
// Week
|
|
215
|
+
// Week sequence
|
|
218
216
|
getBaseYearMonthSeqForWeekSeq(weekStartDay?: number, minDaysInFirstWeek?: number): { year: number; monthSeq: number };
|
|
219
217
|
getWeekSeqStartDate(weekStartDay?: number, minDaysInFirstWeek?: number): DateOnly;
|
|
220
218
|
getWeekSeqOfYear(weekStartDay?: number, minDaysInFirstWeek?: number): { year: number; weekSeq: number };
|
|
@@ -222,37 +220,37 @@ class DateOnly {
|
|
|
222
220
|
|
|
223
221
|
// Formatting
|
|
224
222
|
toFormatString(formatStr: string): string;
|
|
225
|
-
toString(): string;
|
|
223
|
+
toString(): string;
|
|
226
224
|
}
|
|
227
225
|
```
|
|
228
226
|
|
|
229
|
-
###
|
|
227
|
+
### Static Methods
|
|
230
228
|
|
|
231
|
-
|
|
|
232
|
-
|
|
233
|
-
| `yyyy-MM-dd`
|
|
234
|
-
| `
|
|
235
|
-
| ISO 8601 | `"2025-01-15T00:00:00Z"` (converted to local) |
|
|
229
|
+
| Method | Description |
|
|
230
|
+
|--------|-------------|
|
|
231
|
+
| `parse(str)` | Parse string to DateOnly. Supported formats: `yyyy-MM-dd`, `yyyyMMdd`, ISO 8601. Throws `ArgumentError` on failure. |
|
|
232
|
+
| `getDateByYearWeekSeq(arg, weekStartDay?, minDaysInFirstWeek?)` | Get the start date of a given week number within a year or month. |
|
|
236
233
|
|
|
237
|
-
### Week
|
|
234
|
+
### Week Sequence Methods
|
|
238
235
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
| `minDaysInFirstWeek` | `4` (ISO 8601) | Minimum days in the first week |
|
|
236
|
+
All week methods accept optional parameters:
|
|
237
|
+
- `weekStartDay`: 0=Sunday, 1=Monday (default), ..., 6=Saturday
|
|
238
|
+
- `minDaysInFirstWeek`: Minimum days for first week (default: 4, ISO 8601)
|
|
243
239
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
240
|
+
| Method | Returns | Description |
|
|
241
|
+
|--------|---------|-------------|
|
|
242
|
+
| `getBaseYearMonthSeqForWeekSeq(...)` | `{ year, monthSeq }` | Base year and month for this date's week |
|
|
243
|
+
| `getWeekSeqStartDate(...)` | `DateOnly` | Start date of this date's week |
|
|
244
|
+
| `getWeekSeqOfYear(...)` | `{ year, weekSeq }` | Year and week number within that year |
|
|
245
|
+
| `getWeekSeqOfMonth(...)` | `{ year, monthSeq, weekSeq }` | Year, month, and week number within that month |
|
|
246
|
+
|
|
247
|
+
`toString()` returns `"yyyy-MM-dd"`.
|
|
248
|
+
|
|
249
|
+
---
|
|
252
250
|
|
|
253
251
|
## `Time`
|
|
254
252
|
|
|
255
|
-
Immutable time class (no date component). Values
|
|
253
|
+
Immutable time-only class (no date component). Values wrap around 24 hours. Negative values are normalized.
|
|
256
254
|
|
|
257
255
|
```typescript
|
|
258
256
|
class Time {
|
|
@@ -277,7 +275,7 @@ class Time {
|
|
|
277
275
|
setSecond(second: number): Time;
|
|
278
276
|
setMillisecond(millisecond: number): Time;
|
|
279
277
|
|
|
280
|
-
// Arithmetic (
|
|
278
|
+
// Arithmetic (24-hour wrapping)
|
|
281
279
|
addHours(hours: number): Time;
|
|
282
280
|
addMinutes(minutes: number): Time;
|
|
283
281
|
addSeconds(seconds: number): Time;
|
|
@@ -285,23 +283,25 @@ class Time {
|
|
|
285
283
|
|
|
286
284
|
// Formatting
|
|
287
285
|
toFormatString(formatStr: string): string;
|
|
288
|
-
toString(): string;
|
|
286
|
+
toString(): string;
|
|
289
287
|
}
|
|
290
288
|
```
|
|
291
289
|
|
|
292
|
-
###
|
|
290
|
+
### Static Methods
|
|
293
291
|
|
|
294
|
-
|
|
|
295
|
-
|
|
296
|
-
| `HH:mm:ss`
|
|
297
|
-
| `HH:mm:ss.fff` | `"10:30:00.123"` |
|
|
298
|
-
| `AM/PM HH:mm:ss` | `"AM 10:30:00"` |
|
|
299
|
-
| ISO 8601 (time part) | `"2025-01-15T10:30:00Z"` |
|
|
292
|
+
| Method | Description |
|
|
293
|
+
|--------|-------------|
|
|
294
|
+
| `parse(str)` | Parse string to Time. Supported formats: `HH:mm:ss`, `HH:mm:ss.fff`, `AM/PM HH:mm:ss`, ISO 8601 (time part extracted). Throws `ArgumentError` on failure. |
|
|
300
295
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
296
|
+
### Getters
|
|
297
|
+
|
|
298
|
+
| Property | Type | Description |
|
|
299
|
+
|----------|------|-------------|
|
|
300
|
+
| `hour` | `number` | Hour (0-23) |
|
|
301
|
+
| `minute` | `number` | Minute (0-59) |
|
|
302
|
+
| `second` | `number` | Second (0-59) |
|
|
303
|
+
| `millisecond` | `number` | Millisecond (0-999) |
|
|
304
|
+
| `tick` | `number` | Total milliseconds from midnight (0 to 86399999) |
|
|
305
|
+
| `isValid` | `boolean` | Whether the time is valid |
|
|
306
|
+
|
|
307
|
+
`toString()` returns `"HH:mm:ss.fff"`.
|