@craftguild/jscalendar 0.5.3 → 0.5.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 +128 -92
- package/dist/index.cjs +3923 -0
- package/dist/index.d.cts +802 -0
- package/dist/index.d.mts +802 -0
- package/dist/index.mjs +3927 -0
- package/package.json +46 -31
- package/dist/__tests__/builders.test.d.ts +0 -1
- package/dist/__tests__/builders.test.js +0 -101
- package/dist/__tests__/calendar-extra.test.d.ts +0 -1
- package/dist/__tests__/calendar-extra.test.js +0 -221
- package/dist/__tests__/calendar.test.d.ts +0 -1
- package/dist/__tests__/calendar.test.js +0 -97
- package/dist/__tests__/ical-extra.test.d.ts +0 -1
- package/dist/__tests__/ical-extra.test.js +0 -87
- package/dist/__tests__/ical.test.d.ts +0 -1
- package/dist/__tests__/ical.test.js +0 -72
- package/dist/__tests__/index.test.d.ts +0 -1
- package/dist/__tests__/index.test.js +0 -9
- package/dist/__tests__/patch.test.d.ts +0 -1
- package/dist/__tests__/patch.test.js +0 -47
- package/dist/__tests__/recurrence.test.d.ts +0 -1
- package/dist/__tests__/recurrence.test.js +0 -640
- package/dist/__tests__/search.test.d.ts +0 -1
- package/dist/__tests__/search.test.js +0 -264
- package/dist/__tests__/timezones.test.d.ts +0 -1
- package/dist/__tests__/timezones.test.js +0 -12
- package/dist/__tests__/utils.test.d.ts +0 -1
- package/dist/__tests__/utils.test.js +0 -127
- package/dist/__tests__/validation.test.d.ts +0 -1
- package/dist/__tests__/validation.test.js +0 -224
- package/dist/ical.d.ts +0 -13
- package/dist/ical.js +0 -270
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -2
- package/dist/jscal/base.d.ts +0 -89
- package/dist/jscal/base.js +0 -173
- package/dist/jscal/builders.d.ts +0 -183
- package/dist/jscal/builders.js +0 -287
- package/dist/jscal/constants.d.ts +0 -11
- package/dist/jscal/constants.js +0 -11
- package/dist/jscal/datetime.d.ts +0 -14
- package/dist/jscal/datetime.js +0 -42
- package/dist/jscal/defaults.d.ts +0 -31
- package/dist/jscal/defaults.js +0 -102
- package/dist/jscal/duration.d.ts +0 -43
- package/dist/jscal/duration.js +0 -75
- package/dist/jscal/event.d.ts +0 -23
- package/dist/jscal/event.js +0 -78
- package/dist/jscal/group.d.ts +0 -31
- package/dist/jscal/group.js +0 -69
- package/dist/jscal/guards.d.ts +0 -19
- package/dist/jscal/guards.js +0 -25
- package/dist/jscal/ids.d.ts +0 -11
- package/dist/jscal/ids.js +0 -77
- package/dist/jscal/normalize.d.ts +0 -32
- package/dist/jscal/normalize.js +0 -45
- package/dist/jscal/task.d.ts +0 -23
- package/dist/jscal/task.js +0 -67
- package/dist/jscal/types.d.ts +0 -38
- package/dist/jscal/types.js +0 -1
- package/dist/jscal.d.ts +0 -145
- package/dist/jscal.js +0 -126
- package/dist/patch.d.ts +0 -18
- package/dist/patch.js +0 -216
- package/dist/recurrence/constants.d.ts +0 -13
- package/dist/recurrence/constants.js +0 -13
- package/dist/recurrence/date-utils.d.ts +0 -125
- package/dist/recurrence/date-utils.js +0 -259
- package/dist/recurrence/expand.d.ts +0 -23
- package/dist/recurrence/expand.js +0 -315
- package/dist/recurrence/rule-candidates.d.ts +0 -21
- package/dist/recurrence/rule-candidates.js +0 -120
- package/dist/recurrence/rule-generate.d.ts +0 -11
- package/dist/recurrence/rule-generate.js +0 -36
- package/dist/recurrence/rule-matchers.d.ts +0 -34
- package/dist/recurrence/rule-matchers.js +0 -120
- package/dist/recurrence/rule-normalize.d.ts +0 -9
- package/dist/recurrence/rule-normalize.js +0 -57
- package/dist/recurrence/rule-selectors.d.ts +0 -7
- package/dist/recurrence/rule-selectors.js +0 -21
- package/dist/recurrence/rules.d.ts +0 -14
- package/dist/recurrence/rules.js +0 -57
- package/dist/recurrence/types.d.ts +0 -27
- package/dist/recurrence/types.js +0 -1
- package/dist/recurrence.d.ts +0 -2
- package/dist/recurrence.js +0 -1
- package/dist/search.d.ts +0 -44
- package/dist/search.js +0 -292
- package/dist/timezones/chunk_1.d.ts +0 -2
- package/dist/timezones/chunk_1.js +0 -72
- package/dist/timezones/chunk_2.d.ts +0 -2
- package/dist/timezones/chunk_2.js +0 -72
- package/dist/timezones/chunk_3.d.ts +0 -2
- package/dist/timezones/chunk_3.js +0 -72
- package/dist/timezones/chunk_4.d.ts +0 -2
- package/dist/timezones/chunk_4.js +0 -72
- package/dist/timezones/chunk_5.d.ts +0 -2
- package/dist/timezones/chunk_5.js +0 -72
- package/dist/timezones/chunk_6.d.ts +0 -2
- package/dist/timezones/chunk_6.js +0 -72
- package/dist/timezones/chunk_7.d.ts +0 -2
- package/dist/timezones/chunk_7.js +0 -6
- package/dist/timezones.d.ts +0 -9
- package/dist/timezones.js +0 -452
- package/dist/types.d.ts +0 -246
- package/dist/types.js +0 -1
- package/dist/utils.d.ts +0 -82
- package/dist/utils.js +0 -164
- package/dist/validate/asserts.d.ts +0 -155
- package/dist/validate/asserts.js +0 -381
- package/dist/validate/constants.d.ts +0 -25
- package/dist/validate/constants.js +0 -33
- package/dist/validate/error.d.ts +0 -19
- package/dist/validate/error.js +0 -25
- package/dist/validate/validators-common.d.ts +0 -64
- package/dist/validate/validators-common.js +0 -390
- package/dist/validate/validators-objects.d.ts +0 -8
- package/dist/validate/validators-objects.js +0 -70
- package/dist/validate/validators-recurrence.d.ts +0 -15
- package/dist/validate/validators-recurrence.js +0 -115
- package/dist/validate/validators.d.ts +0 -1
- package/dist/validate/validators.js +0 -1
- package/dist/validate.d.ts +0 -2
- package/dist/validate.js +0 -2
package/dist/types.d.ts
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import type { TimeZoneId } from "./timezones.js";
|
|
2
|
-
export { TimeZoneId, TimeZoneInput } from "./timezones.js";
|
|
3
|
-
export type Id = string;
|
|
4
|
-
export type Int = number;
|
|
5
|
-
export type UnsignedInt = number;
|
|
6
|
-
export type UTCDateTime = string;
|
|
7
|
-
export type LocalDateTime = string;
|
|
8
|
-
export type Duration = string;
|
|
9
|
-
export type SignedDuration = string;
|
|
10
|
-
export type BooleanMap = Record<string, true>;
|
|
11
|
-
export type JsonPrimitive = string | number | boolean | null;
|
|
12
|
-
export type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
13
|
-
[key: string]: JsonValue;
|
|
14
|
-
};
|
|
15
|
-
export type PatchValue = JsonValue | null;
|
|
16
|
-
export interface PatchObject {
|
|
17
|
-
[key: string]: PatchValue;
|
|
18
|
-
}
|
|
19
|
-
type PatchFields<T> = {
|
|
20
|
-
[K in keyof Omit<T, "@type">]?: T[K] | null;
|
|
21
|
-
};
|
|
22
|
-
type PatchTag<TTag extends string> = {
|
|
23
|
-
__patchType?: TTag;
|
|
24
|
-
};
|
|
25
|
-
export type EventPatch = PatchFields<Event> & PatchTag<"Event">;
|
|
26
|
-
export type TaskPatch = PatchFields<Task> & PatchTag<"Task">;
|
|
27
|
-
export type GroupPatch = PatchFields<Group> & PatchTag<"Group">;
|
|
28
|
-
export type ParticipantPatch = PatchFields<Participant>;
|
|
29
|
-
export type LocationPatch = PatchFields<Location>;
|
|
30
|
-
export type VirtualLocationPatch = PatchFields<VirtualLocation>;
|
|
31
|
-
export type AlertPatch = PatchFields<Alert>;
|
|
32
|
-
export type RelationPatch = PatchFields<Relation>;
|
|
33
|
-
export type LinkPatch = PatchFields<Link>;
|
|
34
|
-
export type TimeZonePatch = PatchFields<TimeZone>;
|
|
35
|
-
export type TimeZoneRulePatch = PatchFields<TimeZoneRule>;
|
|
36
|
-
export type RecurrenceRulePatch = PatchFields<RecurrenceRule>;
|
|
37
|
-
export type NDayPatch = PatchFields<NDay>;
|
|
38
|
-
export type PatchLike = PatchObject | EventPatch | TaskPatch | GroupPatch | TimeZoneRulePatch;
|
|
39
|
-
export interface Relation {
|
|
40
|
-
"@type": "Relation";
|
|
41
|
-
relation?: BooleanMap;
|
|
42
|
-
}
|
|
43
|
-
export interface Link {
|
|
44
|
-
"@type": "Link";
|
|
45
|
-
href: string;
|
|
46
|
-
cid?: string;
|
|
47
|
-
contentType?: string;
|
|
48
|
-
size?: UnsignedInt;
|
|
49
|
-
rel?: string;
|
|
50
|
-
display?: string;
|
|
51
|
-
title?: string;
|
|
52
|
-
}
|
|
53
|
-
export interface Location {
|
|
54
|
-
"@type": "Location";
|
|
55
|
-
name?: string;
|
|
56
|
-
description?: string;
|
|
57
|
-
locationTypes?: BooleanMap;
|
|
58
|
-
relativeTo?: string;
|
|
59
|
-
timeZone?: TimeZoneId;
|
|
60
|
-
coordinates?: string;
|
|
61
|
-
links?: Record<Id, Link>;
|
|
62
|
-
}
|
|
63
|
-
export interface VirtualLocation {
|
|
64
|
-
"@type": "VirtualLocation";
|
|
65
|
-
name?: string;
|
|
66
|
-
description?: string;
|
|
67
|
-
uri: string;
|
|
68
|
-
features?: BooleanMap;
|
|
69
|
-
}
|
|
70
|
-
export interface Participant {
|
|
71
|
-
"@type": "Participant";
|
|
72
|
-
name?: string;
|
|
73
|
-
email?: string;
|
|
74
|
-
description?: string;
|
|
75
|
-
sendTo?: Record<string, string>;
|
|
76
|
-
kind?: string;
|
|
77
|
-
roles: BooleanMap;
|
|
78
|
-
locationId?: Id;
|
|
79
|
-
language?: string;
|
|
80
|
-
participationStatus?: string;
|
|
81
|
-
participationComment?: string;
|
|
82
|
-
expectReply?: boolean;
|
|
83
|
-
scheduleAgent?: string;
|
|
84
|
-
scheduleForceSend?: boolean;
|
|
85
|
-
scheduleSequence?: UnsignedInt;
|
|
86
|
-
scheduleStatus?: string[];
|
|
87
|
-
scheduleUpdated?: UTCDateTime;
|
|
88
|
-
sentBy?: string;
|
|
89
|
-
invitedBy?: Id;
|
|
90
|
-
delegatedTo?: Record<Id, true>;
|
|
91
|
-
delegatedFrom?: Record<Id, true>;
|
|
92
|
-
memberOf?: Record<Id, true>;
|
|
93
|
-
links?: Record<Id, Link>;
|
|
94
|
-
progress?: string;
|
|
95
|
-
progressUpdated?: UTCDateTime;
|
|
96
|
-
percentComplete?: UnsignedInt;
|
|
97
|
-
}
|
|
98
|
-
export interface OffsetTrigger {
|
|
99
|
-
"@type": "OffsetTrigger";
|
|
100
|
-
offset: SignedDuration;
|
|
101
|
-
relativeTo?: "start" | "end" | string;
|
|
102
|
-
}
|
|
103
|
-
export interface AbsoluteTrigger {
|
|
104
|
-
"@type": "AbsoluteTrigger";
|
|
105
|
-
when: UTCDateTime;
|
|
106
|
-
}
|
|
107
|
-
export interface UnknownTrigger {
|
|
108
|
-
"@type": string;
|
|
109
|
-
[key: string]: JsonValue;
|
|
110
|
-
}
|
|
111
|
-
export type Trigger = OffsetTrigger | AbsoluteTrigger | UnknownTrigger;
|
|
112
|
-
export interface Alert {
|
|
113
|
-
"@type": "Alert";
|
|
114
|
-
trigger: Trigger;
|
|
115
|
-
acknowledged?: UTCDateTime;
|
|
116
|
-
relatedTo?: Record<string, Relation>;
|
|
117
|
-
action?: string;
|
|
118
|
-
}
|
|
119
|
-
export type DayOfWeek = "mo" | "tu" | "we" | "th" | "fr" | "sa" | "su";
|
|
120
|
-
export interface NDay {
|
|
121
|
-
"@type": "NDay";
|
|
122
|
-
day: DayOfWeek;
|
|
123
|
-
nthOfPeriod?: Int;
|
|
124
|
-
}
|
|
125
|
-
export interface RecurrenceRule {
|
|
126
|
-
"@type": "RecurrenceRule";
|
|
127
|
-
frequency: "yearly" | "monthly" | "weekly" | "daily" | "hourly" | "minutely" | "secondly";
|
|
128
|
-
interval?: UnsignedInt;
|
|
129
|
-
rscale?: string;
|
|
130
|
-
skip?: "omit" | "backward" | "forward";
|
|
131
|
-
firstDayOfWeek?: DayOfWeek;
|
|
132
|
-
byDay?: NDay[];
|
|
133
|
-
byMonthDay?: Int[];
|
|
134
|
-
byMonth?: string[];
|
|
135
|
-
byYearDay?: Int[];
|
|
136
|
-
byWeekNo?: Int[];
|
|
137
|
-
byHour?: UnsignedInt[];
|
|
138
|
-
byMinute?: UnsignedInt[];
|
|
139
|
-
bySecond?: UnsignedInt[];
|
|
140
|
-
bySetPosition?: Int[];
|
|
141
|
-
count?: UnsignedInt;
|
|
142
|
-
until?: LocalDateTime;
|
|
143
|
-
}
|
|
144
|
-
export interface TimeZoneRule {
|
|
145
|
-
"@type": "TimeZoneRule";
|
|
146
|
-
start: LocalDateTime;
|
|
147
|
-
offsetFrom: string;
|
|
148
|
-
offsetTo: string;
|
|
149
|
-
recurrenceRules?: RecurrenceRule[];
|
|
150
|
-
recurrenceOverrides?: Record<LocalDateTime, TimeZoneRulePatch>;
|
|
151
|
-
names?: BooleanMap;
|
|
152
|
-
comments?: string[];
|
|
153
|
-
}
|
|
154
|
-
export interface TimeZone {
|
|
155
|
-
"@type": "TimeZone";
|
|
156
|
-
tzId: string;
|
|
157
|
-
updated?: UTCDateTime;
|
|
158
|
-
url?: string;
|
|
159
|
-
validUntil?: UTCDateTime;
|
|
160
|
-
aliases?: BooleanMap;
|
|
161
|
-
standard?: TimeZoneRule[];
|
|
162
|
-
daylight?: TimeZoneRule[];
|
|
163
|
-
}
|
|
164
|
-
export interface JSCalendarCommon {
|
|
165
|
-
"@type": string;
|
|
166
|
-
uid: string;
|
|
167
|
-
relatedTo?: Record<string, Relation>;
|
|
168
|
-
prodId?: string;
|
|
169
|
-
created?: UTCDateTime;
|
|
170
|
-
updated: UTCDateTime;
|
|
171
|
-
sequence?: UnsignedInt;
|
|
172
|
-
method?: string;
|
|
173
|
-
title?: string;
|
|
174
|
-
description?: string;
|
|
175
|
-
descriptionContentType?: string;
|
|
176
|
-
showWithoutTime?: boolean;
|
|
177
|
-
locations?: Record<Id, Location>;
|
|
178
|
-
virtualLocations?: Record<Id, VirtualLocation>;
|
|
179
|
-
links?: Record<Id, Link>;
|
|
180
|
-
locale?: string;
|
|
181
|
-
keywords?: BooleanMap;
|
|
182
|
-
categories?: BooleanMap;
|
|
183
|
-
color?: string;
|
|
184
|
-
recurrenceId?: LocalDateTime;
|
|
185
|
-
recurrenceIdTimeZone?: TimeZoneId | null;
|
|
186
|
-
recurrenceRules?: RecurrenceRule[];
|
|
187
|
-
excludedRecurrenceRules?: RecurrenceRule[];
|
|
188
|
-
excluded?: boolean;
|
|
189
|
-
priority?: Int;
|
|
190
|
-
freeBusyStatus?: string;
|
|
191
|
-
privacy?: string;
|
|
192
|
-
replyTo?: Record<string, string>;
|
|
193
|
-
sentBy?: string;
|
|
194
|
-
participants?: Record<Id, Participant>;
|
|
195
|
-
requestStatus?: string;
|
|
196
|
-
useDefaultAlerts?: boolean;
|
|
197
|
-
alerts?: Record<Id, Alert>;
|
|
198
|
-
timeZone?: TimeZoneId | null;
|
|
199
|
-
timeZones?: Partial<Record<TimeZoneId, TimeZone>>;
|
|
200
|
-
}
|
|
201
|
-
export interface Event extends JSCalendarCommon {
|
|
202
|
-
"@type": "Event";
|
|
203
|
-
start: LocalDateTime;
|
|
204
|
-
duration?: Duration;
|
|
205
|
-
status?: string;
|
|
206
|
-
localizations?: Record<string, EventPatch>;
|
|
207
|
-
recurrenceOverrides?: Record<LocalDateTime, EventPatch>;
|
|
208
|
-
}
|
|
209
|
-
export interface Task extends JSCalendarCommon {
|
|
210
|
-
"@type": "Task";
|
|
211
|
-
due?: LocalDateTime;
|
|
212
|
-
start?: LocalDateTime;
|
|
213
|
-
estimatedDuration?: Duration;
|
|
214
|
-
percentComplete?: UnsignedInt;
|
|
215
|
-
progress?: string;
|
|
216
|
-
progressUpdated?: UTCDateTime;
|
|
217
|
-
localizations?: Record<string, TaskPatch>;
|
|
218
|
-
recurrenceOverrides?: Record<LocalDateTime, TaskPatch>;
|
|
219
|
-
}
|
|
220
|
-
export interface Group extends JSCalendarCommon {
|
|
221
|
-
"@type": "Group";
|
|
222
|
-
entries: Array<Event | Task>;
|
|
223
|
-
source?: string;
|
|
224
|
-
localizations?: Record<string, GroupPatch>;
|
|
225
|
-
recurrenceOverrides?: Record<LocalDateTime, GroupPatch>;
|
|
226
|
-
}
|
|
227
|
-
export type JSCalendarObject = Event | Task | Group;
|
|
228
|
-
export type CalendarType = JSCalendarObject["@type"];
|
|
229
|
-
export type CreateInput<TType extends CalendarType> = TType extends "Event" ? Omit<Event, "@type" | "uid" | "updated"> & {
|
|
230
|
-
type?: "Event" | "event";
|
|
231
|
-
"@type"?: "Event";
|
|
232
|
-
uid?: string;
|
|
233
|
-
updated?: UTCDateTime;
|
|
234
|
-
} : TType extends "Task" ? Omit<Task, "@type" | "uid" | "updated"> & {
|
|
235
|
-
type?: "Task" | "task";
|
|
236
|
-
"@type"?: "Task";
|
|
237
|
-
uid?: string;
|
|
238
|
-
updated?: UTCDateTime;
|
|
239
|
-
} : Omit<Group, "@type" | "uid" | "updated"> & {
|
|
240
|
-
type?: "Group" | "group";
|
|
241
|
-
"@type"?: "Group";
|
|
242
|
-
uid?: string;
|
|
243
|
-
updated?: UTCDateTime;
|
|
244
|
-
};
|
|
245
|
-
export type AnyCreateInput = CreateInput<"Event"> | CreateInput<"Task"> | CreateInput<"Group">;
|
|
246
|
-
export type CalendarLike = JSCalendarObject | PatchObject | JsonValue;
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils.d.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { Duration, UTCDateTime } from "./types.js";
|
|
2
|
-
export type PrimitiveLike = string | number | boolean | object | null | undefined;
|
|
3
|
-
/**
|
|
4
|
-
* Check whether a value is a string.
|
|
5
|
-
* @param value Value to check.
|
|
6
|
-
* @return True if the value is a string.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isStringValue(value: PrimitiveLike): value is string;
|
|
9
|
-
/**
|
|
10
|
-
* Check whether a value is a number.
|
|
11
|
-
* @param value Value to check.
|
|
12
|
-
* @return True if the value is a number.
|
|
13
|
-
*/
|
|
14
|
-
export declare function isNumberValue(value: PrimitiveLike): value is number;
|
|
15
|
-
/**
|
|
16
|
-
* Check whether a value is a boolean.
|
|
17
|
-
* @param value Value to check.
|
|
18
|
-
* @return True if the value is a boolean.
|
|
19
|
-
*/
|
|
20
|
-
export declare function isBooleanValue(value: PrimitiveLike): value is boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Check whether a value is a non-null object.
|
|
23
|
-
* @param value Value to check.
|
|
24
|
-
* @return True if the value is a non-null object.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isObjectValue(value: PrimitiveLike): value is object;
|
|
27
|
-
/**
|
|
28
|
-
* Get the current UTC date-time string.
|
|
29
|
-
* @return Current time as UTCDateTime.
|
|
30
|
-
*/
|
|
31
|
-
export declare function nowUtc(): UTCDateTime;
|
|
32
|
-
/**
|
|
33
|
-
* Deep-clone a value using structuredClone.
|
|
34
|
-
* @param value Value to clone.
|
|
35
|
-
* @return Deep clone of the input value.
|
|
36
|
-
*/
|
|
37
|
-
export declare function deepClone<T>(value: T): T;
|
|
38
|
-
/**
|
|
39
|
-
* Check if a string is a UTCDateTime with Z suffix.
|
|
40
|
-
* @param value Date-time string.
|
|
41
|
-
* @return True if the value ends with Z.
|
|
42
|
-
*/
|
|
43
|
-
export declare function isUtcDateTime(value: string): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Compare two date-time strings, returning null when incomparable.
|
|
46
|
-
* @param a Date-time string A.
|
|
47
|
-
* @param b Date-time string B.
|
|
48
|
-
* @return -1, 0, 1, or null when formats are incompatible.
|
|
49
|
-
*/
|
|
50
|
-
export declare function compareDateTime(a: string, b: string): number | null;
|
|
51
|
-
/**
|
|
52
|
-
* Convert a duration string to milliseconds.
|
|
53
|
-
* @param duration Duration string.
|
|
54
|
-
* @return Milliseconds or null when invalid.
|
|
55
|
-
*/
|
|
56
|
-
export declare function durationToMilliseconds(duration: Duration): number | null;
|
|
57
|
-
/**
|
|
58
|
-
* Normalize a UTCDateTime by trimming trailing fractional zeros.
|
|
59
|
-
* @param value UTCDateTime string.
|
|
60
|
-
* @return Normalized UTCDateTime string.
|
|
61
|
-
*/
|
|
62
|
-
export declare function normalizeUtcDateTime(value: string): UTCDateTime;
|
|
63
|
-
/**
|
|
64
|
-
* Format a Date as LocalDateTime string.
|
|
65
|
-
* @param value Date to format.
|
|
66
|
-
* @return LocalDateTime string.
|
|
67
|
-
*/
|
|
68
|
-
export declare function localDateTimeFromDate(value: Date): string;
|
|
69
|
-
/**
|
|
70
|
-
* Format a Date as a LocalDateTime in a target time zone.
|
|
71
|
-
* @param value Date to format.
|
|
72
|
-
* @param timeZone IANA time zone.
|
|
73
|
-
* @return LocalDateTime string in the time zone.
|
|
74
|
-
*/
|
|
75
|
-
export declare function dateTimeInTimeZone(value: Date, timeZone: string): string;
|
|
76
|
-
/**
|
|
77
|
-
* Convert LocalDateTime string to a UTC Date using a time zone.
|
|
78
|
-
* @param value LocalDateTime string.
|
|
79
|
-
* @param timeZone IANA time zone.
|
|
80
|
-
* @return Date in UTC.
|
|
81
|
-
*/
|
|
82
|
-
export declare function localDateTimeToUtcDate(value: string, timeZone: string): Date;
|
package/dist/utils.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { format } from "date-fns";
|
|
2
|
-
import { formatInTimeZone, fromZonedTime } from "date-fns-tz";
|
|
3
|
-
const TYPEOF_FUNCTION = "function";
|
|
4
|
-
const TYPEOF_STRING = "string";
|
|
5
|
-
const TYPEOF_NUMBER = "number";
|
|
6
|
-
const TYPEOF_BOOLEAN = "boolean";
|
|
7
|
-
const TYPEOF_OBJECT = "object";
|
|
8
|
-
/**
|
|
9
|
-
* Check whether a value is a string.
|
|
10
|
-
* @param value Value to check.
|
|
11
|
-
* @return True if the value is a string.
|
|
12
|
-
*/
|
|
13
|
-
export function isStringValue(value) {
|
|
14
|
-
return typeof value === TYPEOF_STRING;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Check whether a value is a number.
|
|
18
|
-
* @param value Value to check.
|
|
19
|
-
* @return True if the value is a number.
|
|
20
|
-
*/
|
|
21
|
-
export function isNumberValue(value) {
|
|
22
|
-
return typeof value === TYPEOF_NUMBER;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Check whether a value is a boolean.
|
|
26
|
-
* @param value Value to check.
|
|
27
|
-
* @return True if the value is a boolean.
|
|
28
|
-
*/
|
|
29
|
-
export function isBooleanValue(value) {
|
|
30
|
-
return typeof value === TYPEOF_BOOLEAN;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Check whether a value is a non-null object.
|
|
34
|
-
* @param value Value to check.
|
|
35
|
-
* @return True if the value is a non-null object.
|
|
36
|
-
*/
|
|
37
|
-
export function isObjectValue(value) {
|
|
38
|
-
return value !== null && typeof value === TYPEOF_OBJECT;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Get the current UTC date-time string.
|
|
42
|
-
* @return Current time as UTCDateTime.
|
|
43
|
-
*/
|
|
44
|
-
export function nowUtc() {
|
|
45
|
-
return normalizeUtcDateTime(new Date().toISOString());
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Deep-clone a value using structuredClone.
|
|
49
|
-
* @param value Value to clone.
|
|
50
|
-
* @return Deep clone of the input value.
|
|
51
|
-
*/
|
|
52
|
-
export function deepClone(value) {
|
|
53
|
-
if (typeof structuredClone === TYPEOF_FUNCTION) {
|
|
54
|
-
return structuredClone(value);
|
|
55
|
-
}
|
|
56
|
-
throw new Error("structuredClone is not available in this environment");
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Check if a string is a UTCDateTime with Z suffix.
|
|
60
|
-
* @param value Date-time string.
|
|
61
|
-
* @return True if the value ends with Z.
|
|
62
|
-
*/
|
|
63
|
-
export function isUtcDateTime(value) {
|
|
64
|
-
return /Z$/.test(value);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Compare two date-time strings, returning null when incomparable.
|
|
68
|
-
* @param a Date-time string A.
|
|
69
|
-
* @param b Date-time string B.
|
|
70
|
-
* @return -1, 0, 1, or null when formats are incompatible.
|
|
71
|
-
*/
|
|
72
|
-
export function compareDateTime(a, b) {
|
|
73
|
-
const aUtc = isUtcDateTime(a);
|
|
74
|
-
const bUtc = isUtcDateTime(b);
|
|
75
|
-
if (aUtc && bUtc) {
|
|
76
|
-
const aMs = Date.parse(a);
|
|
77
|
-
const bMs = Date.parse(b);
|
|
78
|
-
if (Number.isNaN(aMs) || Number.isNaN(bMs))
|
|
79
|
-
return null;
|
|
80
|
-
return aMs === bMs ? 0 : aMs < bMs ? -1 : 1;
|
|
81
|
-
}
|
|
82
|
-
if (!aUtc && !bUtc) {
|
|
83
|
-
if (a === b)
|
|
84
|
-
return 0;
|
|
85
|
-
return a < b ? -1 : 1;
|
|
86
|
-
}
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Convert a duration string to milliseconds.
|
|
91
|
-
* @param duration Duration string.
|
|
92
|
-
* @return Milliseconds or null when invalid.
|
|
93
|
-
*/
|
|
94
|
-
export function durationToMilliseconds(duration) {
|
|
95
|
-
const re = /^P(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/;
|
|
96
|
-
const match = re.exec(duration);
|
|
97
|
-
if (!match)
|
|
98
|
-
return null;
|
|
99
|
-
const weeks = Number(match[1] || 0);
|
|
100
|
-
const days = Number(match[2] || 0);
|
|
101
|
-
const hours = Number(match[3] || 0);
|
|
102
|
-
const minutes = Number(match[4] || 0);
|
|
103
|
-
const seconds = Number(match[5] || 0);
|
|
104
|
-
const totalSeconds = weeks * 7 * 24 * 60 * 60 +
|
|
105
|
-
days * 24 * 60 * 60 +
|
|
106
|
-
hours * 60 * 60 +
|
|
107
|
-
minutes * 60 +
|
|
108
|
-
seconds;
|
|
109
|
-
return totalSeconds * 1000;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Normalize a UTCDateTime by trimming trailing fractional zeros.
|
|
113
|
-
* @param value UTCDateTime string.
|
|
114
|
-
* @return Normalized UTCDateTime string.
|
|
115
|
-
*/
|
|
116
|
-
export function normalizeUtcDateTime(value) {
|
|
117
|
-
const match = value.match(/^(.*)\.(\d+)Z$/);
|
|
118
|
-
if (!match)
|
|
119
|
-
return value;
|
|
120
|
-
const prefix = match[1] ?? value;
|
|
121
|
-
const fraction = match[2] ?? "";
|
|
122
|
-
const trimmed = fraction.replace(/0+$/, "");
|
|
123
|
-
if (trimmed.length === 0) {
|
|
124
|
-
return `${prefix}Z`;
|
|
125
|
-
}
|
|
126
|
-
return `${prefix}.${trimmed}Z`;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Format a Date as LocalDateTime string.
|
|
130
|
-
* @param value Date to format.
|
|
131
|
-
* @return LocalDateTime string.
|
|
132
|
-
*/
|
|
133
|
-
export function localDateTimeFromDate(value) {
|
|
134
|
-
return format(value, "yyyy-MM-dd'T'HH:mm:ss");
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Format a Date as a LocalDateTime in a target time zone.
|
|
138
|
-
* @param value Date to format.
|
|
139
|
-
* @param timeZone IANA time zone.
|
|
140
|
-
* @return LocalDateTime string in the time zone.
|
|
141
|
-
*/
|
|
142
|
-
export function dateTimeInTimeZone(value, timeZone) {
|
|
143
|
-
return formatInTimeZone(value, timeZone, "yyyy-MM-dd'T'HH:mm:ss");
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Convert LocalDateTime string to a UTC Date using a time zone.
|
|
147
|
-
* @param value LocalDateTime string.
|
|
148
|
-
* @param timeZone IANA time zone.
|
|
149
|
-
* @return Date in UTC.
|
|
150
|
-
*/
|
|
151
|
-
export function localDateTimeToUtcDate(value, timeZone) {
|
|
152
|
-
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/.exec(value);
|
|
153
|
-
if (!match) {
|
|
154
|
-
throw new Error(`Invalid LocalDateTime: ${value}`);
|
|
155
|
-
}
|
|
156
|
-
const year = Number(match[1]);
|
|
157
|
-
const month = Number(match[2]);
|
|
158
|
-
const day = Number(match[3]);
|
|
159
|
-
const hour = Number(match[4]);
|
|
160
|
-
const minute = Number(match[5]);
|
|
161
|
-
const second = Number(match[6]);
|
|
162
|
-
const local = new Date(year, month - 1, day, hour, minute, second);
|
|
163
|
-
return fromZonedTime(local, timeZone);
|
|
164
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import type { JsonValue, PatchLike } from "../types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Get the UTF-8 byte length of a string.
|
|
4
|
-
* @param value Input string.
|
|
5
|
-
* @return Byte length.
|
|
6
|
-
*/
|
|
7
|
-
export declare function utf8Length(value: string): number;
|
|
8
|
-
/**
|
|
9
|
-
* Check whether a value is a plain record.
|
|
10
|
-
* @param value Input value.
|
|
11
|
-
* @return True if the value is a record.
|
|
12
|
-
*/
|
|
13
|
-
export declare function isRecord(value: object | null | undefined): value is Record<string, JsonValue>;
|
|
14
|
-
/**
|
|
15
|
-
* Assert a value is a string when defined.
|
|
16
|
-
* @param value Value to check.
|
|
17
|
-
* @param path Validation path.
|
|
18
|
-
* @return Nothing.
|
|
19
|
-
*/
|
|
20
|
-
export declare function assertString(value: string | null | undefined, path: string): void;
|
|
21
|
-
/**
|
|
22
|
-
* Assert a value is a non-empty string when defined.
|
|
23
|
-
* @param value Value to check.
|
|
24
|
-
* @param path Validation path.
|
|
25
|
-
* @return Nothing.
|
|
26
|
-
*/
|
|
27
|
-
export declare function assertNonEmptyString(value: string | undefined, path: string): void;
|
|
28
|
-
/**
|
|
29
|
-
* Assert a value is a valid Id when defined.
|
|
30
|
-
* @param value Value to check.
|
|
31
|
-
* @param path Validation path.
|
|
32
|
-
* @return Nothing.
|
|
33
|
-
*/
|
|
34
|
-
export declare function assertId(value: string | undefined, path: string): void;
|
|
35
|
-
/**
|
|
36
|
-
* Assert a value is boolean when defined.
|
|
37
|
-
* @param value Value to check.
|
|
38
|
-
* @param path Validation path.
|
|
39
|
-
* @return Nothing.
|
|
40
|
-
*/
|
|
41
|
-
export declare function assertBoolean(value: boolean | null | undefined, path: string): void;
|
|
42
|
-
/**
|
|
43
|
-
* Assert a value is an integer when defined.
|
|
44
|
-
* @param value Value to check.
|
|
45
|
-
* @param path Validation path.
|
|
46
|
-
* @return Nothing.
|
|
47
|
-
*/
|
|
48
|
-
export declare function assertInteger(value: number | null | undefined, path: string): void;
|
|
49
|
-
/**
|
|
50
|
-
* Assert a value is a non-negative integer when defined.
|
|
51
|
-
* @param value Value to check.
|
|
52
|
-
* @param path Validation path.
|
|
53
|
-
* @return Nothing.
|
|
54
|
-
*/
|
|
55
|
-
export declare function assertUnsignedInt(value: number | null | undefined, path: string): void;
|
|
56
|
-
/**
|
|
57
|
-
* Assert a date-time string matches the expected format.
|
|
58
|
-
* @param value Date-time string.
|
|
59
|
-
* @param path Validation path.
|
|
60
|
-
* @param requireZ Whether a Z suffix is required.
|
|
61
|
-
* @return Nothing.
|
|
62
|
-
*/
|
|
63
|
-
export declare function assertDateTime(value: string | undefined, path: string, requireZ: boolean): void;
|
|
64
|
-
/**
|
|
65
|
-
* Assert local date time when provided.
|
|
66
|
-
* @param value LocalDateTime string.
|
|
67
|
-
* @param path Validation path.
|
|
68
|
-
* @return Nothing.
|
|
69
|
-
*/
|
|
70
|
-
export declare function assertLocalDateTime(value: string | undefined, path: string): void;
|
|
71
|
-
/**
|
|
72
|
-
* Assert utc date time when provided.
|
|
73
|
-
* @param value UTCDateTime string.
|
|
74
|
-
* @param path Validation path.
|
|
75
|
-
* @return Nothing.
|
|
76
|
-
*/
|
|
77
|
-
export declare function assertUtcDateTime(value: string | undefined, path: string): void;
|
|
78
|
-
/**
|
|
79
|
-
* Assert duration like when provided.
|
|
80
|
-
* @param value Duration string.
|
|
81
|
-
* @param path Validation path.
|
|
82
|
-
* @param signed Whether negative values are allowed.
|
|
83
|
-
* @return Nothing.
|
|
84
|
-
*/
|
|
85
|
-
export declare function assertDurationLike(value: string | undefined, path: string, signed: boolean): void;
|
|
86
|
-
/**
|
|
87
|
-
* Assert duration when provided.
|
|
88
|
-
* @param value Duration string.
|
|
89
|
-
* @param path Validation path.
|
|
90
|
-
* @return Nothing.
|
|
91
|
-
*/
|
|
92
|
-
export declare function assertDuration(value: string | undefined, path: string): void;
|
|
93
|
-
/**
|
|
94
|
-
* Assert signed duration when provided.
|
|
95
|
-
* @param value Duration string.
|
|
96
|
-
* @param path Validation path.
|
|
97
|
-
* @return Nothing.
|
|
98
|
-
*/
|
|
99
|
-
export declare function assertSignedDuration(value: string | undefined, path: string): void;
|
|
100
|
-
/**
|
|
101
|
-
* Assert boolean map when provided.
|
|
102
|
-
* @param value Boolean map object.
|
|
103
|
-
* @param path Validation path.
|
|
104
|
-
* @return Nothing.
|
|
105
|
-
*/
|
|
106
|
-
export declare function assertBooleanMap(value: object | undefined, path: string): void;
|
|
107
|
-
/**
|
|
108
|
-
* Assert ID boolean map when provided.
|
|
109
|
-
* @param value Boolean map object keyed by Ids.
|
|
110
|
-
* @param path Validation path.
|
|
111
|
-
* @return Nothing.
|
|
112
|
-
*/
|
|
113
|
-
export declare function assertIdBooleanMap(value: object | undefined, path: string): void;
|
|
114
|
-
/**
|
|
115
|
-
* Assert media type when provided.
|
|
116
|
-
* @param value Media type string.
|
|
117
|
-
* @param path Validation path.
|
|
118
|
-
* @return Nothing.
|
|
119
|
-
*/
|
|
120
|
-
export declare function assertMediaType(value: string | undefined, path: string): void;
|
|
121
|
-
/**
|
|
122
|
-
* Assert text content type when provided.
|
|
123
|
-
* @param value Media type string.
|
|
124
|
-
* @param path Validation path.
|
|
125
|
-
* @return Nothing.
|
|
126
|
-
*/
|
|
127
|
-
export declare function assertTextContentType(value: string | undefined, path: string): void;
|
|
128
|
-
/**
|
|
129
|
-
* Assert content ID when provided.
|
|
130
|
-
* @param value Content-ID string.
|
|
131
|
-
* @param path Validation path.
|
|
132
|
-
* @return Nothing.
|
|
133
|
-
*/
|
|
134
|
-
export declare function assertContentId(value: string | undefined, path: string): void;
|
|
135
|
-
/**
|
|
136
|
-
* Assert time zone when provided.
|
|
137
|
-
* @param value Time zone ID.
|
|
138
|
-
* @param path Validation path.
|
|
139
|
-
* @return Nothing.
|
|
140
|
-
*/
|
|
141
|
-
export declare function assertTimeZone(value: string | null | undefined, path: string): void;
|
|
142
|
-
/**
|
|
143
|
-
* Assert json value when provided.
|
|
144
|
-
* @param value JSON value.
|
|
145
|
-
* @param path Validation path.
|
|
146
|
-
* @return Nothing.
|
|
147
|
-
*/
|
|
148
|
-
export declare function assertJsonValue(value: JsonValue | object | null | undefined, path: string): void;
|
|
149
|
-
/**
|
|
150
|
-
* Assert patch object when provided.
|
|
151
|
-
* @param value PatchObject.
|
|
152
|
-
* @param path Validation path.
|
|
153
|
-
* @return Nothing.
|
|
154
|
-
*/
|
|
155
|
-
export declare function assertPatchObject(value: PatchLike | undefined, path: string): void;
|