calendaryjs 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 calendaryjs
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 ADDED
@@ -0,0 +1,187 @@
1
+ # calendaryjs
2
+
3
+ A lightweight, plugin-based calendar system for managing events in TypeScript. Inspired by [Day.js](https://github.com/iamkun/dayjs).
4
+
5
+ ## Features
6
+
7
+ - **πŸͺΆ Lightweight** - ~5KB core, tree-shakeable
8
+ - **πŸ”Œ Plugin System** - Day.js-style `extend()` API
9
+ - **πŸ“… Many Event Types** - const, fixed, monthly, weekly, nth-weekday, formula, relative (+ plugin types)
10
+ - **πŸ” Fluent Query API** - Chain methods for filtering
11
+ - **πŸ’Ύ Caching** - Memoized event generation
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add calendaryjs
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ### Factory API (Recommended)
22
+
23
+ Author events with the **builder** β€” it reads like a sentence and compiles to the
24
+ plain config shown under [Collections](#collections):
25
+
26
+ ```typescript
27
+ import { calendary } from "calendaryjs";
28
+ import { every, date } from "calendaryjs/builder";
29
+
30
+ const cal = calendary();
31
+
32
+ cal.addGroup({
33
+ id: "holidays",
34
+ name: "Holidays",
35
+ events: [
36
+ every("year").on(date(1, 1)).title("New Year"),
37
+ every("year").on(date(12, 25)).title("Christmas"),
38
+ ],
39
+ });
40
+
41
+ // Read events
42
+ cal.getEvents("2026-12-25");
43
+ cal.getEventsInRange("2026-01-01", "2026-12-31");
44
+
45
+ // Fluent query
46
+ cal.search().group("holidays").range("2026-01-01", "2026-12-31").getEvents();
47
+ ```
48
+
49
+ > Full grammar (`every`/`from`/`once`, positions, bounds, plugin selectors): the
50
+ > [builder guide](https://calendaryjs.dev/guides/builder/). Hand-writing the plain
51
+ > config also works β€” both compile to the same model.
52
+
53
+ ### Collections
54
+
55
+ Bundle events into a portable **collection** (a `.cdy` file is its JSON form) and
56
+ load it with `cal.load()`. It declares the plugins its events need; register those
57
+ first β€” `load()` validates them and errors clearly if any is missing.
58
+
59
+ ```typescript
60
+ import { calendary } from "calendaryjs";
61
+ import { lunar } from "calendaryjs-plugin-lunar";
62
+
63
+ const cal = calendary().use(lunar());
64
+
65
+ cal.load({
66
+ collection: "holidays",
67
+ plugins: ["calendaryjs-plugin-lunar"],
68
+ events: [
69
+ { type: "const", id: "new-year", month: 1, day: 1, title: "New Year" },
70
+ { type: "lunar", id: "lunar-new-year", lunarMonth: 1, lunarDay: 1, title: "Lunar New Year" },
71
+ ],
72
+ });
73
+
74
+ // …or from a .cdy (JSON) string, e.g. read from disk or fetched
75
+ cal.load(jsonString);
76
+ ```
77
+
78
+ ### Class-based API
79
+
80
+ > `Calendary` is an alias of the canonical `CalendaryInstance` class, kept for Day.js-style familiarity.
81
+
82
+ ```typescript
83
+ import { Calendary } from "calendaryjs";
84
+
85
+ const cal = new Calendary();
86
+
87
+ cal.addGroup({
88
+ id: "holidays",
89
+ name: "Holidays",
90
+ events: [
91
+ { type: "const", id: "newyear", month: 1, day: 1, title: "New Year" },
92
+ { type: "fixed", id: "wedding", year: 2025, month: 6, day: 15, title: "Wedding" },
93
+ ],
94
+ });
95
+ ```
96
+
97
+ ## Event Types
98
+
99
+ | Type | Description | Example |
100
+ | ------------- | ------------------------------------------ | ---------------------------- |
101
+ | `const` | Fixed annual date | Christmas (Dec 25) |
102
+ | `fixed` | One-time date | Wedding (Jun 15, 2025) |
103
+ | `monthly` | Same day every month (interval/exclusions) | Payday (15th) |
104
+ | `weekly` | Same weekday every week (interval/range) | Standup (Mon) |
105
+ | `nth-weekday` | Nth weekday of a month, or anchored | Thanksgiving (4th Thu / Nov) |
106
+ | `formula` | Custom formula | Last Monday of May |
107
+ | `relative` | Offset from a registered anchor | 49 days after an anchor |
108
+
109
+ Plugins add more types (e.g. `lunar`, `hijri`, `liturgical`).
110
+
111
+ ## Plugin System
112
+
113
+ ```typescript
114
+ import { calendary } from "calendaryjs";
115
+
116
+ // Extend with custom functionality
117
+ calendary.extend((option, C, d) => {
118
+ C.prototype.myMethod = function () {
119
+ return "custom method";
120
+ };
121
+ });
122
+
123
+ // Use plugins
124
+ import { lunar } from "calendaryjs-plugin-lunar";
125
+
126
+ const cal = calendary();
127
+ cal.use(lunar());
128
+ ```
129
+
130
+ ## Event Properties
131
+
132
+ Every event shares `BaseEventProperties` (below) plus its type-specific date fields.
133
+ **`id`, `type`, and `title` are required; everything else is optional.**
134
+
135
+ ### Identity & display
136
+
137
+ | Property | Type | Notes |
138
+ | ------------- | -------- | ------------------------------------------------------------------------------------------------------- |
139
+ | `id` | `string` | unique id β€” _required_ |
140
+ | `type` | `string` | `const` Β· `fixed` Β· `monthly` Β· `weekly` Β· `nth-weekday` Β· `formula` Β· `relative` Β· plugin β€” _required_ |
141
+ | `title` | `string` | _required_ |
142
+ | `description` | `string` | β€” |
143
+ | `location` | `string` | β€” |
144
+ | `url` | `string` | β€” |
145
+ | `icon` | `string` | emoji or glyph |
146
+ | `color` | `string` | β€” |
147
+
148
+ ### Timing
149
+
150
+ | Property | Type | Notes |
151
+ | ----------- | --------- | --------- |
152
+ | `allDay` | `boolean` | β€” |
153
+ | `startTime` | `string` | `"09:00"` |
154
+ | `endTime` | `string` | `"17:00"` |
155
+ | `duration` | `number` | β€” |
156
+
157
+ ### Classification
158
+
159
+ | Property | Type | Notes |
160
+ | ------------ | ------------------------------------------- | ---------------------------------------------------- |
161
+ | `keywords` | `string[]` | β€” |
162
+ | `categories` | `string[]` | β€” |
163
+ | `status` | `'confirmed' \| 'tentative' \| 'cancelled'` | β€” |
164
+ | `priority` | `number` | z-index on a shared day; higher = on top (default 0) |
165
+ | `source` | `string` | origin: plugin / feed / ICS subscription |
166
+ | `metadata` | `Record<string, unknown>` | arbitrary per-event data |
167
+ | `reminders` | `Reminder[]` | β€” |
168
+
169
+ ### Recurrence control
170
+
171
+ | Property | Type | Notes |
172
+ | --------------- | ------------------ | --------------------------------------------------------------- |
173
+ | `onConflict` | `ConflictResolver` | same-day conflict: keep / drop / reschedule |
174
+ | `overrideDates` | `OverrideDatesMap` | force-move an occurrence to another date |
175
+ | `exceptions` | `EventExceptions` | per-occurrence skip / override (ICS `EXDATE` / `RECURRENCE-ID`) |
176
+
177
+ ## Plugins
178
+
179
+ | Package | Description |
180
+ | --------------------------------------------------------------------------------------------------------- | ---------------------- |
181
+ | [calendaryjs-plugin-lunar](https://github.com/calendaryjs/calendaryjs/tree/main/packages/lunar) | Lunar calendar events |
182
+ | [calendaryjs-plugin-liturgical](https://github.com/calendaryjs/calendaryjs/tree/main/packages/liturgical) | Easter & offset events |
183
+ | [calendaryjs-plugin-hijri](https://github.com/calendaryjs/calendaryjs/tree/main/packages/hijri) | Islamic (Hijri) events |
184
+
185
+ ## License
186
+
187
+ MIT