@moltenship/ics 0.0.0-stage → 1.0.0-rc.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Timofey Maximov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,183 @@
1
- # Temporary Holding Version
1
+ # @moltenship/ics
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Typed iCalendar (RFC 5545) parsing with native Temporal values. ICS text goes in; calendars,
4
+ events, to-dos, journals, free/busy and time zones come out, with dates as `Temporal` objects and
5
+ every deviation from the RFC reported as an issue with its line.
6
+
7
+ - **No dependencies.** It needs a runtime with native `Temporal` (Node.js 26+, or a global polyfill
8
+ you install yourself) and TypeScript's `ESNext` library.
9
+ - **Not tied to a calendar UI.** It doesn't import any other Moltenship package.
10
+ - **Standard Schema.** A parser is a [Standard Schema](https://standardschema.dev), and extension
11
+ properties take any Standard Schema validator (Zod, Valibot, ArkType…).
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pnpm add @moltenship/ics
17
+ ```
18
+
19
+ ## Parse a feed
20
+
21
+ ```ts
22
+ import { getEventEnd, parseIcs } from "@moltenship/ics";
23
+
24
+ const text = await (await fetch("https://example.com/team.ics")).text();
25
+ const { calendars, issues } = parseIcs(text);
26
+
27
+ for (const event of calendars[0]?.events ?? []) {
28
+ const end = getEventEnd(event);
29
+ console.log(event.summary, event.start, end);
30
+ }
31
+ ```
32
+
33
+ `parseIcs` is lenient: it keeps what it can, skips components it can't type (an event without UID
34
+ or DTSTART), and lists every problem in `issues`. Text without a VCALENDAR, empty text included,
35
+ is an error. Pass `{ strict: true }` to throw an `IcsParseError` on error-severity issues instead.
36
+
37
+ Bad data never throws on its own. An exception thrown by a callback you pass, `resolveTimeZone` or
38
+ an extension schema's `validate`, propagates out of `parse` unchanged: it's a bug in your code, not
39
+ a problem with the text.
40
+
41
+ ## Dates and times
42
+
43
+ DATE values are `Temporal.PlainDate`. DATE-TIME values are a union, so the type says what the file
44
+ said:
45
+
46
+ | `kind` | Written as | Value |
47
+ | ------------ | ----------------------------------- | ----------------------------------------- |
48
+ | `date` | `DTSTART;VALUE=DATE:20261012` | `date: Temporal.PlainDate` |
49
+ | `utc` | `DTSTART:20261012T090000Z` | `instant: Temporal.Instant` |
50
+ | `zoned` | `DTSTART;TZID=Europe/Berlin:…` | `zoned: Temporal.ZonedDateTime`, `wallTime`, `tzid` |
51
+ | `unresolved` | `DTSTART;TZID=Some Custom Zone:…` | `wallTime: Temporal.PlainDateTime`, `tzid` |
52
+ | `floating` | `DTSTART:20261012T090000` | `wallTime: Temporal.PlainDateTime` |
53
+
54
+ ```ts
55
+ import type { IcsDateValue } from "@moltenship/ics";
56
+
57
+ function startInstant(start: IcsDateValue, timeZone: string): Temporal.Instant {
58
+ switch (start.kind) {
59
+ case "utc":
60
+ return start.instant;
61
+ case "zoned":
62
+ return start.zoned.toInstant();
63
+ case "date":
64
+ return start.date.toZonedDateTime(timeZone).toInstant();
65
+ case "floating":
66
+ case "unresolved":
67
+ return start.wallTime.toZonedDateTime(timeZone).toInstant();
68
+ }
69
+ }
70
+ ```
71
+
72
+ A wall time inside a DST gap or fold resolves the way RFC 5545 §3.3.5 says, which is Temporal's
73
+ `compatible` disambiguation; `wallTime` keeps what the file wrote. Nothing falls back to the host's
74
+ time zone. A calendar's `X-WR-TIMEZONE` is available as `calendar.timeZone` if you want to apply it
75
+ to floating times.
76
+
77
+ ## Time zones
78
+
79
+ Temporal has no custom time zones, so each TZID is mapped to a time zone Temporal knows:
80
+
81
+ 1. your `resolveTimeZone(tzid, vtimezone)` option, if it returns an id Temporal knows (any other
82
+ answer falls through, like `undefined`);
83
+ 2. IANA ids, such as `Europe/Berlin`;
84
+ 3. vendor paths, such as `/mozilla.org/20050126_1/Europe/Berlin`;
85
+ 4. Windows ids and Outlook display names, such as `W. Europe Standard Time` or
86
+ `(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna`, through CLDR's mapping;
87
+ 5. the file's VTIMEZONE: its `X-LIC-LOCATION`, or a fixed offset when it observes no DST;
88
+ 6. offset names, such as `GMT+0100` or `UTC`.
89
+
90
+ When the file's VTIMEZONE observes DST, rules 2–4 and 6 skip zones that never change offset:
91
+ `TZID=EST` is Temporal's fixed −05:00 zone, but a VTIMEZONE named `EST` usually means New York. A
92
+ TZID that matches none of these stays `unresolved`, with an `unknown-time-zone` warning. It isn't
93
+ guessed.
94
+
95
+ ## Extension properties
96
+
97
+ Declare the `X-` properties you rely on, and they're decoded, validated and typed in `extensions`:
98
+
99
+ ```ts
100
+ import { createIcsParser, icsExtension } from "@moltenship/ics";
101
+ import { z } from "zod";
102
+
103
+ const parser = createIcsParser({
104
+ extensions: {
105
+ event: {
106
+ busyStatus: icsExtension("X-MICROSOFT-CDO-BUSYSTATUS", {
107
+ schema: z.enum(["FREE", "TENTATIVE", "BUSY", "OOF", "WORKINGELSEWHERE"]),
108
+ }),
109
+ resourceIds: icsExtension("X-RESOURCE-ID", { multiple: true }),
110
+ guests: icsExtension("X-EXAMPLE-GUESTS", { type: "INTEGER" }),
111
+ },
112
+ },
113
+ });
114
+
115
+ const { calendars } = parser.parse(text);
116
+ const event = calendars[0]!.events[0]!;
117
+ event.extensions.busyStatus; // "FREE" | "TENTATIVE" | … | undefined
118
+ event.extensions.resourceIds; // readonly string[]
119
+ event.extensions.guests; // number | undefined
120
+ ```
121
+
122
+ `type` picks the RFC 5545 value type used to decode the raw value (TEXT by default). `multiple`
123
+ collects every occurrence and every comma-separated value. A value the schema rejects is dropped
124
+ with an error-severity `schema` issue, so strict parsing throws and Standard Schema validation
125
+ fails. Schemas must validate synchronously.
126
+
127
+ To name the result's types in your own code, keep the `extensions` object in a constant: every
128
+ type takes it the same way, as in `IcsCalendar<typeof extensions>` or `IcsEvent<typeof extensions>`.
129
+
130
+ ## As a Standard Schema
131
+
132
+ A parser validates ICS text: it fails with the error-severity issues, or succeeds with the parse
133
+ result.
134
+
135
+ ```ts
136
+ const result = await parser["~standard"].validate(body);
137
+ if (result.issues) {
138
+ return { status: 400, errors: result.issues.map((issue) => issue.message) };
139
+ }
140
+ const { calendars } = result.value;
141
+ ```
142
+
143
+ ## Lower layers
144
+
145
+ When the typed model doesn't cover your data, drop down a layer:
146
+
147
+ - `parseIcsComponents(text)` returns a lossless tree of components and properties with raw
148
+ values, and `stringifyIcsComponents(tree)` writes it back (CRLF, folded at 75 octets).
149
+ - `decodeIcsValue(type, raw, context)` and `encodeIcsValue(type, value)` convert single values of
150
+ any RFC 5545 value type, and `icsValueTypeOf(property)` says which type a property has.
151
+ - `splitIcsValues(type, raw)` splits a list value, such as CATEGORIES or EXDATE, on its separating
152
+ commas; `decodeIcsValues(type, raw, context)` splits and decodes each item.
153
+ - `decodeIcsDateValue(raw, declared, context)` reads a DATE or DATE-TIME by its shape, as the
154
+ typed model does for DTSTART, DTEND and EXDATE.
155
+
156
+ Decoders never throw. They return `{ ok: false, message }`, or `{ ok: true, value }` with
157
+ `warnings` when they read a value leniently; each warning has the `code` the typed model would
158
+ report it under.
159
+
160
+ Typed components also keep every property and subcomponent they don't map in `otherProperties`
161
+ and `otherComponents`.
162
+
163
+ ## Not included yet
164
+
165
+ - Expanding recurrence rules into occurrences: rules are parsed into `IcsRecurrenceRule`, not
166
+ expanded. `@moltenship/calendar-recurrence` expands them: its `recurringEventsFromIcs` groups
167
+ parsed events into series, overrides and one-off events, ready for its expander. This package
168
+ stays standalone and doesn't depend on it.
169
+ - Writing ICS from typed objects.
170
+ - Byte input. Decode the text as UTF-8 first; a fold that splits a multi-byte character can't be
171
+ repaired after decoding.
172
+
173
+ ## Documentation
174
+
175
+ - [ICS reference](https://time.molten.sh/docs/api/ics)
176
+ - [Repository](https://github.com/Moltenship/time)
177
+
178
+ ## License
179
+
180
+ `MIT AND Unicode-3.0`. The code is MIT. The Windows time zone data is derived from Unicode CLDR and
181
+ is under the Unicode License v3; see
182
+ [THIRD-PARTY-NOTICES.md](https://github.com/Moltenship/time/blob/main/packages/ics/THIRD-PARTY-NOTICES.md).
183
+ The built code carries the same notice as a legal comment, which bundlers keep.
@@ -0,0 +1,49 @@
1
+ # Third-party notices
2
+
3
+ `@moltenship/ics` includes data derived from the Unicode Common Locale Data Repository (CLDR),
4
+ release 48.2: the Windows time zone mapping in `common/supplemental/windowsZones.xml` and the
5
+ IANA aliases in `common/bcp47/timezone.xml`. That data is licensed under the Unicode License v3:
6
+
7
+ ```text
8
+ UNICODE LICENSE V3
9
+
10
+ COPYRIGHT AND PERMISSION NOTICE
11
+
12
+ Copyright © 2004-2026 Unicode, Inc.
13
+
14
+ NOTICE TO USER: Carefully read the following legal agreement. BY
15
+ DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
16
+ SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
17
+ TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
18
+ DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
19
+
20
+ Permission is hereby granted, free of charge, to any person obtaining a
21
+ copy of data files and any associated documentation (the "Data Files") or
22
+ software and any associated documentation (the "Software") to deal in the
23
+ Data Files or Software without restriction, including without limitation
24
+ the rights to use, copy, modify, merge, publish, distribute, and/or sell
25
+ copies of the Data Files or Software, and to permit persons to whom the
26
+ Data Files or Software are furnished to do so, provided that either (a)
27
+ this copyright and permission notice appear with all copies of the Data
28
+ Files or Software, or (b) this copyright and permission notice appear in
29
+ associated Documentation.
30
+
31
+ THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
32
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
34
+ THIRD PARTY RIGHTS.
35
+
36
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
37
+ BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
38
+ OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39
+ WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
41
+ FILES OR SOFTWARE.
42
+
43
+ Except as contained in this notice, the name of a copyright holder shall
44
+ not be used in advertising or otherwise to promote the sale, use or other
45
+ dealings in these Data Files or Software without prior written
46
+ authorization of the copyright holder.
47
+
48
+ SPDX-License-Identifier: Unicode-3.0
49
+ ```