afghan-datepicker 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +201 -2
- package/dist/index.cjs +3120 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +406 -0
- package/dist/index.d.ts +406 -0
- package/dist/index.js +3029 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +420 -0
- package/package.json +82 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abdul Sami Fazilyar
|
|
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,202 @@
|
|
|
1
|
-
#
|
|
1
|
+
# afghan-datepicker
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A TypeScript-first calendar engine, date utilities, and React date-picker
|
|
4
|
+
components for Afghan Solar Hijri, Iranian Jalali, and Gregorian calendars.
|
|
5
|
+
|
|
6
|
+
> **Development status:** This package is in active development and is not yet
|
|
7
|
+
> considered production-ready. It has not been published to npm. Calendar
|
|
8
|
+
> calculations, localization, utilities, `Calendar`, `DatePicker`, and
|
|
9
|
+
> `DateRangePicker` are implemented; month and year picker components remain
|
|
10
|
+
> planned.
|
|
11
|
+
|
|
12
|
+
## Supported calendars and locales
|
|
13
|
+
|
|
14
|
+
The calendar engine supports:
|
|
15
|
+
|
|
16
|
+
- Afghan Solar Hijri.
|
|
17
|
+
- Iranian Jalali.
|
|
18
|
+
- Gregorian.
|
|
19
|
+
|
|
20
|
+
Built-in locales are Afghan Dari (`fa-AF`), Afghan Pashto (`ps-AF`), Iranian
|
|
21
|
+
Persian (`fa-IR`), and English (`en`). Calendar selection and locale selection
|
|
22
|
+
are independent.
|
|
23
|
+
|
|
24
|
+
The core provides date conversion, leap-year checks, month lengths, validation,
|
|
25
|
+
weekday calculation, date arithmetic, comparison, and calendar boundaries.
|
|
26
|
+
Supported year ranges and algorithm sources are documented in
|
|
27
|
+
[calendar rules](./docs/calendar-rules.md).
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
The package is not published yet. After a release is available, install it with:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npm install afghan-datepicker
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Import the stylesheet separately when using the React components:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import "afghan-datepicker/styles.css";
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The styles are namespaced and do not require a CSS framework. See
|
|
44
|
+
[component styling](./docs/components.md#styling) for customization.
|
|
45
|
+
|
|
46
|
+
## React components
|
|
47
|
+
|
|
48
|
+
### Calendar
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { Calendar } from "afghan-datepicker";
|
|
52
|
+
import "afghan-datepicker/styles.css";
|
|
53
|
+
|
|
54
|
+
<Calendar
|
|
55
|
+
calendar="afghan"
|
|
56
|
+
locale="fa-AF"
|
|
57
|
+
value={{ year: 1405, month: 1, day: 1 }}
|
|
58
|
+
onChange={(date) => console.log(date)}
|
|
59
|
+
/>;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### DatePicker
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { DatePicker } from "afghan-datepicker";
|
|
66
|
+
|
|
67
|
+
<DatePicker
|
|
68
|
+
calendar="iranian"
|
|
69
|
+
locale="fa-IR"
|
|
70
|
+
defaultValue={{ year: 1405, month: 1, day: 1 }}
|
|
71
|
+
label="تاریخ"
|
|
72
|
+
/>;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### DateRangePicker
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { DateRangePicker } from "afghan-datepicker";
|
|
79
|
+
|
|
80
|
+
<DateRangePicker
|
|
81
|
+
calendar="gregorian"
|
|
82
|
+
locale="en"
|
|
83
|
+
minRangeDays={2}
|
|
84
|
+
maxRangeDays={14}
|
|
85
|
+
/>;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
All components support controlled or uncontrolled values. Calendar and locale
|
|
89
|
+
determine date arithmetic and displayed language/direction respectively. The
|
|
90
|
+
components support RTL locales as well as LTR English; direction is set from
|
|
91
|
+
the selected locale.
|
|
92
|
+
|
|
93
|
+
## Date utilities
|
|
94
|
+
|
|
95
|
+
Date operations take an explicit calendar and use calendar-aware arithmetic;
|
|
96
|
+
they do not rely on JavaScript `Date`, time zones, or daylight-saving rules.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import {
|
|
100
|
+
addDays,
|
|
101
|
+
addMonths,
|
|
102
|
+
convertDate,
|
|
103
|
+
differenceInYears,
|
|
104
|
+
isValidGregorianDate,
|
|
105
|
+
} from "afghan-datepicker";
|
|
106
|
+
|
|
107
|
+
addDays({ year: 1405, month: 1, day: 1 }, 1, "afghan");
|
|
108
|
+
addMonths({ year: 1395, month: 12, day: 30 }, 1, "iranian");
|
|
109
|
+
convertDate({ year: 1382, month: 1, day: 1 }, "afghan", "gregorian");
|
|
110
|
+
differenceInYears(
|
|
111
|
+
{ year: 2026, month: 3, day: 21 },
|
|
112
|
+
{ year: 2025, month: 3, day: 21 },
|
|
113
|
+
"gregorian",
|
|
114
|
+
);
|
|
115
|
+
isValidGregorianDate({ year: 2024, month: 2, day: 29 });
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Month and year arithmetic constrains missing target days by default; pass
|
|
119
|
+
`{ overflow: "reject" }` to throw instead. See
|
|
120
|
+
[date utilities](./docs/date-utilities.md) for boundaries, validation, and
|
|
121
|
+
complete semantics.
|
|
122
|
+
|
|
123
|
+
## Localization and numerals
|
|
124
|
+
|
|
125
|
+
The locale supplies translated interface text, month and weekday names,
|
|
126
|
+
direction, and a default numeral system. Override numerals with `"latin"`,
|
|
127
|
+
`"persian"`, or `"arabic"`:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import {
|
|
131
|
+
formatCalendarDate,
|
|
132
|
+
getLocaleDirection,
|
|
133
|
+
toLocalizedDigits,
|
|
134
|
+
} from "afghan-datepicker";
|
|
135
|
+
|
|
136
|
+
formatCalendarDate(
|
|
137
|
+
{ year: 1405, month: 1, day: 1 },
|
|
138
|
+
{ calendar: "afghan", locale: "fa-AF" },
|
|
139
|
+
); // "۱۴۰۵/۰۱/۰۱"
|
|
140
|
+
|
|
141
|
+
formatCalendarDate(
|
|
142
|
+
{ year: 1405, month: 1, day: 1 },
|
|
143
|
+
{ calendar: "afghan", locale: "en", format: "full" },
|
|
144
|
+
); // "Saturday, Hamal 1, 1405"
|
|
145
|
+
|
|
146
|
+
getLocaleDirection("fa-AF"); // "rtl"
|
|
147
|
+
toLocalizedDigits("1405/01/01", "latin"); // "1405/01/01"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
For example, `locale="fa-AF"` sets an RTL Afghan Dari interface, while
|
|
151
|
+
`locale="en"` sets an LTR English interface. Numeral display can be selected
|
|
152
|
+
independently with the `numerals` prop. See the
|
|
153
|
+
[localization guide](./docs/localization.md) for locale data, formatting, and
|
|
154
|
+
custom locale registration.
|
|
155
|
+
|
|
156
|
+
## TypeScript and compatibility
|
|
157
|
+
|
|
158
|
+
TypeScript declarations and public types are included. Import types such as
|
|
159
|
+
`CalendarDate`, `DateRange`, `CalendarProps`, and `DateRangePickerProps` from
|
|
160
|
+
the package root:
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
import type { CalendarDate, DateRange } from "afghan-datepicker";
|
|
164
|
+
|
|
165
|
+
const date: CalendarDate = { year: 1405, month: 1, day: 1 };
|
|
166
|
+
const range: DateRange = { start: date, end: null };
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The package targets ES2022 and declares React and React DOM peer support for
|
|
170
|
+
versions 18 and 19. SSR and hydration were smoke-tested for those versions;
|
|
171
|
+
there is not yet an automated cross-browser compatibility matrix or a
|
|
172
|
+
production-readiness guarantee.
|
|
173
|
+
|
|
174
|
+
## Development
|
|
175
|
+
|
|
176
|
+
Install dependencies with `npm ci`, then use:
|
|
177
|
+
|
|
178
|
+
```sh
|
|
179
|
+
npm run dev # Start the Vite playground
|
|
180
|
+
npm run build # Build ESM, CommonJS, declarations, and CSS assets
|
|
181
|
+
npm test # Run tests once
|
|
182
|
+
npm run test:watch # Run tests in watch mode
|
|
183
|
+
npm run typecheck # Type-check source, playground, and tests
|
|
184
|
+
npm run lint # Run ESLint
|
|
185
|
+
npm run format # Format project files with Prettier
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Contributing
|
|
189
|
+
|
|
190
|
+
Contributions are welcome. Keep calendar engines independent from React and
|
|
191
|
+
localization, avoid timezone-dependent calendar calculations, and include
|
|
192
|
+
focused tests for new behavior. See the
|
|
193
|
+
[component guide](./docs/components.md) and the calendar, localization, and
|
|
194
|
+
utility references linked above.
|
|
195
|
+
|
|
196
|
+
## Repository
|
|
197
|
+
|
|
198
|
+
[github.com/Abdulsami-hub/afghan-datepicker](https://github.com/Abdulsami-hub/afghan-datepicker)
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT. See [LICENSE](./LICENSE).
|