iamcal 2.1.2 → 3.0.1

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.
Files changed (63) hide show
  1. package/lib/component.d.ts +25 -4
  2. package/lib/component.d.ts.map +1 -1
  3. package/lib/component.js +60 -51
  4. package/lib/components/Calendar.d.ts +0 -20
  5. package/lib/components/Calendar.d.ts.map +1 -1
  6. package/lib/components/Calendar.js +2 -24
  7. package/lib/components/CalendarEvent.d.ts +1 -25
  8. package/lib/components/CalendarEvent.d.ts.map +1 -1
  9. package/lib/components/CalendarEvent.js +4 -29
  10. package/lib/components/TimeZone.d.ts +0 -38
  11. package/lib/components/TimeZone.d.ts.map +1 -1
  12. package/lib/components/TimeZone.js +1 -40
  13. package/lib/components/TimeZoneOffset.d.ts +0 -28
  14. package/lib/components/TimeZoneOffset.d.ts.map +1 -1
  15. package/lib/components/TimeZoneOffset.js +1 -30
  16. package/lib/date.d.ts +2 -10
  17. package/lib/date.d.ts.map +1 -1
  18. package/lib/date.js +15 -20
  19. package/lib/parse.d.ts +9 -16
  20. package/lib/parse.d.ts.map +1 -1
  21. package/lib/parse.js +188 -35
  22. package/lib/patterns.d.ts +28 -0
  23. package/lib/patterns.d.ts.map +1 -1
  24. package/lib/patterns.js +56 -2
  25. package/lib/property/Property.d.ts +344 -0
  26. package/lib/property/Property.d.ts.map +1 -0
  27. package/lib/property/Property.js +508 -0
  28. package/lib/property/escape.d.ts +46 -0
  29. package/lib/property/escape.d.ts.map +1 -0
  30. package/lib/property/escape.js +129 -0
  31. package/lib/property/index.d.ts +7 -0
  32. package/lib/property/index.d.ts.map +1 -0
  33. package/lib/property/index.js +23 -0
  34. package/lib/property/names.d.ts +11 -0
  35. package/lib/property/names.d.ts.map +1 -0
  36. package/lib/property/names.js +62 -0
  37. package/lib/property/parameter.d.ts +10 -0
  38. package/lib/property/parameter.d.ts.map +1 -0
  39. package/lib/property/parameter.js +3 -0
  40. package/lib/{property.d.ts → property/validate.d.ts} +9 -35
  41. package/lib/property/validate.d.ts.map +1 -0
  42. package/lib/property/validate.js +317 -0
  43. package/lib/property/valueType.d.ts +18 -0
  44. package/lib/property/valueType.d.ts.map +1 -0
  45. package/lib/property/valueType.js +82 -0
  46. package/package.json +3 -1
  47. package/src/component.ts +58 -52
  48. package/src/components/Calendar.ts +6 -30
  49. package/src/components/CalendarEvent.ts +7 -33
  50. package/src/components/TimeZone.ts +3 -51
  51. package/src/components/TimeZoneOffset.ts +5 -40
  52. package/src/date.ts +14 -30
  53. package/src/parse.ts +212 -40
  54. package/src/patterns.ts +64 -0
  55. package/src/property/Property.ts +609 -0
  56. package/src/property/escape.ts +132 -0
  57. package/src/property/index.ts +6 -0
  58. package/src/property/names.ts +65 -0
  59. package/src/property/parameter.ts +33 -0
  60. package/src/{property.ts → property/validate.ts} +23 -204
  61. package/src/property/valueType.ts +87 -0
  62. package/lib/property.d.ts.map +0 -1
  63. package/lib/property.js +0 -450
