iamcal 3.0.3 → 4.0.0
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 +2 -2
- package/lib/component.d.ts +2 -1
- package/lib/component.d.ts.map +1 -1
- package/lib/component.js +14 -16
- package/lib/components/CalendarEvent.d.ts +34 -8
- package/lib/components/CalendarEvent.d.ts.map +1 -1
- package/lib/components/CalendarEvent.js +67 -8
- package/lib/date.d.ts +41 -3
- package/lib/date.d.ts.map +1 -1
- package/lib/date.js +75 -7
- package/lib/duration.d.ts +106 -0
- package/lib/duration.d.ts.map +1 -0
- package/lib/duration.js +277 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/io.d.ts +20 -0
- package/lib/io.d.ts.map +1 -1
- package/lib/io.js +30 -1
- package/lib/parse.d.ts +11 -3
- package/lib/parse.d.ts.map +1 -1
- package/lib/parse.js +42 -22
- package/lib/property/Property.d.ts +24 -2
- package/lib/property/Property.d.ts.map +1 -1
- package/lib/property/Property.js +71 -4
- package/lib/property/validate.js +2 -2
- package/package.json +1 -1
- package/src/component.ts +15 -23
- package/src/components/CalendarEvent.ts +73 -9
- package/src/date.ts +96 -13
- package/src/duration.ts +329 -0
- package/src/index.ts +1 -0
- package/src/io.ts +42 -1
- package/src/parse.ts +43 -19
- package/src/property/Property.ts +80 -5
- package/src/property/validate.ts +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { CalendarDateOrTime } from './date';
|
|
2
|
+
export type DurationUnit = 'W' | 'D' | 'H' | 'M' | 'S';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a DURATION value as defined by RFC5545.
|
|
5
|
+
*/
|
|
6
|
+
export declare class CalendarDuration {
|
|
7
|
+
weeks?: number;
|
|
8
|
+
days?: number;
|
|
9
|
+
hours?: number;
|
|
10
|
+
minutes?: number;
|
|
11
|
+
seconds?: number;
|
|
12
|
+
constructor(duration: string | CalendarDuration);
|
|
13
|
+
/**
|
|
14
|
+
* Get the length of this duration object in seconds.
|
|
15
|
+
* @returns The total number of seconds represented by this duration.
|
|
16
|
+
*/
|
|
17
|
+
inSeconds(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Get the length of this duration object in milliseconds.
|
|
20
|
+
*
|
|
21
|
+
* Note that this will always return whole seconds, as durations do not
|
|
22
|
+
* support milliseconds.
|
|
23
|
+
* @returns The total number of milliseconds represented by this duration.
|
|
24
|
+
*/
|
|
25
|
+
inMilliseconds(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Get the duration string that represents this duration.
|
|
28
|
+
* @returns A duration string in the format `P[n]W` for weeks, or `P[n]DT[n]H[n]M[n]S` for days, hours, minutes and seconds. Prefixed with a `-` if negative.
|
|
29
|
+
*/
|
|
30
|
+
getValue(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Get the floor the duration to the nearest of a given unit.
|
|
33
|
+
* @param unit The unit to floor to.
|
|
34
|
+
* @returns The duration with units smaller than `unit` removed.
|
|
35
|
+
* @example
|
|
36
|
+
* const duration = new CalendarDuration("1W2D5H30M")
|
|
37
|
+
* const days = duration.floor("D") // Floor to days
|
|
38
|
+
* console.log(days.getValue()) // "1W2D"
|
|
39
|
+
*/
|
|
40
|
+
floor(unit: DurationUnit): CalendarDuration;
|
|
41
|
+
/**
|
|
42
|
+
* Create a duration from a number of seconds.
|
|
43
|
+
* @param seconds How many seconds the duration should represent.
|
|
44
|
+
* @returns A {@link CalendarDuration} representing the specified number of seconds.
|
|
45
|
+
* @throws {Error} If seconds is NaN.
|
|
46
|
+
*/
|
|
47
|
+
static fromSeconds(seconds: number): CalendarDuration;
|
|
48
|
+
/**
|
|
49
|
+
* Create a duration from a number of days.
|
|
50
|
+
* @param days How many days the duration should represent.
|
|
51
|
+
* @returns A {@link CalendarDuration} representing the specified number of days.
|
|
52
|
+
* @throws {Error} If days is NaN.
|
|
53
|
+
*/
|
|
54
|
+
static fromDays(days: number): CalendarDuration;
|
|
55
|
+
/**
|
|
56
|
+
* Create a duration from a number of weeks.
|
|
57
|
+
* @param weeks How many weeks the duration should represent.
|
|
58
|
+
* @returns A {@link CalendarDuration} representing the specified number of weeks.
|
|
59
|
+
* @throws {Error} If weeks is NaN.
|
|
60
|
+
*/
|
|
61
|
+
static fromWeeks(weeks: number): CalendarDuration;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a duration from the difference between two dates.
|
|
64
|
+
* @param start The start date or time.
|
|
65
|
+
* @param end The end date or time.
|
|
66
|
+
* @returns A {@link CalendarDuration} representing the difference between the two dates.
|
|
67
|
+
* @throws {Error} If the start date and end date have different types.
|
|
68
|
+
*/
|
|
69
|
+
static fromDifference(start: Date | CalendarDateOrTime, end: Date | CalendarDateOrTime): CalendarDuration;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Convert time units to a duration string.
|
|
73
|
+
*
|
|
74
|
+
* A duration is considered negative if any unit is less than 0.
|
|
75
|
+
* @param weeks How many weeks the duration should represent.
|
|
76
|
+
* @param days The days part of the duration.
|
|
77
|
+
* @param hours The hours part of the duration.
|
|
78
|
+
* @param minutes The minutes part of the duration.
|
|
79
|
+
* @param seconds The seconds part of the duration.
|
|
80
|
+
* @returns A string representing the duration in the format `P[n]W` or `P[n]DT[n]H[n]M[n]S` where values may be omitted if 0, prefixed with `-` if negative.
|
|
81
|
+
* @throws {Error} If weeks are combined with other values.
|
|
82
|
+
* @throws {Error} If any unit is NaN.
|
|
83
|
+
*/
|
|
84
|
+
export declare function formatDurationString(weeks: number | undefined, days: number | undefined, hours: number | undefined, minutes: number | undefined, seconds: number | undefined): string;
|
|
85
|
+
/**
|
|
86
|
+
* Convert a number of seconds to a duration string.
|
|
87
|
+
* @param seconds How many seconds the duration should represent.
|
|
88
|
+
* @returns A string representing the duration in the format `PT[n]H[n]M[n]S` where values may be omitted if 0, prefixed with `-` if negative.
|
|
89
|
+
* @throws {Error} If seconds is NaN.
|
|
90
|
+
*/
|
|
91
|
+
export declare function secondsToDurationString(seconds: number): string;
|
|
92
|
+
/**
|
|
93
|
+
* Convert a number of days to a duration string.
|
|
94
|
+
* @param days How many days the duration should represent.
|
|
95
|
+
* @returns A string representing the duration in the format `P[n]D`, prefixed with `-` if negative.
|
|
96
|
+
* @throws {Error} If days is NaN.
|
|
97
|
+
*/
|
|
98
|
+
export declare function daysToDurationString(days: number): string;
|
|
99
|
+
/**
|
|
100
|
+
* Convert a number of weeks to a duration string.
|
|
101
|
+
* @param weeks How many weeks the duration should represent.
|
|
102
|
+
* @returns A string representing the duration in the format `P[n]W`, prefixed with `-` if negative.
|
|
103
|
+
* @throws {Error} If weeks is NaN.
|
|
104
|
+
*/
|
|
105
|
+
export declare function weeksToDurationString(weeks: number): string;
|
|
106
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,kBAAkB,EASrB,MAAM,QAAQ,CAAA;AAGf,MAAM,MAAM,YAAY,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAEtD;;GAEG;AACH,qBAAa,gBAAgB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;gBAEJ,QAAQ,EAAE,MAAM,GAAG,gBAAgB;IAqC/C;;;OAGG;IACH,SAAS,IAAI,MAAM;IAUnB;;;;;;OAMG;IACH,cAAc,IAAI,MAAM;IAIxB;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAUlB;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,gBAAgB;IAiB3C;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB;IAIrD;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB;IAI/C;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB;IAIjD;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CACjB,KAAK,EAAE,IAAI,GAAG,kBAAkB,EAChC,GAAG,EAAE,IAAI,GAAG,kBAAkB,GAC/B,gBAAgB;CA4BtB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,GAC5B,MAAM,CAkDR;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAsB/D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQzD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ3D"}
|
package/lib/duration.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CalendarDuration = void 0;
|
|
4
|
+
exports.formatDurationString = formatDurationString;
|
|
5
|
+
exports.secondsToDurationString = secondsToDurationString;
|
|
6
|
+
exports.daysToDurationString = daysToDurationString;
|
|
7
|
+
exports.weeksToDurationString = weeksToDurationString;
|
|
8
|
+
const date_1 = require("./date");
|
|
9
|
+
const property_1 = require("./property");
|
|
10
|
+
/**
|
|
11
|
+
* Represents a DURATION value as defined by RFC5545.
|
|
12
|
+
*/
|
|
13
|
+
class CalendarDuration {
|
|
14
|
+
weeks;
|
|
15
|
+
days;
|
|
16
|
+
hours;
|
|
17
|
+
minutes;
|
|
18
|
+
seconds;
|
|
19
|
+
constructor(duration) {
|
|
20
|
+
if (typeof duration === 'string') {
|
|
21
|
+
(0, property_1.validateDuration)(duration);
|
|
22
|
+
const negativeMultiplier = duration.startsWith('-') ? -1 : 1;
|
|
23
|
+
const findParts = /(\d+)([WDHMS])/g;
|
|
24
|
+
const parts = duration.matchAll(findParts);
|
|
25
|
+
for (const part of parts) {
|
|
26
|
+
const value = parseInt(part[1], 10);
|
|
27
|
+
const name = part[2];
|
|
28
|
+
switch (name) {
|
|
29
|
+
case 'W':
|
|
30
|
+
this.weeks = value * negativeMultiplier;
|
|
31
|
+
break;
|
|
32
|
+
case 'D':
|
|
33
|
+
this.days = value * negativeMultiplier;
|
|
34
|
+
break;
|
|
35
|
+
case 'H':
|
|
36
|
+
this.hours = value * negativeMultiplier;
|
|
37
|
+
break;
|
|
38
|
+
case 'M':
|
|
39
|
+
this.minutes = value * negativeMultiplier;
|
|
40
|
+
break;
|
|
41
|
+
case 'S':
|
|
42
|
+
this.seconds = value * negativeMultiplier;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.weeks = duration.weeks;
|
|
49
|
+
this.days = duration.days;
|
|
50
|
+
this.hours = duration.hours;
|
|
51
|
+
this.minutes = duration.minutes;
|
|
52
|
+
this.seconds = duration.seconds;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the length of this duration object in seconds.
|
|
57
|
+
* @returns The total number of seconds represented by this duration.
|
|
58
|
+
*/
|
|
59
|
+
inSeconds() {
|
|
60
|
+
return ((this.weeks ?? 0) * date_1.ONE_WEEK_SECONDS +
|
|
61
|
+
(this.days ?? 0) * date_1.ONE_DAY_SECONDS +
|
|
62
|
+
(this.hours ?? 0) * date_1.ONE_HOUR_SECONDS +
|
|
63
|
+
(this.minutes ?? 0) * date_1.ONE_MINUTE_SECONDS +
|
|
64
|
+
(this.seconds ?? 0));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the length of this duration object in milliseconds.
|
|
68
|
+
*
|
|
69
|
+
* Note that this will always return whole seconds, as durations do not
|
|
70
|
+
* support milliseconds.
|
|
71
|
+
* @returns The total number of milliseconds represented by this duration.
|
|
72
|
+
*/
|
|
73
|
+
inMilliseconds() {
|
|
74
|
+
return this.inSeconds() * date_1.ONE_SECOND_MS;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the duration string that represents this duration.
|
|
78
|
+
* @returns A duration string in the format `P[n]W` for weeks, or `P[n]DT[n]H[n]M[n]S` for days, hours, minutes and seconds. Prefixed with a `-` if negative.
|
|
79
|
+
*/
|
|
80
|
+
getValue() {
|
|
81
|
+
return formatDurationString(this.weeks, this.days, this.hours, this.minutes, this.seconds);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the floor the duration to the nearest of a given unit.
|
|
85
|
+
* @param unit The unit to floor to.
|
|
86
|
+
* @returns The duration with units smaller than `unit` removed.
|
|
87
|
+
* @example
|
|
88
|
+
* const duration = new CalendarDuration("1W2D5H30M")
|
|
89
|
+
* const days = duration.floor("D") // Floor to days
|
|
90
|
+
* console.log(days.getValue()) // "1W2D"
|
|
91
|
+
*/
|
|
92
|
+
floor(unit) {
|
|
93
|
+
const result = new CalendarDuration(this);
|
|
94
|
+
/* eslint-disable no-fallthrough */
|
|
95
|
+
switch (unit) {
|
|
96
|
+
case 'W':
|
|
97
|
+
result.days = undefined;
|
|
98
|
+
case 'D':
|
|
99
|
+
result.hours = undefined;
|
|
100
|
+
case 'H':
|
|
101
|
+
result.minutes = undefined;
|
|
102
|
+
case 'M':
|
|
103
|
+
result.seconds = undefined;
|
|
104
|
+
}
|
|
105
|
+
/* eslint-enable no-fallthrough */
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Create a duration from a number of seconds.
|
|
110
|
+
* @param seconds How many seconds the duration should represent.
|
|
111
|
+
* @returns A {@link CalendarDuration} representing the specified number of seconds.
|
|
112
|
+
* @throws {Error} If seconds is NaN.
|
|
113
|
+
*/
|
|
114
|
+
static fromSeconds(seconds) {
|
|
115
|
+
return new CalendarDuration(secondsToDurationString(seconds));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create a duration from a number of days.
|
|
119
|
+
* @param days How many days the duration should represent.
|
|
120
|
+
* @returns A {@link CalendarDuration} representing the specified number of days.
|
|
121
|
+
* @throws {Error} If days is NaN.
|
|
122
|
+
*/
|
|
123
|
+
static fromDays(days) {
|
|
124
|
+
return new CalendarDuration(daysToDurationString(days));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a duration from a number of weeks.
|
|
128
|
+
* @param weeks How many weeks the duration should represent.
|
|
129
|
+
* @returns A {@link CalendarDuration} representing the specified number of weeks.
|
|
130
|
+
* @throws {Error} If weeks is NaN.
|
|
131
|
+
*/
|
|
132
|
+
static fromWeeks(weeks) {
|
|
133
|
+
return new CalendarDuration(weeksToDurationString(weeks));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Creates a duration from the difference between two dates.
|
|
137
|
+
* @param start The start date or time.
|
|
138
|
+
* @param end The end date or time.
|
|
139
|
+
* @returns A {@link CalendarDuration} representing the difference between the two dates.
|
|
140
|
+
* @throws {Error} If the start date and end date have different types.
|
|
141
|
+
*/
|
|
142
|
+
static fromDifference(start, end) {
|
|
143
|
+
if ((0, date_1.isDateObject)(start)) {
|
|
144
|
+
// Date
|
|
145
|
+
if ((0, date_1.isDateObject)(end)) {
|
|
146
|
+
const differenceSeconds = (end.getTime() - start.getTime()) / date_1.ONE_SECOND_MS;
|
|
147
|
+
return CalendarDuration.fromSeconds(differenceSeconds);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if (start.isFullDay()) {
|
|
151
|
+
// CalendarDate
|
|
152
|
+
if ((0, date_1.isCalendarDateOrTime)(end) && end.isFullDay()) {
|
|
153
|
+
const startMs = start.getDate().getTime();
|
|
154
|
+
const endMs = end.getDate().getTime();
|
|
155
|
+
const differenceDays = (endMs - startMs) / date_1.ONE_DAY_MS;
|
|
156
|
+
return CalendarDuration.fromDays(differenceDays);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// CalendarDateTime
|
|
161
|
+
if ((0, date_1.isCalendarDateOrTime)(end) && !end.isFullDay()) {
|
|
162
|
+
const startMs = start.getDate().getTime();
|
|
163
|
+
const endMs = end.getDate().getTime();
|
|
164
|
+
const differenceSeconds = (endMs - startMs) / date_1.ONE_SECOND_MS;
|
|
165
|
+
return CalendarDuration.fromSeconds(differenceSeconds);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
throw new Error('Start and end dates must be of the same type');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.CalendarDuration = CalendarDuration;
|
|
172
|
+
/**
|
|
173
|
+
* Convert time units to a duration string.
|
|
174
|
+
*
|
|
175
|
+
* A duration is considered negative if any unit is less than 0.
|
|
176
|
+
* @param weeks How many weeks the duration should represent.
|
|
177
|
+
* @param days The days part of the duration.
|
|
178
|
+
* @param hours The hours part of the duration.
|
|
179
|
+
* @param minutes The minutes part of the duration.
|
|
180
|
+
* @param seconds The seconds part of the duration.
|
|
181
|
+
* @returns A string representing the duration in the format `P[n]W` or `P[n]DT[n]H[n]M[n]S` where values may be omitted if 0, prefixed with `-` if negative.
|
|
182
|
+
* @throws {Error} If weeks are combined with other values.
|
|
183
|
+
* @throws {Error} If any unit is NaN.
|
|
184
|
+
*/
|
|
185
|
+
function formatDurationString(weeks, days, hours, minutes, seconds) {
|
|
186
|
+
let prefix = '';
|
|
187
|
+
let durationString = prefix + 'P';
|
|
188
|
+
let hasTime = false;
|
|
189
|
+
let isEmpty = true;
|
|
190
|
+
const appendUnit = (time, unit) => {
|
|
191
|
+
if (time === undefined)
|
|
192
|
+
return;
|
|
193
|
+
if (isNaN(time)) {
|
|
194
|
+
throw new Error(`${unit} must not be NaN`);
|
|
195
|
+
}
|
|
196
|
+
if (time < 0)
|
|
197
|
+
prefix = '-';
|
|
198
|
+
const absTime = Math.abs(Math.floor(time));
|
|
199
|
+
durationString += absTime + unit.charAt(0);
|
|
200
|
+
isEmpty = false;
|
|
201
|
+
};
|
|
202
|
+
const appendTimeUnit = (time, unit) => {
|
|
203
|
+
if (time === undefined)
|
|
204
|
+
return;
|
|
205
|
+
if (!hasTime) {
|
|
206
|
+
durationString += 'T';
|
|
207
|
+
hasTime = true;
|
|
208
|
+
}
|
|
209
|
+
appendUnit(time, unit);
|
|
210
|
+
};
|
|
211
|
+
// Add units
|
|
212
|
+
if (weeks !== undefined) {
|
|
213
|
+
if (days !== undefined ||
|
|
214
|
+
hours !== undefined ||
|
|
215
|
+
minutes !== undefined ||
|
|
216
|
+
seconds !== undefined) {
|
|
217
|
+
throw new Error('Cannot combine weeks with other units in duration string');
|
|
218
|
+
}
|
|
219
|
+
appendUnit(weeks, 'Weeks');
|
|
220
|
+
}
|
|
221
|
+
appendUnit(days, 'Days');
|
|
222
|
+
appendTimeUnit(hours, 'Hours');
|
|
223
|
+
if (minutes !== undefined) {
|
|
224
|
+
appendTimeUnit(minutes, 'Minutes');
|
|
225
|
+
}
|
|
226
|
+
else if (hours !== undefined && seconds !== undefined) {
|
|
227
|
+
appendTimeUnit(0, 'Minutes');
|
|
228
|
+
}
|
|
229
|
+
appendTimeUnit(seconds, 'Seconds');
|
|
230
|
+
if (isEmpty) {
|
|
231
|
+
throw new Error('Duration string must not be empty');
|
|
232
|
+
}
|
|
233
|
+
return prefix + durationString;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Convert a number of seconds to a duration string.
|
|
237
|
+
* @param seconds How many seconds the duration should represent.
|
|
238
|
+
* @returns A string representing the duration in the format `PT[n]H[n]M[n]S` where values may be omitted if 0, prefixed with `-` if negative.
|
|
239
|
+
* @throws {Error} If seconds is NaN.
|
|
240
|
+
*/
|
|
241
|
+
function secondsToDurationString(seconds) {
|
|
242
|
+
if (isNaN(seconds))
|
|
243
|
+
throw new Error('Seconds must not be NaN');
|
|
244
|
+
seconds = Math.floor(seconds);
|
|
245
|
+
const absSeconds = Math.abs(seconds);
|
|
246
|
+
const minutes = Math.floor(absSeconds / 60);
|
|
247
|
+
const hours = Math.floor(minutes / 60);
|
|
248
|
+
let secondsValue = seconds % 60;
|
|
249
|
+
let minutesValue = minutes % 60;
|
|
250
|
+
let hoursValue = hours;
|
|
251
|
+
if (hoursValue === 0)
|
|
252
|
+
hoursValue = undefined;
|
|
253
|
+
if (minutesValue === 0)
|
|
254
|
+
minutesValue = undefined;
|
|
255
|
+
if (secondsValue === 0 && !(minutesValue === undefined && hoursValue === undefined))
|
|
256
|
+
secondsValue = undefined;
|
|
257
|
+
return formatDurationString(undefined, undefined, hoursValue, minutesValue, secondsValue);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Convert a number of days to a duration string.
|
|
261
|
+
* @param days How many days the duration should represent.
|
|
262
|
+
* @returns A string representing the duration in the format `P[n]D`, prefixed with `-` if negative.
|
|
263
|
+
* @throws {Error} If days is NaN.
|
|
264
|
+
*/
|
|
265
|
+
function daysToDurationString(days) {
|
|
266
|
+
return formatDurationString(undefined, days, undefined, undefined, undefined);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Convert a number of weeks to a duration string.
|
|
270
|
+
* @param weeks How many weeks the duration should represent.
|
|
271
|
+
* @returns A string representing the duration in the format `P[n]W`, prefixed with `-` if negative.
|
|
272
|
+
* @throws {Error} If weeks is NaN.
|
|
273
|
+
*/
|
|
274
|
+
function weeksToDurationString(weeks) {
|
|
275
|
+
return formatDurationString(weeks, undefined, undefined, undefined, undefined);
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=data: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UFZO0lBQzdDLE9BQU8sb0JBQW9CLENBQ3ZCLFNBQVMsRUFDVCxJQUFJLEVBQ0osU0FBUyxFQUNULFNBQVMsRUFDVCxTQUFTLENBQ1osQ0FBQTtBQUNMLENBQUM7QUFFRDs7Ozs7R0FLRztBQUNILFNBQWdCLHFCQUFxQixDQUFDLEtBQWE7SUFDL0MsT0FBTyxvQkFBb0IsQ0FDdkIsS0FBSyxFQUNMLFNBQVMsRUFDVCxTQUFTLEVBQ1QsU0FBUyxFQUNULFNBQVMsQ0FDWixDQUFBO0FBQ0wsQ0FBQyJ9
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,QAAQ,CAAA;AACtB,cAAc,MAAM,CAAA;AACpB,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA;AAC1B,cAAc,MAAM,CAAA;AACpB,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./component"), exports);
|
|
18
18
|
__exportStar(require("./components"), exports);
|
|
19
19
|
__exportStar(require("./date"), exports);
|
|
20
|
+
__exportStar(require("./duration"), exports);
|
|
20
21
|
__exportStar(require("./io"), exports);
|
|
21
22
|
__exportStar(require("./parse"), exports);
|
|
22
23
|
__exportStar(require("./property"), exports);
|
|
23
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
24
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDhDQUEyQjtBQUMzQiwrQ0FBNEI7QUFDNUIseUNBQXNCO0FBQ3RCLDZDQUEwQjtBQUMxQix1Q0FBb0I7QUFDcEIsMENBQXVCO0FBQ3ZCLDZDQUEwQiJ9
|
package/lib/io.d.ts
CHANGED
|
@@ -5,14 +5,34 @@ import { Calendar } from './components/Calendar';
|
|
|
5
5
|
* @param path Path to the file.
|
|
6
6
|
* @returns The calendar deserialized from the file.
|
|
7
7
|
* @throws {DeserializationError} If the file content is not a valid calendar.
|
|
8
|
+
* @deprecated Use `loadCalendarSync` instead.
|
|
8
9
|
*/
|
|
9
10
|
export declare function load(path: fs.PathLike): Promise<Calendar>;
|
|
11
|
+
/**
|
|
12
|
+
* Read a calendar from a iCalendar file.
|
|
13
|
+
* @param path Path to the file.
|
|
14
|
+
* @param encoding The file encoding, defaults to UTF-8.
|
|
15
|
+
* @returns The calendar deserialized from the file.
|
|
16
|
+
* @throws {DeserializationError} If the file content is not a valid component.
|
|
17
|
+
* @throws {ComponentValidationError} If the deserialized component is not a VCALENDAR.
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadCalendarSync(path: fs.PathLike, encoding?: BufferEncoding): Calendar;
|
|
10
20
|
/**
|
|
11
21
|
* Write a calendar to a file.
|
|
12
22
|
* @param calendar The calendar to write to file.
|
|
13
23
|
* @param path Path to the file to write.
|
|
14
24
|
* @example
|
|
15
25
|
* dump(myCalendar, 'calendar.ics')
|
|
26
|
+
* @deprecated Use `dumpCalendarSync` instead.
|
|
16
27
|
*/
|
|
17
28
|
export declare function dump(calendar: Calendar, path: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Write a calendar to a file.
|
|
31
|
+
* @param calendar The calendar to write to file.
|
|
32
|
+
* @param path Path to the file to write.
|
|
33
|
+
* @param encoding The file encoding, defaults to UTF-8.
|
|
34
|
+
* @example
|
|
35
|
+
* dump(myCalendar, 'calendar.ics')
|
|
36
|
+
*/
|
|
37
|
+
export declare function dumpCalendarSync(calendar: Calendar, path: string, encoding?: BufferEncoding): void;
|
|
18
38
|
//# sourceMappingURL=io.d.ts.map
|
package/lib/io.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAQhD;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAc/D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC5B,IAAI,EAAE,EAAE,CAAC,QAAQ,EACjB,QAAQ,GAAE,cAAuB,GAClC,QAAQ,CAIV;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMpE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC5B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,cAAuB,GAClC,IAAI,CAGN"}
|
package/lib/io.js
CHANGED
|
@@ -4,7 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.load = load;
|
|
7
|
+
exports.loadCalendarSync = loadCalendarSync;
|
|
7
8
|
exports.dump = dump;
|
|
9
|
+
exports.dumpCalendarSync = dumpCalendarSync;
|
|
8
10
|
const fs_1 = __importDefault(require("fs"));
|
|
9
11
|
const readline_1 = __importDefault(require("readline"));
|
|
10
12
|
const Calendar_1 = require("./components/Calendar");
|
|
@@ -14,6 +16,7 @@ const parse_1 = require("./parse");
|
|
|
14
16
|
* @param path Path to the file.
|
|
15
17
|
* @returns The calendar deserialized from the file.
|
|
16
18
|
* @throws {DeserializationError} If the file content is not a valid calendar.
|
|
19
|
+
* @deprecated Use `loadCalendarSync` instead.
|
|
17
20
|
*/
|
|
18
21
|
async function load(path) {
|
|
19
22
|
const stream = fs_1.default.createReadStream(path);
|
|
@@ -27,12 +30,26 @@ async function load(path) {
|
|
|
27
30
|
}
|
|
28
31
|
return new Calendar_1.Calendar(component);
|
|
29
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Read a calendar from a iCalendar file.
|
|
35
|
+
* @param path Path to the file.
|
|
36
|
+
* @param encoding The file encoding, defaults to UTF-8.
|
|
37
|
+
* @returns The calendar deserialized from the file.
|
|
38
|
+
* @throws {DeserializationError} If the file content is not a valid component.
|
|
39
|
+
* @throws {ComponentValidationError} If the deserialized component is not a VCALENDAR.
|
|
40
|
+
*/
|
|
41
|
+
function loadCalendarSync(path, encoding = 'utf8') {
|
|
42
|
+
const text = fs_1.default.readFileSync(path, { encoding: encoding });
|
|
43
|
+
const component = (0, parse_1.deserializeComponentString)(text);
|
|
44
|
+
return new Calendar_1.Calendar(component);
|
|
45
|
+
}
|
|
30
46
|
/**
|
|
31
47
|
* Write a calendar to a file.
|
|
32
48
|
* @param calendar The calendar to write to file.
|
|
33
49
|
* @param path Path to the file to write.
|
|
34
50
|
* @example
|
|
35
51
|
* dump(myCalendar, 'calendar.ics')
|
|
52
|
+
* @deprecated Use `dumpCalendarSync` instead.
|
|
36
53
|
*/
|
|
37
54
|
function dump(calendar, path) {
|
|
38
55
|
return new Promise(resolve => {
|
|
@@ -41,4 +58,16 @@ function dump(calendar, path) {
|
|
|
41
58
|
});
|
|
42
59
|
});
|
|
43
60
|
}
|
|
44
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Write a calendar to a file.
|
|
63
|
+
* @param calendar The calendar to write to file.
|
|
64
|
+
* @param path Path to the file to write.
|
|
65
|
+
* @param encoding The file encoding, defaults to UTF-8.
|
|
66
|
+
* @example
|
|
67
|
+
* dump(myCalendar, 'calendar.ics')
|
|
68
|
+
*/
|
|
69
|
+
function dumpCalendarSync(calendar, path, encoding = 'utf8') {
|
|
70
|
+
const text = calendar.serialize();
|
|
71
|
+
fs_1.default.writeFileSync(path, text, { encoding: encoding });
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW8uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW8udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFpQkEsb0JBY0M7QUFVRCw0Q0FPQztBQVVELG9CQU1DO0FBVUQsNENBT0M7QUFqRkQsNENBQW1CO0FBQ25CLHdEQUErQjtBQUMvQixvREFBZ0Q7QUFDaEQsbUNBSWdCO0FBR2hCOzs7Ozs7R0FNRztBQUNJLEtBQUssVUFBVSxJQUFJLENBQUMsSUFBaUI7SUFDeEMsTUFBTSxNQUFNLEdBQUcsWUFBRSxDQUFDLGdCQUFnQixDQUFDLElBQUksQ0FBQyxDQUFBO0lBQ3hDLE1BQU0sS0FBSyxHQUFHLGtCQUFRLENBQUMsZUFBZSxDQUFDO1FBQ25DLEtBQUssRUFBRSxNQUFNO1FBQ2IsU0FBUyxFQUFFLFFBQVE7S0FDdEIsQ0FBQyxDQUFBO0lBRUYsTUFBTSxTQUFTLEdBQUc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FBUyxFQUFFLENBQUE7SUFDakMsWUFBRSxDQUFDLGFBQWEsQ0FBQyxJQUFJLEVBQUUsSUFBSSxFQUFFLEVBQUUsUUFBUSxFQUFFLFFBQVEsRUFBRSxDQUFDLENBQUE7QUFDeEQsQ0FBQyJ9
|
package/lib/parse.d.ts
CHANGED
|
@@ -11,27 +11,35 @@ export declare class DeserializationError extends Error {
|
|
|
11
11
|
* @param lines The serialized component as a **readline** interface.
|
|
12
12
|
* @returns The deserialized calendar component object.
|
|
13
13
|
* @throws {DeserializationError} If the component is invalid.
|
|
14
|
+
* @deprecated Use the synchronous `deserializeComponentLines` instead.
|
|
14
15
|
*/
|
|
15
16
|
export declare function deserializeComponent(lines: readline.Interface): Promise<Component>;
|
|
17
|
+
/**
|
|
18
|
+
* Deserialize a calendar component from a list of lines.
|
|
19
|
+
* @param lines The serialized component as a list of lines.
|
|
20
|
+
* @returns The deserialized calendar component object.
|
|
21
|
+
* @throws {DeserializationError} If the component is invalid.
|
|
22
|
+
*/
|
|
23
|
+
export declare function deserializeComponentLines(lines: string[]): Component;
|
|
16
24
|
/**
|
|
17
25
|
* Deserialize a calendar component string.
|
|
18
26
|
* @param text The serialized component.
|
|
19
27
|
* @returns The deserialized component object.
|
|
20
28
|
* @throws {DeserializationError} If the component is invalid.
|
|
21
29
|
*/
|
|
22
|
-
export declare function deserializeComponentString(text: string):
|
|
30
|
+
export declare function deserializeComponentString(text: string): Component;
|
|
23
31
|
/**
|
|
24
32
|
* Parse a serialized calendar.
|
|
25
33
|
* @param text A serialized calendar as you would see in an iCalendar file.
|
|
26
34
|
* @returns The parsed calendar object.
|
|
27
35
|
*/
|
|
28
|
-
export declare function parseCalendar(text: string):
|
|
36
|
+
export declare function parseCalendar(text: string): Calendar;
|
|
29
37
|
/**
|
|
30
38
|
* Parse a serialized calendar event.
|
|
31
39
|
* @param text A serialized event as you would see in an iCalendar file.
|
|
32
40
|
* @returns The parsed event object.
|
|
33
41
|
*/
|
|
34
|
-
export declare function parseEvent(text: string):
|
|
42
|
+
export declare function parseEvent(text: string): CalendarEvent;
|
|
35
43
|
/**
|
|
36
44
|
* Deserialize a component property.
|
|
37
45
|
* @param line The serialized content line that defines this property.
|
package/lib/parse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAMtD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAM9C,+EAA+E;AAC/E,qBAAa,oBAAqB,SAAQ,KAAK;IAC3C,IAAI,SAAyB;CAChC;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACtC,KAAK,EAAE,QAAQ,CAAC,SAAS,GAC1B,OAAO,CAAC,SAAS,CAAC,CAGpB;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAkHpE;AAqBD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAGlE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAGpD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAGtD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,OAAe,GACxB,QAAQ,CA8LV"}
|