@simplysm/core-common 13.0.100 → 14.0.4
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 +86 -92
- package/dist/common.types.d.ts +14 -14
- package/dist/common.types.js +2 -1
- package/dist/common.types.js.map +1 -6
- package/dist/env.d.ts +8 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +13 -9
- package/dist/env.js.map +1 -6
- 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 +31 -14
- package/dist/errors/argument-error.js.map +1 -6
- package/dist/errors/not-implemented-error.d.ts +8 -8
- package/dist/errors/not-implemented-error.js +30 -12
- package/dist/errors/not-implemented-error.js.map +1 -6
- package/dist/errors/sd-error.d.ts +10 -10
- package/dist/errors/sd-error.d.ts.map +1 -1
- package/dist/errors/sd-error.js +45 -24
- package/dist/errors/sd-error.js.map +1 -6
- package/dist/errors/timeout-error.d.ts +10 -10
- package/dist/errors/timeout-error.js +34 -15
- package/dist/errors/timeout-error.js.map +1 -6
- package/dist/extensions/arr-ext.d.ts +2 -2
- package/dist/extensions/arr-ext.helpers.d.ts +10 -10
- package/dist/extensions/arr-ext.helpers.js +112 -89
- package/dist/extensions/arr-ext.helpers.js.map +1 -6
- package/dist/extensions/arr-ext.js +458 -422
- package/dist/extensions/arr-ext.js.map +1 -6
- package/dist/extensions/arr-ext.types.d.ts +57 -57
- package/dist/extensions/arr-ext.types.d.ts.map +1 -1
- package/dist/extensions/arr-ext.types.js +6 -1
- package/dist/extensions/arr-ext.types.js.map +1 -6
- package/dist/extensions/map-ext.d.ts +16 -16
- package/dist/extensions/map-ext.js +27 -22
- package/dist/extensions/map-ext.js.map +1 -6
- package/dist/extensions/set-ext.d.ts +11 -11
- package/dist/extensions/set-ext.js +32 -25
- package/dist/extensions/set-ext.js.map +1 -6
- package/dist/features/debounce-queue.d.ts +17 -17
- package/dist/features/debounce-queue.js +98 -70
- package/dist/features/debounce-queue.js.map +1 -6
- package/dist/features/event-emitter.d.ts +20 -20
- package/dist/features/event-emitter.js +101 -78
- package/dist/features/event-emitter.js.map +1 -6
- package/dist/features/serial-queue.d.ts +11 -11
- package/dist/features/serial-queue.js +78 -57
- package/dist/features/serial-queue.js.map +1 -6
- package/dist/globals.d.ts +4 -4
- package/dist/globals.js +9 -1
- package/dist/globals.js.map +1 -6
- package/dist/index.js +28 -27
- package/dist/index.js.map +1 -6
- 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 +263 -252
- package/dist/types/date-only.js.map +1 -6
- package/dist/types/date-time.d.ts +36 -36
- package/dist/types/date-time.d.ts.map +1 -1
- package/dist/types/date-time.js +196 -288
- package/dist/types/date-time.js.map +1 -6
- 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 +202 -159
- package/dist/types/lazy-gc-map.js.map +1 -6
- package/dist/types/time.d.ts +23 -23
- package/dist/types/time.d.ts.map +1 -1
- package/dist/types/time.js +169 -158
- package/dist/types/time.js.map +1 -6
- package/dist/types/uuid.d.ts +11 -11
- package/dist/types/uuid.d.ts.map +1 -1
- package/dist/types/uuid.js +95 -70
- package/dist/types/uuid.js.map +1 -6
- package/dist/utils/bytes.d.ts +17 -17
- package/dist/utils/bytes.js +137 -81
- package/dist/utils/bytes.js.map +1 -6
- package/dist/utils/date-format.d.ts +40 -40
- package/dist/utils/date-format.js +187 -101
- package/dist/utils/date-format.js.map +1 -6
- package/dist/utils/error.d.ts +4 -4
- package/dist/utils/error.js +11 -6
- package/dist/utils/error.js.map +1 -6
- package/dist/utils/json.d.ts +19 -19
- package/dist/utils/json.js +187 -135
- package/dist/utils/json.js.map +1 -6
- package/dist/utils/num.d.ts +20 -20
- package/dist/utils/num.js +76 -34
- package/dist/utils/num.js.map +1 -6
- package/dist/utils/obj.d.ts +111 -111
- package/dist/utils/obj.d.ts.map +1 -1
- package/dist/utils/obj.js +706 -496
- package/dist/utils/obj.js.map +1 -6
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +35 -18
- package/dist/utils/path.js.map +1 -6
- package/dist/utils/primitive.d.ts +5 -5
- package/dist/utils/primitive.js +34 -14
- package/dist/utils/primitive.js.map +1 -6
- package/dist/utils/str.d.ts +38 -38
- package/dist/utils/str.js +217 -113
- package/dist/utils/str.js.map +1 -6
- package/dist/utils/template-strings.d.ts +26 -26
- package/dist/utils/template-strings.js +113 -40
- package/dist/utils/template-strings.js.map +1 -6
- package/dist/utils/transferable.d.ts +18 -18
- package/dist/utils/transferable.js +218 -151
- package/dist/utils/transferable.js.map +1 -6
- package/dist/utils/wait.d.ts +9 -9
- package/dist/utils/wait.js +30 -15
- package/dist/utils/wait.js.map +1 -6
- package/dist/utils/xml.d.ts +13 -13
- package/dist/utils/xml.js +84 -46
- package/dist/utils/xml.js.map +1 -6
- package/dist/utils/zip.d.ts +22 -22
- package/dist/utils/zip.js +172 -148
- package/dist/utils/zip.js.map +1 -6
- package/docs/array-extensions.md +430 -0
- package/docs/env.md +52 -0
- package/docs/errors.md +41 -56
- package/docs/features.md +82 -97
- package/docs/type-utilities.md +91 -0
- package/docs/types.md +221 -201
- package/docs/utils.md +319 -435
- package/package.json +7 -5
- package/src/common.types.ts +14 -14
- package/src/env.ts +12 -3
- 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 +16 -16
- package/src/extensions/arr-ext.ts +35 -35
- package/src/extensions/arr-ext.types.ts +57 -57
- package/src/extensions/map-ext.ts +16 -16
- package/src/extensions/set-ext.ts +11 -11
- package/src/features/debounce-queue.ts +23 -23
- 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 +5 -5
- package/src/types/date-only.ts +84 -83
- package/src/types/date-time.ts +43 -42
- package/src/types/lazy-gc-map.ts +44 -44
- package/src/types/time.ts +29 -29
- package/src/types/uuid.ts +15 -15
- package/src/utils/bytes.ts +35 -35
- package/src/utils/date-format.ts +59 -59
- package/src/utils/error.ts +4 -4
- package/src/utils/json.ts +41 -41
- package/src/utils/num.ts +20 -20
- 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 +48 -48
- package/src/utils/template-strings.ts +29 -29
- package/src/utils/transferable.ts +38 -38
- package/src/utils/wait.ts +10 -10
- package/src/utils/xml.ts +19 -19
- package/src/utils/zip.ts +25 -25
- package/docs/extensions.md +0 -387
- package/tests/errors/errors.spec.ts +0 -80
- package/tests/extensions/array-extension.spec.ts +0 -654
- package/tests/extensions/map-extension.spec.ts +0 -117
- package/tests/extensions/set-extension.spec.ts +0 -67
- package/tests/types/date-only.spec.ts +0 -533
- package/tests/types/date-time.spec.ts +0 -246
- package/tests/types/lazy-gc-map.spec.ts +0 -606
- package/tests/types/time.spec.ts +0 -428
- package/tests/types/uuid.spec.ts +0 -74
- package/tests/utils/bytes-utils.spec.ts +0 -197
- package/tests/utils/date-format.spec.ts +0 -350
- package/tests/utils/debounce-queue.spec.ts +0 -226
- package/tests/utils/json.spec.ts +0 -400
- package/tests/utils/number.spec.ts +0 -136
- package/tests/utils/object.spec.ts +0 -810
- package/tests/utils/path.spec.ts +0 -70
- package/tests/utils/primitive.spec.ts +0 -43
- package/tests/utils/sd-event-emitter.spec.ts +0 -189
- package/tests/utils/serial-queue.spec.ts +0 -305
- package/tests/utils/string.spec.ts +0 -265
- package/tests/utils/template-strings.spec.ts +0 -48
- package/tests/utils/transferable.spec.ts +0 -639
- package/tests/utils/wait.spec.ts +0 -123
- package/tests/utils/xml.spec.ts +0 -146
- package/tests/utils/zip.spec.ts +0 -221
package/docs/types.md
CHANGED
|
@@ -1,179 +1,56 @@
|
|
|
1
1
|
# Types
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Source: `src/types/*.ts`, `src/common.types.ts`, `src/env.ts`
|
|
6
|
-
|
|
7
|
-
---
|
|
3
|
+
Immutable value types for UUID, date/time, and a self-expiring map.
|
|
8
4
|
|
|
9
5
|
## `Uuid`
|
|
10
6
|
|
|
11
|
-
UUID v4 class.
|
|
7
|
+
UUID v4 class. Uses `crypto.getRandomValues` for cryptographically secure generation.
|
|
12
8
|
|
|
13
9
|
```typescript
|
|
14
|
-
|
|
15
|
-
/** Create new UUID v4 instance */
|
|
10
|
+
class Uuid {
|
|
16
11
|
static generate(): Uuid;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create UUID from 16-byte Uint8Array
|
|
20
|
-
* @throws {ArgumentError} If byte size is not 16
|
|
21
|
-
*/
|
|
22
12
|
static fromBytes(bytes: Bytes): Uuid;
|
|
23
13
|
|
|
24
|
-
/**
|
|
25
|
-
* @param uuid UUID string (format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
|
|
26
|
-
* @throws {ArgumentError} If format is invalid
|
|
27
|
-
*/
|
|
28
14
|
constructor(uuid: string);
|
|
29
15
|
|
|
30
|
-
/** Convert UUID to string */
|
|
31
16
|
toString(): string;
|
|
32
|
-
|
|
33
|
-
/** Convert UUID to 16-byte Uint8Array */
|
|
34
17
|
toBytes(): Bytes;
|
|
35
18
|
}
|
|
36
19
|
```
|
|
37
20
|
|
|
38
|
-
|
|
21
|
+
### Static Methods
|
|
39
22
|
|
|
40
|
-
|
|
23
|
+
| Method | Description |
|
|
24
|
+
|--------|-------------|
|
|
25
|
+
| `generate()` | Creates a new random UUID v4 instance |
|
|
26
|
+
| `fromBytes(bytes)` | Creates a UUID from a 16-byte `Uint8Array`. Throws `ArgumentError` if length is not 16 |
|
|
41
27
|
|
|
42
|
-
|
|
28
|
+
### Constructor
|
|
43
29
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
| Parameter | Type | Description |
|
|
31
|
+
|-----------|------|-------------|
|
|
32
|
+
| `uuid` | `string` | UUID string in format `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`. Throws `ArgumentError` if invalid |
|
|
47
33
|
|
|
48
|
-
|
|
49
|
-
constructor();
|
|
50
|
-
/** Create with year, month, day, hour, minute, second, millisecond */
|
|
51
|
-
constructor(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number);
|
|
52
|
-
/** Create from tick (millisecond) */
|
|
53
|
-
constructor(tick: number);
|
|
54
|
-
/** Create from Date object */
|
|
55
|
-
constructor(date: Date);
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Parse a string to create DateTime instance
|
|
59
|
-
* Supported formats: 'yyyy-MM-dd HH:mm:ss', 'yyyy-MM-dd HH:mm:ss.fff', 'yyyyMMddHHmmss',
|
|
60
|
-
* 'yyyy-MM-dd AM/PM HH:mm:ss', Korean AM/PM (오전/오후), ISO 8601
|
|
61
|
-
* @throws ArgumentError If unsupported format
|
|
62
|
-
*/
|
|
63
|
-
static parse(str: string): DateTime;
|
|
64
|
-
}
|
|
65
|
-
```
|
|
34
|
+
### Instance Methods
|
|
66
35
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
**Arithmetic** (return new instance): `addYears(n)`, `addMonths(n)`, `addDays(n)`, `addHours(n)`, `addMinutes(n)`, `addSeconds(n)`, `addMilliseconds(n)`
|
|
72
|
-
|
|
73
|
-
**Formatting**: `toFormatString(formatStr)`, `toString()` (default: `"yyyy-MM-ddTHH:mm:ss.fffzzz"`)
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## `DateOnly`
|
|
78
|
-
|
|
79
|
-
Immutable date class (without time: `yyyy-MM-dd`). Operates based on local timezone.
|
|
36
|
+
| Method | Returns | Description |
|
|
37
|
+
|--------|---------|-------------|
|
|
38
|
+
| `toString()` | `string` | Returns the UUID string representation |
|
|
39
|
+
| `toBytes()` | `Bytes` | Converts to a 16-byte `Uint8Array` |
|
|
80
40
|
|
|
81
41
|
```typescript
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
constructor();
|
|
87
|
-
/** Initialize with year, month, day */
|
|
88
|
-
constructor(year: number, month: number, day: number);
|
|
89
|
-
/** Create from tick (millisecond) */
|
|
90
|
-
constructor(tick: number);
|
|
91
|
-
/** Create from Date type */
|
|
92
|
-
constructor(date: Date);
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Parse a string into DateOnly
|
|
96
|
-
* Supported formats: 'yyyy-MM-dd', 'yyyyMMdd', ISO 8601
|
|
97
|
-
*/
|
|
98
|
-
static parse(str: string): DateOnly;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get the start date of a week based on week information
|
|
102
|
-
*/
|
|
103
|
-
static getDateByYearWeekSeq(
|
|
104
|
-
arg: { year: number; month?: number; weekSeq: number },
|
|
105
|
-
weekStartDay?: number,
|
|
106
|
-
minDaysInFirstWeek?: number,
|
|
107
|
-
): DateOnly;
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
**Getters** (read-only): `year`, `month`, `day`, `tick`, `dayOfWeek`, `isValid`
|
|
112
|
-
|
|
113
|
-
**Immutable setters**: `setYear(year)`, `setMonth(month)`, `setDay(day)`
|
|
114
|
-
|
|
115
|
-
**Arithmetic**: `addYears(n)`, `addMonths(n)`, `addDays(n)`
|
|
116
|
-
|
|
117
|
-
**Week calculation methods**:
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
120
|
-
getBaseYearMonthSeqForWeekSeq(weekStartDay?: number, minDaysInFirstWeek?: number): { year: number; monthSeq: number };
|
|
121
|
-
getWeekSeqStartDate(weekStartDay?: number, minDaysInFirstWeek?: number): DateOnly;
|
|
122
|
-
getWeekSeqOfYear(weekStartDay?: number, minDaysInFirstWeek?: number): { year: number; weekSeq: number };
|
|
123
|
-
getWeekSeqOfMonth(weekStartDay?: number, minDaysInFirstWeek?: number): { year: number; monthSeq: number; weekSeq: number };
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Defaults: `weekStartDay = 1` (Monday), `minDaysInFirstWeek = 4` (ISO 8601 standard).
|
|
127
|
-
|
|
128
|
-
**Formatting**: `toFormatString(formatStr)`, `toString()` (default: `"yyyy-MM-dd"`)
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
## `Time`
|
|
133
|
-
|
|
134
|
-
Immutable time class (without date: `HH:mm:ss.fff`). Values exceeding 24 hours or negative values are automatically normalized (24-hour wraparound).
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
export class Time {
|
|
138
|
-
/** Create with current time */
|
|
139
|
-
constructor();
|
|
140
|
-
/** Create with hour, minute, second, millisecond */
|
|
141
|
-
constructor(hour: number, minute: number, second?: number, millisecond?: number);
|
|
142
|
-
/** Create from tick (millisecond) */
|
|
143
|
-
constructor(tick: number);
|
|
144
|
-
/** Create by extracting time part only from Date object */
|
|
145
|
-
constructor(date: Date);
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Parse a string to create Time instance
|
|
149
|
-
* Supported formats: 'HH:mm:ss', 'HH:mm:ss.fff', 'AM/PM HH:mm:ss', ISO 8601 (extract time part)
|
|
150
|
-
* @throws ArgumentError If unsupported format
|
|
151
|
-
*/
|
|
152
|
-
static parse(str: string): Time;
|
|
153
|
-
}
|
|
42
|
+
const id = Uuid.generate();
|
|
43
|
+
const fromStr = new Uuid("550e8400-e29b-41d4-a716-446655440000");
|
|
44
|
+
const bytes = id.toBytes(); // Uint8Array(16)
|
|
45
|
+
const restored = Uuid.fromBytes(bytes);
|
|
154
46
|
```
|
|
155
47
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
**Immutable setters**: `setHour(hour)`, `setMinute(minute)`, `setSecond(second)`, `setMillisecond(millisecond)`
|
|
159
|
-
|
|
160
|
-
**Arithmetic** (24-hour wraparound): `addHours(n)`, `addMinutes(n)`, `addSeconds(n)`, `addMilliseconds(n)`
|
|
161
|
-
|
|
162
|
-
**Formatting**: `toFormatString(formatStr)`, `toString()` (default: `"HH:mm:ss.fff"`)
|
|
163
|
-
|
|
164
|
-
---
|
|
165
|
-
|
|
166
|
-
## `LazyGcMap`
|
|
48
|
+
## `LazyGcMap<TKey, TValue>`
|
|
167
49
|
|
|
168
|
-
Map with automatic expiration
|
|
50
|
+
A Map with automatic expiration. Entries not accessed within `expireTime` are garbage collected. Supports `using` syntax (Symbol.dispose).
|
|
169
51
|
|
|
170
52
|
```typescript
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* @param options.gcInterval GC interval in ms. Default: 1/10 of expireTime (minimum 1000ms)
|
|
174
|
-
* @param options.expireTime Expiration time in ms since last access
|
|
175
|
-
* @param options.onExpire Callback called on expiration (can be async)
|
|
176
|
-
*/
|
|
53
|
+
class LazyGcMap<TKey, TValue> {
|
|
177
54
|
constructor(options: {
|
|
178
55
|
gcInterval?: number;
|
|
179
56
|
expireTime: number;
|
|
@@ -185,103 +62,246 @@ export class LazyGcMap<TKey, TValue> {
|
|
|
185
62
|
get(key: TKey): TValue | undefined;
|
|
186
63
|
set(key: TKey, value: TValue): void;
|
|
187
64
|
delete(key: TKey): boolean;
|
|
188
|
-
clear(): void;
|
|
189
65
|
getOrCreate(key: TKey, factory: () => TValue): TValue;
|
|
66
|
+
clear(): void;
|
|
67
|
+
dispose(): void;
|
|
68
|
+
[Symbol.dispose](): void;
|
|
69
|
+
|
|
190
70
|
values(): IterableIterator<TValue>;
|
|
191
71
|
keys(): IterableIterator<TKey>;
|
|
192
72
|
entries(): IterableIterator<[TKey, TValue]>;
|
|
193
|
-
dispose(): void;
|
|
194
|
-
[Symbol.dispose](): void;
|
|
195
73
|
}
|
|
196
74
|
```
|
|
197
75
|
|
|
198
|
-
|
|
76
|
+
### Constructor Options
|
|
199
77
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
78
|
+
| Option | Type | Default | Description |
|
|
79
|
+
|--------|------|---------|-------------|
|
|
80
|
+
| `gcInterval` | `number` | `expireTime / 10` (min 1000ms) | Interval between GC runs (ms) |
|
|
81
|
+
| `expireTime` | `number` | required | Time since last access before entry is removed (ms) |
|
|
82
|
+
| `onExpire` | `(key, value) => void \| Promise<void>` | `undefined` | Callback when an entry expires |
|
|
205
83
|
|
|
206
|
-
|
|
84
|
+
### Methods
|
|
207
85
|
|
|
208
|
-
|
|
86
|
+
| Method | Description |
|
|
87
|
+
|--------|-------------|
|
|
88
|
+
| `has(key)` | Check if key exists (does NOT refresh access time) |
|
|
89
|
+
| `get(key)` | Get value and refresh access time (LRU) |
|
|
90
|
+
| `set(key, value)` | Set value and start GC timer if needed |
|
|
91
|
+
| `delete(key)` | Delete entry; stops GC if map becomes empty |
|
|
92
|
+
| `getOrCreate(key, factory)` | Get or create value. Throws if disposed |
|
|
93
|
+
| `clear()` | Remove all entries (instance remains usable) |
|
|
94
|
+
| `dispose()` | Stop GC timer and clear all data. Instance becomes unusable |
|
|
209
95
|
|
|
210
|
-
|
|
96
|
+
**Important:** Always call `dispose()` or use `using` to prevent memory leaks from the GC timer.
|
|
211
97
|
|
|
212
98
|
```typescript
|
|
213
|
-
|
|
214
|
-
|
|
99
|
+
using map = new LazyGcMap<string, Connection>({
|
|
100
|
+
expireTime: 60_000,
|
|
101
|
+
onExpire: async (_key, conn) => { await conn.close(); },
|
|
102
|
+
});
|
|
215
103
|
|
|
216
|
-
|
|
104
|
+
map.set("conn1", createConnection());
|
|
105
|
+
const conn = map.get("conn1"); // refreshes access time
|
|
106
|
+
```
|
|
217
107
|
|
|
218
|
-
## `
|
|
108
|
+
## `DateTime`
|
|
219
109
|
|
|
220
|
-
|
|
110
|
+
Immutable date-time class wrapping JavaScript `Date`. Millisecond precision, local timezone.
|
|
221
111
|
|
|
222
112
|
```typescript
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
113
|
+
class DateTime {
|
|
114
|
+
readonly date: Date;
|
|
115
|
+
|
|
116
|
+
constructor();
|
|
117
|
+
constructor(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number);
|
|
118
|
+
constructor(tick: number);
|
|
119
|
+
constructor(date: Date);
|
|
120
|
+
|
|
121
|
+
static parse(str: string): DateTime;
|
|
122
|
+
|
|
123
|
+
// Getters
|
|
124
|
+
get year(): number;
|
|
125
|
+
get month(): number; // 1-12
|
|
126
|
+
get day(): number;
|
|
127
|
+
get hour(): number;
|
|
128
|
+
get minute(): number;
|
|
129
|
+
get second(): number;
|
|
130
|
+
get millisecond(): number;
|
|
131
|
+
get tick(): number;
|
|
132
|
+
get dayOfWeek(): number; // 0(Sun)-6(Sat)
|
|
133
|
+
get timezoneOffsetMinutes(): number;
|
|
134
|
+
get isValid(): boolean;
|
|
135
|
+
|
|
136
|
+
// Immutable setters (return new instance)
|
|
137
|
+
setYear(year: number): DateTime;
|
|
138
|
+
setMonth(month: number): DateTime;
|
|
139
|
+
setDay(day: number): DateTime;
|
|
140
|
+
setHour(hour: number): DateTime;
|
|
141
|
+
setMinute(minute: number): DateTime;
|
|
142
|
+
setSecond(second: number): DateTime;
|
|
143
|
+
setMillisecond(millisecond: number): DateTime;
|
|
144
|
+
|
|
145
|
+
// Arithmetic (return new instance)
|
|
146
|
+
addYears(years: number): DateTime;
|
|
147
|
+
addMonths(months: number): DateTime;
|
|
148
|
+
addDays(days: number): DateTime;
|
|
149
|
+
addHours(hours: number): DateTime;
|
|
150
|
+
addMinutes(minutes: number): DateTime;
|
|
151
|
+
addSeconds(seconds: number): DateTime;
|
|
152
|
+
addMilliseconds(milliseconds: number): DateTime;
|
|
153
|
+
|
|
154
|
+
// Formatting
|
|
155
|
+
toFormatString(formatStr: string): string;
|
|
156
|
+
toString(): string; // "yyyy-MM-ddTHH:mm:ss.fffzzz"
|
|
157
|
+
}
|
|
233
158
|
```
|
|
234
159
|
|
|
235
|
-
|
|
160
|
+
### `DateTime.parse` Supported Formats
|
|
236
161
|
|
|
237
|
-
|
|
162
|
+
| Format | Example |
|
|
163
|
+
|--------|---------|
|
|
164
|
+
| `yyyy-MM-dd HH:mm:ss` | `"2025-01-15 10:30:00"` |
|
|
165
|
+
| `yyyy-MM-dd HH:mm:ss.fff` | `"2025-01-15 10:30:00.123"` |
|
|
166
|
+
| `yyyyMMddHHmmss` | `"20250115103000"` |
|
|
167
|
+
| `yyyy-MM-dd AM/PM HH:mm:ss` | `"2025-01-15 AM 10:30:00"` |
|
|
168
|
+
| ISO 8601 | `"2025-01-15T10:30:00Z"` |
|
|
169
|
+
| Korean AM/PM | `"2025-01-15 오전 10:30:00"` |
|
|
238
170
|
|
|
239
171
|
```typescript
|
|
240
|
-
|
|
172
|
+
const now = new DateTime();
|
|
173
|
+
const d = new DateTime(2025, 1, 15, 10, 30, 0);
|
|
174
|
+
const parsed = DateTime.parse("2025-01-15 10:30:00");
|
|
175
|
+
const next = d.addDays(7).setHour(14);
|
|
176
|
+
d.toFormatString("yyyy-MM-dd HH:mm"); // "2025-01-15 10:30"
|
|
241
177
|
```
|
|
242
178
|
|
|
243
|
-
|
|
179
|
+
## `DateOnly`
|
|
244
180
|
|
|
245
|
-
|
|
181
|
+
Immutable date class (no time component). Local timezone.
|
|
246
182
|
|
|
247
183
|
```typescript
|
|
248
|
-
|
|
184
|
+
class DateOnly {
|
|
185
|
+
readonly date: Date;
|
|
186
|
+
|
|
187
|
+
constructor();
|
|
188
|
+
constructor(year: number, month: number, day: number);
|
|
189
|
+
constructor(tick: number);
|
|
190
|
+
constructor(date: Date);
|
|
191
|
+
|
|
192
|
+
static parse(str: string): DateOnly;
|
|
193
|
+
static getDateByYearWeekSeq(
|
|
194
|
+
arg: { year: number; month?: number; weekSeq: number },
|
|
195
|
+
weekStartDay?: number,
|
|
196
|
+
minDaysInFirstWeek?: number,
|
|
197
|
+
): DateOnly;
|
|
198
|
+
|
|
199
|
+
// Getters
|
|
200
|
+
get year(): number;
|
|
201
|
+
get month(): number; // 1-12
|
|
202
|
+
get day(): number;
|
|
203
|
+
get tick(): number;
|
|
204
|
+
get dayOfWeek(): number; // 0(Sun)-6(Sat)
|
|
205
|
+
get isValid(): boolean;
|
|
206
|
+
|
|
207
|
+
// Immutable setters
|
|
208
|
+
setYear(year: number): DateOnly;
|
|
209
|
+
setMonth(month: number): DateOnly;
|
|
210
|
+
setDay(day: number): DateOnly;
|
|
211
|
+
|
|
212
|
+
// Arithmetic
|
|
213
|
+
addYears(years: number): DateOnly;
|
|
214
|
+
addMonths(months: number): DateOnly;
|
|
215
|
+
addDays(days: number): DateOnly;
|
|
216
|
+
|
|
217
|
+
// Week calculations
|
|
218
|
+
getBaseYearMonthSeqForWeekSeq(weekStartDay?: number, minDaysInFirstWeek?: number): { year: number; monthSeq: number };
|
|
219
|
+
getWeekSeqStartDate(weekStartDay?: number, minDaysInFirstWeek?: number): DateOnly;
|
|
220
|
+
getWeekSeqOfYear(weekStartDay?: number, minDaysInFirstWeek?: number): { year: number; weekSeq: number };
|
|
221
|
+
getWeekSeqOfMonth(weekStartDay?: number, minDaysInFirstWeek?: number): { year: number; monthSeq: number; weekSeq: number };
|
|
222
|
+
|
|
223
|
+
// Formatting
|
|
224
|
+
toFormatString(formatStr: string): string;
|
|
225
|
+
toString(): string; // "yyyy-MM-dd"
|
|
226
|
+
}
|
|
249
227
|
```
|
|
250
228
|
|
|
251
|
-
|
|
229
|
+
### `DateOnly.parse` Supported Formats
|
|
230
|
+
|
|
231
|
+
| Format | Example |
|
|
232
|
+
|--------|---------|
|
|
233
|
+
| `yyyy-MM-dd` | `"2025-01-15"` (timezone-safe) |
|
|
234
|
+
| `yyyyMMdd` | `"20250115"` (timezone-safe) |
|
|
235
|
+
| ISO 8601 | `"2025-01-15T00:00:00Z"` (converted to local) |
|
|
252
236
|
|
|
253
|
-
|
|
237
|
+
### Week Calculation Parameters
|
|
254
238
|
|
|
255
|
-
|
|
239
|
+
| Parameter | Default | Description |
|
|
240
|
+
|-----------|---------|-------------|
|
|
241
|
+
| `weekStartDay` | `1` (Monday) | Week start day: 0=Sun, 1=Mon, ..., 6=Sat |
|
|
242
|
+
| `minDaysInFirstWeek` | `4` (ISO 8601) | Minimum days in the first week |
|
|
256
243
|
|
|
257
244
|
```typescript
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
245
|
+
const today = new DateOnly();
|
|
246
|
+
const d = new DateOnly(2025, 1, 15);
|
|
247
|
+
const parsed = DateOnly.parse("2025-01-15");
|
|
248
|
+
d.getWeekSeqOfYear(); // { year: 2025, weekSeq: 3 }
|
|
249
|
+
d.getWeekSeqOfMonth(); // { year: 2025, monthSeq: 1, weekSeq: 3 }
|
|
250
|
+
DateOnly.getDateByYearWeekSeq({ year: 2025, weekSeq: 2 }); // 2025-01-06
|
|
261
251
|
```
|
|
262
252
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
## `Type<T>`
|
|
253
|
+
## `Time`
|
|
266
254
|
|
|
267
|
-
|
|
255
|
+
Immutable time class (no date component). Values automatically wrap within 24 hours.
|
|
268
256
|
|
|
269
257
|
```typescript
|
|
270
|
-
|
|
271
|
-
|
|
258
|
+
class Time {
|
|
259
|
+
constructor();
|
|
260
|
+
constructor(hour: number, minute: number, second?: number, millisecond?: number);
|
|
261
|
+
constructor(tick: number);
|
|
262
|
+
constructor(date: Date);
|
|
263
|
+
|
|
264
|
+
static parse(str: string): Time;
|
|
265
|
+
|
|
266
|
+
// Getters
|
|
267
|
+
get hour(): number;
|
|
268
|
+
get minute(): number;
|
|
269
|
+
get second(): number;
|
|
270
|
+
get millisecond(): number;
|
|
271
|
+
get tick(): number;
|
|
272
|
+
get isValid(): boolean;
|
|
273
|
+
|
|
274
|
+
// Immutable setters
|
|
275
|
+
setHour(hour: number): Time;
|
|
276
|
+
setMinute(minute: number): Time;
|
|
277
|
+
setSecond(second: number): Time;
|
|
278
|
+
setMillisecond(millisecond: number): Time;
|
|
279
|
+
|
|
280
|
+
// Arithmetic (wraps at 24h)
|
|
281
|
+
addHours(hours: number): Time;
|
|
282
|
+
addMinutes(minutes: number): Time;
|
|
283
|
+
addSeconds(seconds: number): Time;
|
|
284
|
+
addMilliseconds(milliseconds: number): Time;
|
|
285
|
+
|
|
286
|
+
// Formatting
|
|
287
|
+
toFormatString(formatStr: string): string;
|
|
288
|
+
toString(): string; // "HH:mm:ss.fff"
|
|
272
289
|
}
|
|
273
290
|
```
|
|
274
291
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
## `env`
|
|
292
|
+
### `Time.parse` Supported Formats
|
|
278
293
|
|
|
279
|
-
|
|
294
|
+
| Format | Example |
|
|
295
|
+
|--------|---------|
|
|
296
|
+
| `HH:mm:ss` | `"10:30:00"` |
|
|
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"` |
|
|
280
300
|
|
|
281
301
|
```typescript
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
302
|
+
const now = new Time();
|
|
303
|
+
const t = new Time(14, 30, 0);
|
|
304
|
+
const parsed = Time.parse("10:30:00");
|
|
305
|
+
t.addHours(12); // wraps: 02:30:00
|
|
306
|
+
t.toFormatString("tt h:mm:ss"); // "PM 2:30:00"
|
|
287
307
|
```
|