@craftguild/jscalendar 0.5.2 → 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 +130 -94
- 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/jscal/duration.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert seconds to an ISO 8601 duration string.
|
|
3
|
-
* @param totalSeconds Total seconds to encode.
|
|
4
|
-
* @return ISO 8601 duration string.
|
|
5
|
-
*/
|
|
6
|
-
export declare function durationFromSeconds(totalSeconds: number): string;
|
|
7
|
-
export declare const Duration: {
|
|
8
|
-
/**
|
|
9
|
-
* Convert seconds to a duration string.
|
|
10
|
-
* @param value Total seconds.
|
|
11
|
-
* @return ISO 8601 duration string (signed when negative).
|
|
12
|
-
*/
|
|
13
|
-
seconds(value: number): string;
|
|
14
|
-
/**
|
|
15
|
-
* Convert minutes to a duration string.
|
|
16
|
-
* @param value Total minutes.
|
|
17
|
-
* @return ISO 8601 duration string (signed when negative).
|
|
18
|
-
*/
|
|
19
|
-
minutes(value: number): string;
|
|
20
|
-
/**
|
|
21
|
-
* Convert hours to a duration string.
|
|
22
|
-
* @param value Total hours.
|
|
23
|
-
* @return ISO 8601 duration string (signed when negative).
|
|
24
|
-
*/
|
|
25
|
-
hours(value: number): string;
|
|
26
|
-
/**
|
|
27
|
-
* Convert days to a duration string.
|
|
28
|
-
* @param value Total days.
|
|
29
|
-
* @return ISO 8601 duration string (signed when negative).
|
|
30
|
-
*/
|
|
31
|
-
days(value: number): string;
|
|
32
|
-
/**
|
|
33
|
-
* Build a duration string from component parts.
|
|
34
|
-
* @param parts Day/hour/minute/second parts.
|
|
35
|
-
* @return ISO 8601 duration string (signed when total is negative).
|
|
36
|
-
*/
|
|
37
|
-
from(parts: {
|
|
38
|
-
days?: number;
|
|
39
|
-
hours?: number;
|
|
40
|
-
minutes?: number;
|
|
41
|
-
seconds?: number;
|
|
42
|
-
}): string;
|
|
43
|
-
};
|
package/dist/jscal/duration.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { EMPTY_STRING } from "./constants.js";
|
|
2
|
-
/**
|
|
3
|
-
* Convert seconds to an ISO 8601 duration string.
|
|
4
|
-
* @param totalSeconds Total seconds to encode.
|
|
5
|
-
* @return ISO 8601 duration string.
|
|
6
|
-
*/
|
|
7
|
-
export function durationFromSeconds(totalSeconds) {
|
|
8
|
-
const negative = totalSeconds < 0;
|
|
9
|
-
const absSeconds = Math.abs(totalSeconds);
|
|
10
|
-
const clamped = Math.floor(absSeconds);
|
|
11
|
-
const days = Math.floor(clamped / 86400);
|
|
12
|
-
let remaining = clamped % 86400;
|
|
13
|
-
const hours = Math.floor(remaining / 3600);
|
|
14
|
-
remaining %= 3600;
|
|
15
|
-
const minutes = Math.floor(remaining / 60);
|
|
16
|
-
const seconds = remaining % 60;
|
|
17
|
-
const datePart = days > 0 ? `${days}D` : "";
|
|
18
|
-
const timeParts = [];
|
|
19
|
-
if (hours > 0)
|
|
20
|
-
timeParts.push(`${hours}H`);
|
|
21
|
-
if (minutes > 0)
|
|
22
|
-
timeParts.push(`${minutes}M`);
|
|
23
|
-
if (seconds > 0 || (datePart === EMPTY_STRING && timeParts.length === 0)) {
|
|
24
|
-
timeParts.push(`${seconds}S`);
|
|
25
|
-
}
|
|
26
|
-
const timePart = timeParts.length > 0 ? `T${timeParts.join("")}` : "";
|
|
27
|
-
const sign = negative && clamped > 0 ? "-" : "";
|
|
28
|
-
return `${sign}P${datePart}${timePart}`;
|
|
29
|
-
}
|
|
30
|
-
export const Duration = {
|
|
31
|
-
/**
|
|
32
|
-
* Convert seconds to a duration string.
|
|
33
|
-
* @param value Total seconds.
|
|
34
|
-
* @return ISO 8601 duration string (signed when negative).
|
|
35
|
-
*/
|
|
36
|
-
seconds(value) {
|
|
37
|
-
return durationFromSeconds(value);
|
|
38
|
-
},
|
|
39
|
-
/**
|
|
40
|
-
* Convert minutes to a duration string.
|
|
41
|
-
* @param value Total minutes.
|
|
42
|
-
* @return ISO 8601 duration string (signed when negative).
|
|
43
|
-
*/
|
|
44
|
-
minutes(value) {
|
|
45
|
-
return durationFromSeconds(value * 60);
|
|
46
|
-
},
|
|
47
|
-
/**
|
|
48
|
-
* Convert hours to a duration string.
|
|
49
|
-
* @param value Total hours.
|
|
50
|
-
* @return ISO 8601 duration string (signed when negative).
|
|
51
|
-
*/
|
|
52
|
-
hours(value) {
|
|
53
|
-
return durationFromSeconds(value * 3600);
|
|
54
|
-
},
|
|
55
|
-
/**
|
|
56
|
-
* Convert days to a duration string.
|
|
57
|
-
* @param value Total days.
|
|
58
|
-
* @return ISO 8601 duration string (signed when negative).
|
|
59
|
-
*/
|
|
60
|
-
days(value) {
|
|
61
|
-
return durationFromSeconds(value * 86400);
|
|
62
|
-
},
|
|
63
|
-
/**
|
|
64
|
-
* Build a duration string from component parts.
|
|
65
|
-
* @param parts Day/hour/minute/second parts.
|
|
66
|
-
* @return ISO 8601 duration string (signed when total is negative).
|
|
67
|
-
*/
|
|
68
|
-
from(parts) {
|
|
69
|
-
const seconds = (parts.days ?? 0) * 86400 +
|
|
70
|
-
(parts.hours ?? 0) * 3600 +
|
|
71
|
-
(parts.minutes ?? 0) * 60 +
|
|
72
|
-
(parts.seconds ?? 0);
|
|
73
|
-
return durationFromSeconds(seconds);
|
|
74
|
-
},
|
|
75
|
-
};
|
package/dist/jscal/event.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Event, EventPatch } from "../types.js";
|
|
2
|
-
import type { CreateOptions, EventInput } from "./types.js";
|
|
3
|
-
import { Base } from "./base.js";
|
|
4
|
-
export declare class EventObject extends Base<Event, EventPatch, EventObject> {
|
|
5
|
-
/**
|
|
6
|
-
* Wrap updated data in a new EventObject.
|
|
7
|
-
* @param data Updated event data.
|
|
8
|
-
* @return New EventObject instance.
|
|
9
|
-
*/
|
|
10
|
-
protected wrap(data: Event): EventObject;
|
|
11
|
-
/**
|
|
12
|
-
* Create an event with normalized dates, duration, and RFC defaults.
|
|
13
|
-
* @param input Event input values to normalize.
|
|
14
|
-
* @param options Creation options (validation, clock).
|
|
15
|
-
* @return EventObject instance.
|
|
16
|
-
*/
|
|
17
|
-
constructor(input: EventInput, options?: CreateOptions);
|
|
18
|
-
/**
|
|
19
|
-
* Clone the event as a new EventObject instance.
|
|
20
|
-
* @return Cloned EventObject.
|
|
21
|
-
*/
|
|
22
|
-
clone(): EventObject;
|
|
23
|
-
}
|
package/dist/jscal/event.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { resolveTimeZone } from "../timezones.js";
|
|
2
|
-
import { deepClone, nowUtc } from "../utils.js";
|
|
3
|
-
import { validateJsCalendarObject } from "../validate.js";
|
|
4
|
-
import { applyCommonDefaults, applyEventDefaults } from "./defaults.js";
|
|
5
|
-
import { durationFromSeconds } from "./duration.js";
|
|
6
|
-
import { createUid } from "./ids.js";
|
|
7
|
-
import { toLocalDateTime, toUtcDateTime } from "./datetime.js";
|
|
8
|
-
import { Base } from "./base.js";
|
|
9
|
-
import { isStringValue, isNumberValue } from "../utils.js";
|
|
10
|
-
export class EventObject extends Base {
|
|
11
|
-
/**
|
|
12
|
-
* Wrap updated data in a new EventObject.
|
|
13
|
-
* @param data Updated event data.
|
|
14
|
-
* @return New EventObject instance.
|
|
15
|
-
*/
|
|
16
|
-
wrap(data) {
|
|
17
|
-
const { "@type": _type, ...rest } = data;
|
|
18
|
-
return new EventObject(rest, { validate: false });
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Create an event with normalized dates, duration, and RFC defaults.
|
|
22
|
-
* @param input Event input values to normalize.
|
|
23
|
-
* @param options Creation options (validation, clock).
|
|
24
|
-
* @return EventObject instance.
|
|
25
|
-
*/
|
|
26
|
-
constructor(input, options = {}) {
|
|
27
|
-
if (!isStringValue(input.start) && !(input.start instanceof Date)) {
|
|
28
|
-
throw new Error("Event.start is required");
|
|
29
|
-
}
|
|
30
|
-
if (isStringValue(input.start) && input.start.length === 0) {
|
|
31
|
-
throw new Error("Event.start is required");
|
|
32
|
-
}
|
|
33
|
-
const now = options.now ?? nowUtc;
|
|
34
|
-
const { start: rawStart, duration: rawDuration, updated: rawUpdated, created: rawCreated, timeZone: rawTimeZone, ...rest } = input;
|
|
35
|
-
const start = toLocalDateTime(rawStart);
|
|
36
|
-
const updated = rawUpdated ? toUtcDateTime(rawUpdated) : now();
|
|
37
|
-
let timeZone;
|
|
38
|
-
if (rawTimeZone === null) {
|
|
39
|
-
timeZone = null;
|
|
40
|
-
}
|
|
41
|
-
else if (rawTimeZone) {
|
|
42
|
-
timeZone = resolveTimeZone(rawTimeZone);
|
|
43
|
-
}
|
|
44
|
-
const data = {
|
|
45
|
-
...rest,
|
|
46
|
-
"@type": "Event",
|
|
47
|
-
start,
|
|
48
|
-
uid: input.uid ?? createUid(),
|
|
49
|
-
updated,
|
|
50
|
-
};
|
|
51
|
-
if (timeZone !== undefined)
|
|
52
|
-
data.timeZone = timeZone;
|
|
53
|
-
if (rawDuration !== undefined) {
|
|
54
|
-
data.duration = isNumberValue(rawDuration)
|
|
55
|
-
? durationFromSeconds(Math.max(0, rawDuration))
|
|
56
|
-
: rawDuration;
|
|
57
|
-
}
|
|
58
|
-
if (rawCreated) {
|
|
59
|
-
data.created = toUtcDateTime(rawCreated);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
data.created = updated;
|
|
63
|
-
}
|
|
64
|
-
applyCommonDefaults(data);
|
|
65
|
-
applyEventDefaults(data);
|
|
66
|
-
if (options.validate !== false) {
|
|
67
|
-
validateJsCalendarObject(data);
|
|
68
|
-
}
|
|
69
|
-
super(data);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Clone the event as a new EventObject instance.
|
|
73
|
-
* @return Cloned EventObject.
|
|
74
|
-
*/
|
|
75
|
-
clone() {
|
|
76
|
-
return this.wrap(deepClone(this.data));
|
|
77
|
-
}
|
|
78
|
-
}
|
package/dist/jscal/group.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Event, Group, GroupPatch, Task } from "../types.js";
|
|
2
|
-
import type { CreateOptions, GroupInput } from "./types.js";
|
|
3
|
-
import { Base } from "./base.js";
|
|
4
|
-
export declare class GroupObject extends Base<Group, GroupPatch, GroupObject> {
|
|
5
|
-
/**
|
|
6
|
-
* Wrap updated data in a new GroupObject.
|
|
7
|
-
* @param data Updated group data.
|
|
8
|
-
* @return New GroupObject instance.
|
|
9
|
-
*/
|
|
10
|
-
protected wrap(data: Group): GroupObject;
|
|
11
|
-
/**
|
|
12
|
-
* Create a group with normalized entries and RFC defaults.
|
|
13
|
-
* @param input Group input values to normalize.
|
|
14
|
-
* @param options Creation options (validation, clock).
|
|
15
|
-
* @return GroupObject instance.
|
|
16
|
-
*/
|
|
17
|
-
constructor(input: GroupInput, options?: CreateOptions);
|
|
18
|
-
/**
|
|
19
|
-
* Append a normalized entry to the group.
|
|
20
|
-
* @param entry Event or task entry to add.
|
|
21
|
-
* @return New GroupObject instance with the added entry.
|
|
22
|
-
*/
|
|
23
|
-
addEntry(entry: Event | Task | {
|
|
24
|
-
data: Event | Task;
|
|
25
|
-
}): GroupObject;
|
|
26
|
-
/**
|
|
27
|
-
* Clone the group as a new GroupObject instance.
|
|
28
|
-
* @return Cloned GroupObject.
|
|
29
|
-
*/
|
|
30
|
-
clone(): GroupObject;
|
|
31
|
-
}
|
package/dist/jscal/group.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { deepClone, nowUtc } from "../utils.js";
|
|
2
|
-
import { validateJsCalendarObject } from "../validate.js";
|
|
3
|
-
import { applyCommonDefaults } from "./defaults.js";
|
|
4
|
-
import { createUid } from "./ids.js";
|
|
5
|
-
import { Base } from "./base.js";
|
|
6
|
-
import { normalizeEntry } from "./normalize.js";
|
|
7
|
-
import { toUtcDateTime } from "./datetime.js";
|
|
8
|
-
export class GroupObject extends Base {
|
|
9
|
-
/**
|
|
10
|
-
* Wrap updated data in a new GroupObject.
|
|
11
|
-
* @param data Updated group data.
|
|
12
|
-
* @return New GroupObject instance.
|
|
13
|
-
*/
|
|
14
|
-
wrap(data) {
|
|
15
|
-
const { "@type": _type, ...rest } = data;
|
|
16
|
-
return new GroupObject(rest, { validate: false });
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Create a group with normalized entries and RFC defaults.
|
|
20
|
-
* @param input Group input values to normalize.
|
|
21
|
-
* @param options Creation options (validation, clock).
|
|
22
|
-
* @return GroupObject instance.
|
|
23
|
-
*/
|
|
24
|
-
constructor(input, options = {}) {
|
|
25
|
-
if (!Array.isArray(input.entries)) {
|
|
26
|
-
throw new Error("Group.entries is required");
|
|
27
|
-
}
|
|
28
|
-
const now = options.now ?? nowUtc;
|
|
29
|
-
const { updated: rawUpdated, created: rawCreated, ...rest } = input;
|
|
30
|
-
const entries = input.entries.map((entry) => normalizeEntry(entry));
|
|
31
|
-
const updated = rawUpdated ? toUtcDateTime(rawUpdated) : now();
|
|
32
|
-
const data = {
|
|
33
|
-
...rest,
|
|
34
|
-
"@type": "Group",
|
|
35
|
-
entries,
|
|
36
|
-
uid: input.uid ?? createUid(),
|
|
37
|
-
updated,
|
|
38
|
-
};
|
|
39
|
-
if (rawCreated) {
|
|
40
|
-
data.created = toUtcDateTime(rawCreated);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
data.created = updated;
|
|
44
|
-
}
|
|
45
|
-
applyCommonDefaults(data);
|
|
46
|
-
if (options.validate !== false) {
|
|
47
|
-
validateJsCalendarObject(data);
|
|
48
|
-
}
|
|
49
|
-
super(data);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Append a normalized entry to the group.
|
|
53
|
-
* @param entry Event or task entry to add.
|
|
54
|
-
* @return New GroupObject instance with the added entry.
|
|
55
|
-
*/
|
|
56
|
-
addEntry(entry) {
|
|
57
|
-
const next = deepClone(this.data);
|
|
58
|
-
next.entries = [...next.entries, normalizeEntry(entry)];
|
|
59
|
-
const touched = this.touchKeys(next, ["entries"]);
|
|
60
|
-
return this.wrap(touched);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Clone the group as a new GroupObject instance.
|
|
64
|
-
* @return Cloned GroupObject.
|
|
65
|
-
*/
|
|
66
|
-
clone() {
|
|
67
|
-
return this.wrap(deepClone(this.data));
|
|
68
|
-
}
|
|
69
|
-
}
|
package/dist/jscal/guards.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Event, Group, JSCalendarObject, Task } from "../types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Type guard for JSCalendar Event objects.
|
|
4
|
-
* @param obj JSCalendar object to check.
|
|
5
|
-
* @return True when the object is an Event.
|
|
6
|
-
*/
|
|
7
|
-
export declare function isEvent(obj: JSCalendarObject): obj is Event;
|
|
8
|
-
/**
|
|
9
|
-
* Type guard for JSCalendar Task objects.
|
|
10
|
-
* @param obj JSCalendar object to check.
|
|
11
|
-
* @return True when the object is a Task.
|
|
12
|
-
*/
|
|
13
|
-
export declare function isTask(obj: JSCalendarObject): obj is Task;
|
|
14
|
-
/**
|
|
15
|
-
* Type guard for JSCalendar Group objects.
|
|
16
|
-
* @param obj JSCalendar object to check.
|
|
17
|
-
* @return True when the object is a Group.
|
|
18
|
-
*/
|
|
19
|
-
export declare function isGroup(obj: JSCalendarObject): obj is Group;
|
package/dist/jscal/guards.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { TYPE_EVENT, TYPE_GROUP, TYPE_TASK } from "./constants.js";
|
|
2
|
-
/**
|
|
3
|
-
* Type guard for JSCalendar Event objects.
|
|
4
|
-
* @param obj JSCalendar object to check.
|
|
5
|
-
* @return True when the object is an Event.
|
|
6
|
-
*/
|
|
7
|
-
export function isEvent(obj) {
|
|
8
|
-
return obj["@type"] === TYPE_EVENT;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Type guard for JSCalendar Task objects.
|
|
12
|
-
* @param obj JSCalendar object to check.
|
|
13
|
-
* @return True when the object is a Task.
|
|
14
|
-
*/
|
|
15
|
-
export function isTask(obj) {
|
|
16
|
-
return obj["@type"] === TYPE_TASK;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Type guard for JSCalendar Group objects.
|
|
20
|
-
* @param obj JSCalendar object to check.
|
|
21
|
-
* @return True when the object is a Group.
|
|
22
|
-
*/
|
|
23
|
-
export function isGroup(obj) {
|
|
24
|
-
return obj["@type"] === TYPE_GROUP;
|
|
25
|
-
}
|
package/dist/jscal/ids.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Id } from "../types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Create a UUID-like identifier.
|
|
4
|
-
* @return UUID string.
|
|
5
|
-
*/
|
|
6
|
-
export declare function createUid(): string;
|
|
7
|
-
/**
|
|
8
|
-
* Create a compact base64url identifier.
|
|
9
|
-
* @return Base64url ID string.
|
|
10
|
-
*/
|
|
11
|
-
export declare function createId(): Id;
|
package/dist/jscal/ids.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { TYPEOF_FUNCTION } from "./constants.js";
|
|
2
|
-
/**
|
|
3
|
-
* Get a Crypto instance if available.
|
|
4
|
-
* @return Crypto instance when available, otherwise undefined.
|
|
5
|
-
*/
|
|
6
|
-
function getCrypto() {
|
|
7
|
-
const cryptoObj = globalThis.crypto;
|
|
8
|
-
if (cryptoObj && typeof cryptoObj.getRandomValues === TYPEOF_FUNCTION) {
|
|
9
|
-
return cryptoObj;
|
|
10
|
-
}
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Generate random bytes using Crypto or Math.random.
|
|
15
|
-
* @param length Number of bytes to generate.
|
|
16
|
-
* @return Random byte array.
|
|
17
|
-
*/
|
|
18
|
-
function getRandomBytes(length) {
|
|
19
|
-
const bytes = new Uint8Array(length);
|
|
20
|
-
const cryptoObj = getCrypto();
|
|
21
|
-
if (cryptoObj) {
|
|
22
|
-
cryptoObj.getRandomValues(bytes);
|
|
23
|
-
return bytes;
|
|
24
|
-
}
|
|
25
|
-
for (let i = 0; i < length; i += 1) {
|
|
26
|
-
bytes[i] = Math.floor(Math.random() * 256);
|
|
27
|
-
}
|
|
28
|
-
return bytes;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Encode bytes as base64url.
|
|
32
|
-
* @param bytes Byte array to encode.
|
|
33
|
-
* @return Base64url string without padding.
|
|
34
|
-
*/
|
|
35
|
-
function base64UrlEncode(bytes) {
|
|
36
|
-
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
37
|
-
let output = "";
|
|
38
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
39
|
-
const b0 = bytes[i] ?? 0;
|
|
40
|
-
const b1 = bytes[i + 1] ?? 0;
|
|
41
|
-
const b2 = bytes[i + 2] ?? 0;
|
|
42
|
-
const triplet = ((b0 ?? 0) << 16) | ((b1 ?? 0) << 8) | (b2 ?? 0);
|
|
43
|
-
output += alphabet[(triplet >> 18) & 0x3f] ?? "";
|
|
44
|
-
output += alphabet[(triplet >> 12) & 0x3f] ?? "";
|
|
45
|
-
output += i + 1 < bytes.length ? alphabet[(triplet >> 6) & 0x3f] ?? "" : "=";
|
|
46
|
-
output += i + 2 < bytes.length ? alphabet[triplet & 0x3f] ?? "" : "=";
|
|
47
|
-
}
|
|
48
|
-
return output.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Create a UUID-like identifier.
|
|
52
|
-
* @return UUID string.
|
|
53
|
-
*/
|
|
54
|
-
export function createUid() {
|
|
55
|
-
const cryptoObj = getCrypto();
|
|
56
|
-
if (cryptoObj?.randomUUID) {
|
|
57
|
-
return cryptoObj.randomUUID();
|
|
58
|
-
}
|
|
59
|
-
const bytes = getRandomBytes(16);
|
|
60
|
-
if (bytes.length > 6) {
|
|
61
|
-
const b6 = bytes[6] ?? 0;
|
|
62
|
-
bytes[6] = (b6 & 0x0f) | 0x40;
|
|
63
|
-
}
|
|
64
|
-
if (bytes.length > 8) {
|
|
65
|
-
const b8 = bytes[8] ?? 0;
|
|
66
|
-
bytes[8] = (b8 & 0x3f) | 0x80;
|
|
67
|
-
}
|
|
68
|
-
const hex = Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
69
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Create a compact base64url identifier.
|
|
73
|
-
* @return Base64url ID string.
|
|
74
|
-
*/
|
|
75
|
-
export function createId() {
|
|
76
|
-
return base64UrlEncode(getRandomBytes(16));
|
|
77
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Event, JSCalendarObject, Task } from "../types.js";
|
|
2
|
-
import type { EntryInput } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Type guard for wrapper instances that expose a data field.
|
|
5
|
-
* @param value Value to check.
|
|
6
|
-
* @return True when value looks like a JsCal instance.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isJsCalInstance(value: object): value is {
|
|
9
|
-
data: JSCalendarObject;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Normalize a list of mixed JSCalendar objects and JsCal instances.
|
|
13
|
-
* @param items Items to normalize.
|
|
14
|
-
* @return Plain JSCalendar objects.
|
|
15
|
-
*/
|
|
16
|
-
export declare function normalizeItems(items: Array<JSCalendarObject | {
|
|
17
|
-
data: JSCalendarObject;
|
|
18
|
-
}>): JSCalendarObject[];
|
|
19
|
-
/**
|
|
20
|
-
* Normalize a group entry into a plain Event or Task.
|
|
21
|
-
* @param entry Group entry input.
|
|
22
|
-
* @return Plain Event or Task object.
|
|
23
|
-
*/
|
|
24
|
-
export declare function normalizeEntry(entry: EntryInput): Event | Task;
|
|
25
|
-
/**
|
|
26
|
-
* Normalize a list to plain JSCalendar objects.
|
|
27
|
-
* @param value List of JSCalendar objects or JsCal instances.
|
|
28
|
-
* @return Plain JSCalendar objects.
|
|
29
|
-
*/
|
|
30
|
-
export declare function normalizeToObjects(value: Array<JSCalendarObject | {
|
|
31
|
-
data: JSCalendarObject;
|
|
32
|
-
}>): JSCalendarObject[];
|
package/dist/jscal/normalize.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { isObjectValue } from "../utils.js";
|
|
2
|
-
/**
|
|
3
|
-
* Type guard for wrapper instances that expose a data field.
|
|
4
|
-
* @param value Value to check.
|
|
5
|
-
* @return True when value looks like a JsCal instance.
|
|
6
|
-
*/
|
|
7
|
-
export function isJsCalInstance(value) {
|
|
8
|
-
return "data" in value;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Normalize a list of mixed JSCalendar objects and JsCal instances.
|
|
12
|
-
* @param items Items to normalize.
|
|
13
|
-
* @return Plain JSCalendar objects.
|
|
14
|
-
*/
|
|
15
|
-
export function normalizeItems(items) {
|
|
16
|
-
const mapped = [];
|
|
17
|
-
for (const entry of items) {
|
|
18
|
-
if (isObjectValue(entry) && isJsCalInstance(entry)) {
|
|
19
|
-
mapped.push(entry.data);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
mapped.push(entry);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return mapped;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Normalize a group entry into a plain Event or Task.
|
|
29
|
-
* @param entry Group entry input.
|
|
30
|
-
* @return Plain Event or Task object.
|
|
31
|
-
*/
|
|
32
|
-
export function normalizeEntry(entry) {
|
|
33
|
-
if (isObjectValue(entry) && isJsCalInstance(entry)) {
|
|
34
|
-
return entry.data;
|
|
35
|
-
}
|
|
36
|
-
return entry;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Normalize a list to plain JSCalendar objects.
|
|
40
|
-
* @param value List of JSCalendar objects or JsCal instances.
|
|
41
|
-
* @return Plain JSCalendar objects.
|
|
42
|
-
*/
|
|
43
|
-
export function normalizeToObjects(value) {
|
|
44
|
-
return normalizeItems(value);
|
|
45
|
-
}
|
package/dist/jscal/task.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Task, TaskPatch } from "../types.js";
|
|
2
|
-
import type { CreateOptions, TaskInput } from "./types.js";
|
|
3
|
-
import { Base } from "./base.js";
|
|
4
|
-
export declare class TaskObject extends Base<Task, TaskPatch, TaskObject> {
|
|
5
|
-
/**
|
|
6
|
-
* Wrap updated data in a new TaskObject.
|
|
7
|
-
* @param data Updated task data.
|
|
8
|
-
* @return New TaskObject instance.
|
|
9
|
-
*/
|
|
10
|
-
protected wrap(data: Task): TaskObject;
|
|
11
|
-
/**
|
|
12
|
-
* Create a task with normalized date fields and RFC defaults applied.
|
|
13
|
-
* @param input Task input values to normalize.
|
|
14
|
-
* @param options Creation options (validation, clock).
|
|
15
|
-
* @return TaskObject instance.
|
|
16
|
-
*/
|
|
17
|
-
constructor(input?: TaskInput, options?: CreateOptions);
|
|
18
|
-
/**
|
|
19
|
-
* Clone the task as a new TaskObject instance.
|
|
20
|
-
* @return Cloned TaskObject.
|
|
21
|
-
*/
|
|
22
|
-
clone(): TaskObject;
|
|
23
|
-
}
|
package/dist/jscal/task.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { resolveTimeZone } from "../timezones.js";
|
|
2
|
-
import { deepClone, nowUtc } from "../utils.js";
|
|
3
|
-
import { validateJsCalendarObject } from "../validate.js";
|
|
4
|
-
import { applyCommonDefaults, applyTaskDefaults } from "./defaults.js";
|
|
5
|
-
import { createUid } from "./ids.js";
|
|
6
|
-
import { toLocalDateTime, toUtcDateTime } from "./datetime.js";
|
|
7
|
-
import { Base } from "./base.js";
|
|
8
|
-
export class TaskObject extends Base {
|
|
9
|
-
/**
|
|
10
|
-
* Wrap updated data in a new TaskObject.
|
|
11
|
-
* @param data Updated task data.
|
|
12
|
-
* @return New TaskObject instance.
|
|
13
|
-
*/
|
|
14
|
-
wrap(data) {
|
|
15
|
-
const { "@type": _type, ...rest } = data;
|
|
16
|
-
return new TaskObject(rest, { validate: false });
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Create a task with normalized date fields and RFC defaults applied.
|
|
20
|
-
* @param input Task input values to normalize.
|
|
21
|
-
* @param options Creation options (validation, clock).
|
|
22
|
-
* @return TaskObject instance.
|
|
23
|
-
*/
|
|
24
|
-
constructor(input = {}, options = {}) {
|
|
25
|
-
const now = options.now ?? nowUtc;
|
|
26
|
-
const { start: rawStart, due: rawDue, updated: rawUpdated, created: rawCreated, timeZone: rawTimeZone, ...rest } = input;
|
|
27
|
-
const updated = rawUpdated ? toUtcDateTime(rawUpdated) : now();
|
|
28
|
-
let timeZone;
|
|
29
|
-
if (rawTimeZone === null) {
|
|
30
|
-
timeZone = null;
|
|
31
|
-
}
|
|
32
|
-
else if (rawTimeZone) {
|
|
33
|
-
timeZone = resolveTimeZone(rawTimeZone);
|
|
34
|
-
}
|
|
35
|
-
const data = {
|
|
36
|
-
...rest,
|
|
37
|
-
"@type": "Task",
|
|
38
|
-
uid: input.uid ?? createUid(),
|
|
39
|
-
updated,
|
|
40
|
-
};
|
|
41
|
-
if (rawStart)
|
|
42
|
-
data.start = toLocalDateTime(rawStart);
|
|
43
|
-
if (rawDue)
|
|
44
|
-
data.due = toLocalDateTime(rawDue);
|
|
45
|
-
if (timeZone !== undefined)
|
|
46
|
-
data.timeZone = timeZone;
|
|
47
|
-
if (rawCreated) {
|
|
48
|
-
data.created = toUtcDateTime(rawCreated);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
data.created = updated;
|
|
52
|
-
}
|
|
53
|
-
applyCommonDefaults(data);
|
|
54
|
-
applyTaskDefaults(data);
|
|
55
|
-
if (options.validate !== false) {
|
|
56
|
-
validateJsCalendarObject(data);
|
|
57
|
-
}
|
|
58
|
-
super(data);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Clone the task as a new TaskObject instance.
|
|
62
|
-
* @return Cloned TaskObject.
|
|
63
|
-
*/
|
|
64
|
-
clone() {
|
|
65
|
-
return this.wrap(deepClone(this.data));
|
|
66
|
-
}
|
|
67
|
-
}
|
package/dist/jscal/types.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Event, Group, Task, TimeZoneInput, UTCDateTime } from "../types.js";
|
|
2
|
-
export type CreateOptions = {
|
|
3
|
-
now?: () => UTCDateTime;
|
|
4
|
-
validate?: boolean;
|
|
5
|
-
};
|
|
6
|
-
export type UpdateOptions = {
|
|
7
|
-
touch?: boolean;
|
|
8
|
-
sequence?: boolean;
|
|
9
|
-
now?: () => UTCDateTime;
|
|
10
|
-
validate?: boolean;
|
|
11
|
-
};
|
|
12
|
-
export type DateInput = string | Date;
|
|
13
|
-
export type DurationInput = string | number;
|
|
14
|
-
export type EntryInput = Event | Task | {
|
|
15
|
-
data: Event | Task;
|
|
16
|
-
};
|
|
17
|
-
export type EventInput = Omit<Event, "@type" | "uid" | "updated" | "created" | "start" | "duration" | "timeZone"> & {
|
|
18
|
-
start: DateInput;
|
|
19
|
-
duration?: DurationInput;
|
|
20
|
-
timeZone?: TimeZoneInput | null;
|
|
21
|
-
uid?: string;
|
|
22
|
-
updated?: DateInput;
|
|
23
|
-
created?: DateInput;
|
|
24
|
-
};
|
|
25
|
-
export type TaskInput = Omit<Task, "@type" | "uid" | "updated" | "created" | "start" | "due" | "timeZone"> & {
|
|
26
|
-
uid?: string;
|
|
27
|
-
updated?: DateInput;
|
|
28
|
-
created?: DateInput;
|
|
29
|
-
start?: DateInput;
|
|
30
|
-
due?: DateInput;
|
|
31
|
-
timeZone?: TimeZoneInput | null;
|
|
32
|
-
};
|
|
33
|
-
export type GroupInput = Omit<Group, "@type" | "uid" | "updated" | "created" | "entries"> & {
|
|
34
|
-
entries: EntryInput[];
|
|
35
|
-
uid?: string;
|
|
36
|
-
updated?: DateInput;
|
|
37
|
-
created?: DateInput;
|
|
38
|
-
};
|
package/dist/jscal/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|