@@ -0,0 +1,18 @@
1
+ import type { AllowedPropertyName, KnownPropertyName } from './names';
2
+ export declare const knownValueTypes: readonly ["BINARY", "BOOLEAN", "CAL-ADDRESS", "DATE", "DATE-TIME", "DURATION", "FLOAT", "INTEGER", "PERIOD", "RECUR", "TEXT", "TIME", "URI", "UTC-OFFSET"];
3
+ export type KnownValueType = (typeof knownValueTypes)[number];
4
+ export type AllowedValueType = KnownValueType | (string & {});
5
+ /**
6
+ * The value types that each known property supports as defined by the iCalendar
7
+ * specification. The first in the list is the default type.
8
+ */
9
+ export declare const supportedValueTypes: {
10
+ [name in KnownPropertyName]: KnownValueType[];
11
+ };
12
+ /**
13
+ * Get the default value type of a property based on its name.
14
+ * @param name The name of the property.
15
+ * @returns The default value type of the property, or `TEXT` if the property is unknown.
16
+ */
17
+ export declare function getDefaultValueType(name: AllowedPropertyName): KnownValueType;
18
+ //# sourceMappingURL=valueType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valueType.d.ts","sourceRoot":"","sources":["../../src/property/valueType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAErE,eAAO,MAAM,eAAe,4JAelB,CAAA;AACV,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AAC7D,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAE7D;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE;KAC7B,IAAI,IAAI,iBAAiB,GAAG,cAAc,EAAE;CAgDhD,CAAA;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,mBAAmB,GAAG,cAAc,CAK7E"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.supportedValueTypes = exports.knownValueTypes = void 0;
4
+ exports.getDefaultValueType = getDefaultValueType;
5
+ exports.knownValueTypes = [
6
+ 'BINARY',
7
+ 'BOOLEAN',
8
+ 'CAL-ADDRESS',
9
+ 'DATE',
10
+ 'DATE-TIME',
11
+ 'DURATION',
12
+ 'FLOAT',
13
+ 'INTEGER',
14
+ 'PERIOD',
15
+ 'RECUR',
16
+ 'TEXT',
17
+ 'TIME',
18
+ 'URI',
19
+ 'UTC-OFFSET',
20
+ ];
21
+ /**
22
+ * The value types that each known property supports as defined by the iCalendar
23
+ * specification. The first in the list is the default type.
24
+ */
25
+ exports.supportedValueTypes = {
26
+ CALSCALE: ['TEXT'],
27
+ METHOD: ['TEXT'],
28
+ PRODID: ['TEXT'],
29
+ VERSION: ['TEXT'],
30
+ ATTACH: ['URI', 'BINARY'],
31
+ CATEGORIES: ['TEXT'],
32
+ CLASS: ['TEXT'],
33
+ COMMENT: ['TEXT'],
34
+ DESCRIPTION: ['TEXT'],
35
+ GEO: ['FLOAT'],
36
+ LOCATION: ['TEXT'],
37
+ 'PERCENT-COMPLETE': ['INTEGER'],
38
+ PRIORITY: ['INTEGER'],
39
+ RESOURCES: ['TEXT'],
40
+ STATUS: ['TEXT'],
41
+ SUMMARY: ['TEXT'],
42
+ COMPLETED: ['DATE-TIME'],
43
+ DTEND: ['DATE-TIME', 'DATE'],
44
+ DUE: ['DATE-TIME', 'DATE'],
45
+ DTSTART: ['DATE-TIME', 'DATE'],
46
+ DURATION: ['DURATION'],
47
+ FREEBUSY: ['PERIOD'],
48
+ TRANSP: ['TEXT'],
49
+ TZID: ['TEXT'],
50
+ TZNAME: ['TEXT'],
51
+ TZOFFSETFROM: ['UTC-OFFSET'],
52
+ TZOFFSETTO: ['UTC-OFFSET'],
53
+ TZURL: ['URI'],
54
+ ATTENDEE: ['CAL-ADDRESS'],
55
+ CONTACT: ['TEXT'],
56
+ ORGANIZER: ['CAL-ADDRESS'],
57
+ 'RECURRENCE-ID': ['DATE-TIME', 'DATE'],
58
+ 'RELATED-TO': ['TEXT'],
59
+ URL: ['URI'],
60
+ UID: ['TEXT'],
61
+ EXDATE: ['DATE-TIME', 'DATE'],
62
+ RDATE: ['DATE-TIME', 'DATE', 'PERIOD'],
63
+ RRULE: ['RECUR'],
64
+ ACTION: ['TEXT'],
65
+ REPEAT: ['INTEGER'],
66
+ TRIGGER: ['DURATION', 'DATE-TIME'],
67
+ CREATED: ['DATE-TIME'],
68
+ DTSTAMP: ['DATE-TIME'],
69
+ 'LAST-MODIFIED': ['DATE-TIME'],
70
+ SEQUENCE: ['INTEGER'],
71
+ 'REQUEST-STATUS': ['TEXT'],
72
+ };
73
+ /**
74
+ * Get the default value type of a property based on its name.
75
+ * @param name The name of the property.
76
+ * @returns The default value type of the property, or `TEXT` if the property is unknown.
77
+ */
78
+ function getDefaultValueType(name) {
79
+ const defaultType = exports.supportedValueTypes[name.toUpperCase()]?.[0];
80
+ return defaultType ?? 'TEXT';
81
+ }
82
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidm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BRSxDQUFDLE9BQU8sQ0FBQztJQUNoQixNQUFNLEVBQUUsQ0FBQyxNQUFNLENBQUM7SUFDaEIsTUFBTSxFQUFFLENBQUMsU0FBUyxDQUFDO0lBQ25CLE9BQU8sRUFBRSxDQUFDLFVBQVUsRUFBRSxXQUFXLENBQUM7SUFDbEMsT0FBTyxFQUFFLENBQUMsV0FBVyxDQUFDO0lBQ3RCLE9BQU8sRUFBRSxDQUFDLFdBQVcsQ0FBQztJQUN0QixlQUFlLEVBQUUsQ0FBQyxXQUFXLENBQUM7SUFDOUIsUUFBUSxFQUFFLENBQUMsU0FBUyxDQUFDO0lBQ3JCLGdCQUFnQixFQUFFLENBQUMsTUFBTSxDQUFDO0NBQzdCLENBQUE7QUFFRDs7OztHQUlHO0FBQ0gsU0FBZ0IsbUJBQW1CLENBQUMsSUFBeUI7SUFDekQsTUFBTSxXQUFXLEdBQUcsMkJBQW1CLENBQ25DLElBQUksQ0FBQyxXQUFXLEVBQXVCLENBQzFDLEVBQUUsQ0FBQyxDQUFDLENBQStCLENBQUE7SUFDcEMsT0FBTyxXQUFXLElBQUksTUFBTSxDQUFBO0FBQ2hDLENBQUMifQ==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iamcal",
3
- "version": "2.1.2",
3
+ "version": "3.0.1",
4
4
  "description": "Read and write ICalendar files",
5
5
  "files": [
6
6
  "/lib",
@@ -39,8 +39,10 @@
39
39
  "devDependencies": {
40
40
  "@eslint/compat": "^1.3.1",
41
41
  "@eslint/js": "^9.32.0",
42
+ "@types/adm-zip": "^0.5.7",
42
43
  "@types/jest": "^30.0.0",
43
44
  "@types/node": "^22.10.1",
45
+ "adm-zip": "^0.5.16",
44
46
  "eslint": "^9.32.0",
45
47
  "eslint-plugin-jsdoc": "^52.0.2",
46
48
  "jest": "^30.0.5",
package/src/component.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import { CalendarDateOrTime } from './date'
2
+ import { Property } from './property/Property'
3
+ import type { AllowedPropertyName, KnownPropertyName } from './property/names'
2
4
  import {
3
- AllowedPropertyName,
4
- KnownPropertyName,
5
5
  MissingPropertyError,
6
- Property,
7
6
  PropertyValidationError,
8
7
  validateProperty,
9
- } from './property'
8
+ } from './property/validate'
10
9
 
11
- /** Represents an error which occurs while validating a calendar component. */
10
+ /**
11
+ * Represents an error which occurs while validating a calendar component.
12
+ */
12
13
  export class ComponentValidationError extends Error {
13
14
  constructor(message: string) {
14
15
  super(message)
@@ -16,9 +17,16 @@ export class ComponentValidationError extends Error {
16
17
  }
17
18
  }
18
19
 
19
- // Max line length as defined by RFC 5545 3.1.
20
- const MAX_LINE_LENGTH = 75
21
-
20
+ /**
21
+ * Represents an error which occurs when trying to perform an operation which
22
+ * would break the state of a calendar component.
23
+ */
24
+ export class IllegalOperationError extends Error {
25
+ constructor(message: string) {
26
+ super(message)
27
+ this.name = 'IllegalOperationError'
28
+ }
29
+ }
22
30
  export class Component {
23
31
  name: string
24
32
  properties: Property[]
@@ -31,7 +39,10 @@ export class Component {
31
39
  ) {
32
40
  this.name = name
33
41
  if (properties) {
34
- this.properties = properties
42
+ this.properties = []
43
+ properties.forEach(property => {
44
+ this.addProperty(property)
45
+ })
35
46
  } else {
36
47
  this.properties = []
37
48
  }
@@ -47,17 +58,7 @@ export class Component {
47
58
  const lines = [`BEGIN:${this.name}`]
48
59
 
49
60
  for (const property of this.properties) {
50
- let line =
51
- property['name'] + //
52
- property.params.map(p => ';' + p).join('') +
53
- ':' +
54
- property['value']
55
-
56
- // Wrap lines
57
- while (line.length > MAX_LINE_LENGTH) {
58
- lines.push(line.substring(0, MAX_LINE_LENGTH))
59
- line = ' ' + line.substring(MAX_LINE_LENGTH)
60
- }
61
+ const line = property.serialize()
61
62
  lines.push(line)
62
63
  }
63
64
 
@@ -84,29 +85,52 @@ export class Component {
84
85
 
85
86
  setProperty(name: string, value: string | CalendarDateOrTime): this {
86
87
  for (const property of this.properties) {
87
- if (property.name === name) {
88
- if (typeof value === 'string') {
89
- property.value = value
90
- } else {
91
- const prop = value.toProperty(name)
92
- property.params = prop.params
93
- property.value = prop.value
94
- }
88
+ if (property.name !== name) continue
89
+
90
+ if (typeof value === 'string') {
91
+ property.value = value
95
92
  return this
96
93
  }
94
+
95
+ const dateProperty = Property.fromDate(name, value)
96
+
97
+ // Update value type
98
+ if (dateProperty.getValueType() === 'DATE')
99
+ property.setValueType('DATE')
100
+ else property.removeValueType()
101
+
102
+ // Update value
103
+ property.value = dateProperty.value
104
+
105
+ return this
97
106
  }
107
+ // Property is new
98
108
  this.properties.push(
99
109
  typeof value === 'string'
100
- ? {
101
- name: name,
102
- params: [],
103
- value: value,
104
- }
105
- : value.toProperty(name)
110
+ ? new Property(name, value)
111
+ : Property.fromDate(name, value)
106
112
  )
107
113
  return this
108
114
  }
109
115
 
116
+ /**
117
+ * Add a property to this component.
118
+ * @param property The property to add.
119
+ * @returns This component for chaining.
120
+ * @throws {IllegalOperationError} If the property cannot be added to this component.
121
+ */
122
+ addProperty(property: Property): this {
123
+ // TODO: Validate if property can be added to this component.
124
+ this.properties.push(property)
125
+ return this
126
+ }
127
+
128
+ /**
129
+ * Check whether this component has a certain property.
130
+ * @param name The property name to check.
131
+ * @param value An optional value to check against the property. If this is specified the property value must equal this value.
132
+ * @returns Whether the property is present and matches the value if given.
133
+ */
110
134
  hasProperty(name: string, value?: string): boolean {
111
135
  for (const property of this.properties) {
112
136
  if (
@@ -126,24 +150,6 @@ export class Component {
126
150
  this.properties.splice(index, 1)
127
151
  }
128
152
 
129
- getPropertyParams(name: string): string[] | null {
130
- for (const property of this.properties) {
131
- if (property.name === name) {
132
- return property.params
133
- }
134
- }
135
- return null
136
- }
137
-
138
- setPropertyParams(name: string, params: string[]): this {
139
- for (const property of this.properties) {
140
- if (property.name === name) {
141
- property.params = params
142
- }
143
- }
144
- return this
145
- }
146
-
147
153
  addComponent(component: Component): this {
148
154
  this.components.push(component)
149
155
  return this
@@ -1,4 +1,4 @@
1
- import { KnownPropertyName } from '../property'
1
+ import { KnownPropertyName } from '../property/names'
2
2
  import { Component, ComponentValidationError } from '../component'
3
3
  import { CalendarEvent } from './CalendarEvent'
4
4
 
@@ -27,13 +27,13 @@ export class Calendar extends Component {
27
27
  * @param component A VCALENDAR component.
28
28
  */
29
29
  constructor(component: Component)
30
- constructor(a?: string | Component, b?: string) {
30
+ constructor(a: string | Component, b?: string) {
31
31
  let component: Component
32
32
  if (a instanceof Component) {
33
- component = a as Component
33
+ component = a
34
34
  Calendar.prototype.validate.call(component)
35
35
  } else {
36
- const prodid = a as string
36
+ const prodid = a
37
37
  const version = (b as string) ?? '2.0'
38
38
  component = new Component('VCALENDAR')
39
39
  component.setProperty('PRODID', prodid)
@@ -61,10 +61,9 @@ export class Calendar extends Component {
61
61
  removeEvent(uid: string): boolean
62
62
  removeEvent(a: CalendarEvent | string): boolean {
63
63
  if (a instanceof CalendarEvent) {
64
- const event = a as CalendarEvent
65
- return this.removeComponent(event)
64
+ return this.removeComponent(a)
66
65
  } else {
67
- const uid = a as string
66
+ const uid = a
68
67
  for (const event of this.getEvents()) {
69
68
  if (event.getUid() !== uid) continue
70
69
  return this.removeComponent(event)
@@ -136,27 +135,4 @@ export class Calendar extends Component {
136
135
  removeCalendarDescription() {
137
136
  this.removePropertiesWithName('X-WR-CALDESC')
138
137
  }
139
-
140
- /* eslint-disable */
141
-
142
- /** @deprecated use {@link getEvents} instead */
143
- events = this.getEvents
144
- /** @deprecated use {@link getProductId} instead */
145
- prodId = this.getProductId
146
- /** @deprecated use {@link setProductId} instead */
147
- setProdId = this.setProductId
148
- /** @deprecated use {@link getVersion} instead */
149
- version = this.getVersion
150
- /** @deprecated use {@link getCalendarScale} instead */
151
- calScale = this.getCalendarScale
152
- /** @deprecated use {@link setCalendarScale} instead */
153
- setCalScale = this.setCalendarScale
154
- /** @deprecated use {@link removeCalendarScale} instead */
155
- removeCalScale = this.removeCalendarScale
156
- /** @deprecated use {@link getMethod} instead */
157
- method = this.getMethod
158
- /** @deprecated use {@link getCalendarName} instead */
159
- calendarName = this.getCalendarName
160
- /** @deprecated use {@link getCalendarDescription} instead */
161
- calendarDescription = this.getCalendarDescription
162
138
  }
@@ -1,12 +1,13 @@
1
- import { KnownPropertyName, PropertyValidationError } from '../property'
2
- import { ComponentValidationError, Component } from '../component'
1
+ import { Component, ComponentValidationError } from '../component'
3
2
  import {
3
+ CalendarDateOrTime,
4
4
  CalendarDateTime,
5
5
  convertDate,
6
- CalendarDateOrTime,
7
6
  parseDateProperty,
8
7
  toDateTimeString,
9
8
  } from '../date'
9
+ import { KnownPropertyName } from '../property/names'
10
+ import { PropertyValidationError } from '../property/validate'
10
11
 
11
12
  /**
12
13
  * Represents a VEVENT component, representing an event in a calendar.
@@ -27,10 +28,10 @@ export class CalendarEvent extends Component {
27
28
  ) {
28
29
  let component: Component
29
30
  if (a instanceof Component) {
30
- component = a as Component
31
+ component = a
31
32
  CalendarEvent.prototype.validate.call(component)
32
33
  } else {
33
- const uid = a as string
34
+ const uid = a
34
35
  const dtstamp = convertDate(b!, false)
35
36
  const dtstart = convertDate(c!)
36
37
  component = new Component('VEVENT')
@@ -42,7 +43,7 @@ export class CalendarEvent extends Component {
42
43
  }
43
44
 
44
45
  serialize(): string {
45
- if (!this.getEnd() && !this.duration()) {
46
+ if (!this.getEnd() && !this.getDuration()) {
46
47
  throw new Error(
47
48
  'Failed to serialize calendar event, end or duration must be set'
48
49
  )
@@ -240,31 +241,4 @@ export class CalendarEvent extends Component {
240
241
  removeGeographicLocation() {
241
242
  this.removePropertiesWithName('GEO')
242
243
  }
243
-
244
- /* eslint-disable */
245
-
246
- /** @deprecated use {@link getStamp} instead */
247
- stamp = this.getStamp
248
- /** @deprecated use {@link getUid} instead */
249
- uid = this.getUid
250
- /** @deprecated use {@link getSummary} instead */
251
- summary = this.getSummary
252
- /** @deprecated use {@link getDescription} instead */
253
- description = this.getDescription
254
- /** @deprecated use {@link getLocation} instead */
255
- location = this.getLocation
256
- /** @deprecated use {@link getStart} instead */
257
- start = this.getStart
258
- /** @deprecated use {@link getEnd} instead */
259
- end = this.getEnd
260
- /** @deprecated use {@link getDuration} instead */
261
- duration = this.getDuration
262
- /** @deprecated use {@link getCreated} instead */
263
- created = this.getCreated
264
- /** @deprecated use {@link getGeographicPosition} instead */
265
- geo = this.getGeographicPosition
266
- /** @deprecated use {@link setGeographicPosition} instead */
267
- setGeo = this.setGeographicPosition
268
- /** @deprecated use {@link removeGeographicLocation} instead */
269
- removeGeo = this.removeGeographicLocation
270
244
  }
@@ -1,6 +1,6 @@
1
1
  import { Component, ComponentValidationError } from '../component'
2
2
  import { CalendarDateOrTime, parseDateProperty } from '../date'
3
- import { KnownPropertyName } from '../property'
3
+ import { KnownPropertyName } from '../property/names'
4
4
  import { TimeZoneOffset } from './TimeZoneOffset'
5
5
 
6
6
  /**
@@ -14,10 +14,10 @@ export class TimeZone extends Component {
14
14
  constructor(a: string | Component) {
15
15
  let component: Component
16
16
  if (a instanceof Component) {
17
- component = a as Component
17
+ component = a
18
18
  TimeZone.prototype.validate.call(component)
19
19
  } else {
20
- const tzid = a as string
20
+ const tzid = a
21
21
  component = new Component('VTIMEZONE')
22
22
  component.setProperty('TZID', tzid)
23
23
  }
@@ -101,52 +101,4 @@ export class TimeZone extends Component {
101
101
  c => new TimeZoneOffset(c)
102
102
  )
103
103
  }
104
-
105
- /* eslint-disable */
106
-
107
- /**
108
- * @deprecated Use {@link getId} instead.
109
- */
110
- id = this.getId
111
-
112
- /**
113
- * @deprecated Use {@link getLastModified} instead.
114
- */
115
- lastMod = this.getLastModified
116
-
117
- /**
118
- * @deprecated Use {@link setLastModified} instead.
119
- */
120
- setLastMod = this.setLastModified
121
-
122
- /**
123
- * @deprecated Use {@link removeLastModified} instead.
124
- */
125
- removeLastMod = this.removeLastModified
126
-
127
- /**
128
- * @deprecated Use {@link getUrl} instead.
129
- */
130
- url = this.getUrl
131
-
132
- /**
133
- * Get all time offsets.
134
- * @returns An array of time zone offsets defined in this time zone.
135
- * @deprecated Use {@link getOffsets} instead.
136
- */
137
- offsets = this.getOffsets
138
-
139
- /**
140
- * Get standard/winter time offsets.
141
- * @returns An array of time zone offsets defined in this time zone that are of type STANDARD.
142
- * @deprecated Use {@link getStandardOffsets} instead.
143
- */
144
- standardOffsets = this.getStandardOffsets
145
-
146
- /**
147
- * Get daylight savings time offsets.
148
- * @returns An array of time zone offsets defined in this time zone that are of type DAYLIGHT.
149
- * @deprecated Use {@link getDaylightOffsets} instead.
150
- */
151
- daylightOffsets = this.getDaylightOffsets
152
104
  }
@@ -1,6 +1,6 @@
1
1
  import { Component, ComponentValidationError } from '../component'
2
2
  import { CalendarDateOrTime, convertDate, parseDateProperty } from '../date'
3
- import { AllowedPropertyName } from '../property'
3
+ import { AllowedPropertyName } from '../property/names'
4
4
 
5
5
  export const knownOffsetTypes = ['DAYLIGHT', 'STANDARD']
6
6
  export type OffsetType = (typeof knownOffsetTypes)[number]
@@ -32,13 +32,13 @@ export class TimeZoneOffset extends Component {
32
32
  ) {
33
33
  let component: Component
34
34
  if (a instanceof Component) {
35
- component = a as Component
35
+ component = a
36
36
  TimeZoneOffset.prototype.validate.call(component)
37
37
  } else {
38
- const name = a as OffsetType
38
+ const name: OffsetType = a
39
39
  const start = convertDate(b!)
40
- const offsetFrom = c as Offset
41
- const offsetTo = d as Offset
40
+ const offsetFrom = c!
41
+ const offsetTo = d!
42
42
  component = new Component(name)
43
43
  component.setProperty('DTSTART', start)
44
44
  component.setProperty('TZOFFSETFROM', offsetFrom)
@@ -149,39 +149,4 @@ export class TimeZoneOffset extends Component {
149
149
  removeTimeZoneName() {
150
150
  this.removePropertiesWithName('TZNAME')
151
151
  }
152
-
153
- /* eslint-disable */
154
-
155
- /**
156
- * Get the date or time when this time zone offset starts.
157
- * @returns The start date or time of this time zone offset.
158
- * @deprecated Use {@link getStart} instead.
159
- */
160
- start = this.getStart
161
-
162
- /**
163
- * Get the offset which is offset from during this time zone offset.
164
- * @returns The offset in a format such as "+0100" or "-0230".
165
- * @deprecated Use {@link getOffsetFrom} instead.
166
- */
167
- offsetFrom = this.getOffsetFrom
168
-
169
- /**
170
- * Get the offset which is offset to during this time zone offset.
171
- * @returns The offset in a format such as "+0100" or "-0230".
172
- * @deprecated Use {@link getOffsetTo} instead.
173
- */
174
- offsetTo = this.getOffsetTo
175
-
176
- /**
177
- * @deprecated Use {@link getComment} instead.
178
- */
179
- comment = this.getComment
180
-
181
- /**
182
- * Get the name of this time zone offset.
183
- * @returns The time zone offset name if it exists.
184
- * @deprecated Use {@link getTimeZoneName} instead.
185
- */
186
- timeZoneName = this.getTimeZoneName
187
152
  }
package/src/date.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as patterns from './patterns'
2
- import { getPropertyValueType, type Property } from './property'
2
+ import { Property } from './property/Property'
3
3
 
4
4
  export const ONE_SECOND_MS = 1000
5
5
  export const ONE_MINUTE_MS = 60 * ONE_SECOND_MS
@@ -7,12 +7,6 @@ export const ONE_HOUR_MS = 60 * ONE_MINUTE_MS
7
7
  export const ONE_DAY_MS = 24 * ONE_HOUR_MS
8
8
 
9
9
  export interface CalendarDateOrTime {
10
- /**
11
- * Create a property from this date.
12
- * @param name The name of the property.
13
- */
14
- toProperty(name: string): Property
15
-
16
10
  /**
17
11
  * Get the string value of this date.
18
12
  * @returns An iCalendar date or date-time string.
@@ -62,14 +56,6 @@ export class CalendarDate implements CalendarDateOrTime {
62
56
  this.date.setHours(0, 0, 0, 0)
63
57
  }
64
58
 
65
- toProperty(name: string): Property {
66
- return {
67
- name,
68
- params: ['VALUE=DATE'],
69
- value: this.getValue(),
70
- }
71
- }
72
-
73
59
  getValue(): string {
74
60
  return toDateString(this.date)
75
61
  }
@@ -106,14 +92,6 @@ export class CalendarDateTime implements CalendarDateOrTime {
106
92
  }
107
93
  }
108
94
 
109
- toProperty(name: string): Property {
110
- return {
111
- name,
112
- params: [],
113
- value: this.getValue(),
114
- }
115
- }
116
-
117
95
  getValue(): string {
118
96
  return toDateTimeString(this.date)
119
97
  }
@@ -208,24 +186,30 @@ export function padSeconds(seconds: number): string {
208
186
  /**
209
187
  * Parse a date property into a {@link CalendarDateOrTime}.
210
188
  * @param dateProperty The property to parse.
211
- * @param defaultType The default value type to be used if the property does not have an explicit value type.
212
189
  * @returns The parsed date as a {@link CalendarDateOrTime}.
213
190
  * @throws If the value is invalid for the value type.
214
191
  * @throws If the value type is not `DATE-TIME` or `DATE`.
215
192
  */
216
- export function parseDateProperty(
217
- dateProperty: Property,
218
- defaultType: 'DATE-TIME' | 'DATE' = 'DATE-TIME'
219
- ): CalendarDateOrTime {
193
+ export function parseDateProperty(dateProperty: Property): CalendarDateOrTime {
220
194
  const value = dateProperty.value
221
- const valueType = getPropertyValueType(dateProperty, defaultType)
195
+ const valueType = dateProperty.getValueType()
222
196
 
223
197
  if (valueType === 'DATE-TIME') {
224
198
  return new CalendarDateTime(value)
225
199
  } else if (valueType === 'DATE') {
226
200
  return new CalendarDate(value)
227
201
  } else {
228
- throw new Error(`Illegal value type for date '${valueType}'`)
202
+ const explicitValueType = dateProperty.hasValueType()
203
+ if (explicitValueType)
204
+ throw new Error(`Illegal value type for date '${valueType}'`)
205
+ else {
206
+ // Infer type based on shape
207
+ try {
208
+ return new CalendarDateTime(value)
209
+ } catch {
210
+ return new CalendarDate(value)
211
+ }
212
+ }
229
213
  }
230
214
  }
231
215