@gambhirpoudel/nepali-calendar-kit 1.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/LICENSE ADDED
File without changes
package/README.md ADDED
File without changes
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+
3
+ declare function adToBs(ad: Date): {
4
+ year: number;
5
+ month: number;
6
+ day: number;
7
+ };
8
+
9
+ declare function bsToAd(year: number, month: number, day: number): Date;
10
+
11
+ declare function useNepaliDate(adDate?: Date): {
12
+ bs: {
13
+ year: number;
14
+ month: number;
15
+ day: number;
16
+ };
17
+ toAD: () => Date;
18
+ };
19
+
20
+ interface NepaliCalendarProps {
21
+ date?: Date;
22
+ renderDay?: (day: number, month: number, year: number) => React.ReactNode;
23
+ }
24
+ declare const NepaliCalendar: React.FC<NepaliCalendarProps>;
25
+
26
+ interface DayCellProps {
27
+ day: number;
28
+ month: number;
29
+ year: number;
30
+ isSelected?: boolean;
31
+ render?: (day: number, month: number, year: number, isSelected?: boolean) => React.ReactNode;
32
+ }
33
+ declare const DayCell: React.FC<DayCellProps>;
34
+
35
+ interface MonthViewProps {
36
+ year: number;
37
+ month: number;
38
+ renderDay?: (day: number, month: number, year: number) => React.ReactNode;
39
+ }
40
+ declare const MonthView: React.FC<MonthViewProps>;
41
+
42
+ export { DayCell, MonthView, NepaliCalendar, adToBs, bsToAd, useNepaliDate };
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+
3
+ declare function adToBs(ad: Date): {
4
+ year: number;
5
+ month: number;
6
+ day: number;
7
+ };
8
+
9
+ declare function bsToAd(year: number, month: number, day: number): Date;
10
+
11
+ declare function useNepaliDate(adDate?: Date): {
12
+ bs: {
13
+ year: number;
14
+ month: number;
15
+ day: number;
16
+ };
17
+ toAD: () => Date;
18
+ };
19
+
20
+ interface NepaliCalendarProps {
21
+ date?: Date;
22
+ renderDay?: (day: number, month: number, year: number) => React.ReactNode;
23
+ }
24
+ declare const NepaliCalendar: React.FC<NepaliCalendarProps>;
25
+
26
+ interface DayCellProps {
27
+ day: number;
28
+ month: number;
29
+ year: number;
30
+ isSelected?: boolean;
31
+ render?: (day: number, month: number, year: number, isSelected?: boolean) => React.ReactNode;
32
+ }
33
+ declare const DayCell: React.FC<DayCellProps>;
34
+
35
+ interface MonthViewProps {
36
+ year: number;
37
+ month: number;
38
+ renderDay?: (day: number, month: number, year: number) => React.ReactNode;
39
+ }
40
+ declare const MonthView: React.FC<MonthViewProps>;
41
+
42
+ export { DayCell, MonthView, NepaliCalendar, adToBs, bsToAd, useNepaliDate };
package/dist/index.js ADDED
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
24
+ var __copyProps = (to, from, except, desc) => {
25
+ if (from && typeof from === "object" || typeof from === "function") {
26
+ for (let key of __getOwnPropNames(from))
27
+ if (!__hasOwnProp.call(to, key) && key !== except)
28
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29
+ }
30
+ return to;
31
+ };
32
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
+
34
+ // src/index.ts
35
+ var index_exports = {};
36
+ __export(index_exports, {
37
+ DayCell: () => DayCell,
38
+ MonthView: () => MonthView,
39
+ NepaliCalendar: () => NepaliCalendar,
40
+ adToBs: () => adToBs,
41
+ bsToAd: () => bsToAd,
42
+ useNepaliDate: () => useNepaliDate
43
+ });
44
+ module.exports = __toCommonJS(index_exports);
45
+
46
+ // src/core/constants.ts
47
+ var AD_ANCHOR = new Date(Date.UTC(1943, 3, 14));
48
+ var BS_ANCHOR = { year: 2e3, month: 1, day: 1 };
49
+
50
+ // src/data/bsMonthData.ts
51
+ var BS_MONTH_DATA = {
52
+ 1970: [31, 31, 32, 31, 31, 30, 30, 29, 30, 29, 30, 30],
53
+ 1971: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
54
+ 1972: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
55
+ 1973: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
56
+ 1974: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
57
+ 1975: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
58
+ 1976: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
59
+ 1977: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
60
+ 1978: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
61
+ 1979: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
62
+ 1980: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
63
+ 1981: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
64
+ 1982: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
65
+ 1983: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
66
+ 1984: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
67
+ 1985: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
68
+ 1986: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
69
+ 1987: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
70
+ 1988: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
71
+ 1989: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
72
+ 1990: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
73
+ 1991: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
74
+ 1992: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
75
+ 1993: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
76
+ 1994: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
77
+ 1995: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
78
+ 1996: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
79
+ 1997: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
80
+ 1998: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
81
+ 1999: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
82
+ 2e3: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
83
+ 2001: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
84
+ 2002: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
85
+ 2003: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
86
+ 2004: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
87
+ 2005: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
88
+ 2006: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
89
+ 2007: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
90
+ 2008: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
91
+ 2009: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
92
+ 2010: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
93
+ 2011: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
94
+ 2012: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
95
+ 2013: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
96
+ 2014: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
97
+ 2015: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
98
+ 2016: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
99
+ 2017: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
100
+ 2018: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
101
+ 2019: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
102
+ 2020: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
103
+ 2021: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
104
+ 2022: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
105
+ 2023: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
106
+ 2024: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
107
+ 2025: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
108
+ 2026: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
109
+ 2027: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
110
+ 2028: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
111
+ 2029: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
112
+ 2030: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
113
+ 2031: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
114
+ 2032: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
115
+ 2033: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
116
+ 2034: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
117
+ 2035: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
118
+ 2036: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
119
+ 2037: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
120
+ 2038: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
121
+ 2039: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
122
+ 2040: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
123
+ 2041: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
124
+ 2042: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
125
+ 2043: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
126
+ 2044: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
127
+ 2045: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
128
+ 2046: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
129
+ 2047: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
130
+ 2048: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
131
+ 2049: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
132
+ 2050: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
133
+ 2051: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
134
+ 2052: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
135
+ 2053: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
136
+ 2054: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
137
+ 2055: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
138
+ 2056: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
139
+ 2057: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
140
+ 2058: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
141
+ 2059: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
142
+ 2060: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
143
+ 2061: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
144
+ 2062: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
145
+ 2063: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
146
+ 2064: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
147
+ 2065: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
148
+ 2066: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
149
+ 2067: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
150
+ 2068: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
151
+ 2069: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
152
+ 2070: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
153
+ 2071: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
154
+ 2072: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
155
+ 2073: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
156
+ 2074: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
157
+ 2075: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
158
+ 2076: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
159
+ 2077: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
160
+ 2078: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
161
+ 2079: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
162
+ 2080: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
163
+ 2081: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
164
+ 2082: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
165
+ 2083: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
166
+ 2084: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
167
+ 2085: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
168
+ 2086: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
169
+ 2087: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
170
+ 2088: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
171
+ 2089: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
172
+ 2090: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
173
+ 2091: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
174
+ 2092: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
175
+ 2093: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
176
+ 2094: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
177
+ 2095: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
178
+ 2096: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
179
+ 2097: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
180
+ 2098: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
181
+ 2099: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
182
+ 2100: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
183
+ 2101: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
184
+ 2102: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
185
+ 2103: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
186
+ 2104: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
187
+ 2105: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
188
+ 2106: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
189
+ 2107: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
190
+ 2108: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
191
+ 2109: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
192
+ 2110: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
193
+ 2111: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
194
+ 2112: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
195
+ 2113: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
196
+ 2114: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
197
+ 2115: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
198
+ 2116: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
199
+ 2117: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
200
+ 2118: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
201
+ 2119: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
202
+ 2120: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
203
+ 2121: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
204
+ 2122: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
205
+ 2123: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
206
+ 2124: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31]
207
+ };
208
+
209
+ // src/core/adToBs.ts
210
+ function adToBs(ad) {
211
+ let days = Math.floor((ad.getTime() - AD_ANCHOR.getTime()) / 864e5);
212
+ let { year, month, day } = __spreadValues({}, BS_ANCHOR);
213
+ while (days > 0) {
214
+ const daysInMonth = BS_MONTH_DATA[year][month - 1];
215
+ day++;
216
+ if (day > daysInMonth) {
217
+ day = 1;
218
+ month++;
219
+ if (month > 12) {
220
+ month = 1;
221
+ year++;
222
+ }
223
+ }
224
+ days--;
225
+ }
226
+ return { year, month, day };
227
+ }
228
+
229
+ // src/core/bsToAd.ts
230
+ function bsToAd(year, month, day) {
231
+ let totalDays = 0;
232
+ for (let y = BS_ANCHOR.year; y < year; y++) {
233
+ totalDays += BS_MONTH_DATA[y].reduce((a, b) => a + b, 0);
234
+ }
235
+ for (let m = 1; m < month; m++) {
236
+ totalDays += BS_MONTH_DATA[year][m - 1];
237
+ }
238
+ totalDays += day - 1;
239
+ return new Date(AD_ANCHOR.getTime() + totalDays * 864e5);
240
+ }
241
+
242
+ // src/hooks/useNepaliDate.ts
243
+ function useNepaliDate(adDate = /* @__PURE__ */ new Date()) {
244
+ const bs = adToBs(adDate);
245
+ const toAD = () => bsToAd(bs.year, bs.month, bs.day);
246
+ return { bs, toAD };
247
+ }
248
+
249
+ // src/components/NepaliCalendar.tsx
250
+ var import_react = require("react");
251
+
252
+ // src/components/DayCell.tsx
253
+ var import_jsx_runtime = require("react/jsx-runtime");
254
+ var DayCell = ({ day, month, year, isSelected, render }) => {
255
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `day-cell ${isSelected ? "selected" : ""}`, children: render ? render(day, month, year, isSelected) : day });
256
+ };
257
+
258
+ // src/components/MonthView.tsx
259
+ var import_jsx_runtime2 = require("react/jsx-runtime");
260
+ var MonthView = ({ year, month, renderDay }) => {
261
+ const daysInMonth = BS_MONTH_DATA[year][month - 1];
262
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "month-view-grid", children: Array.from({ length: daysInMonth }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DayCell, { day: i + 1, month, year, render: renderDay }, i)) });
263
+ };
264
+
265
+ // src/components/NepaliCalendar.tsx
266
+ var import_jsx_runtime3 = require("react/jsx-runtime");
267
+ var NepaliCalendar = ({ date = /* @__PURE__ */ new Date(), renderDay }) => {
268
+ const [current, setCurrent] = (0, import_react.useState)(adToBs(date));
269
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "nepali-calendar", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MonthView, { year: current.year, month: current.month, renderDay }) });
270
+ };
271
+ // Annotate the CommonJS export names for ESM import in node:
272
+ 0 && (module.exports = {
273
+ DayCell,
274
+ MonthView,
275
+ NepaliCalendar,
276
+ adToBs,
277
+ bsToAd,
278
+ useNepaliDate
279
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,250 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ // src/core/constants.ts
19
+ var AD_ANCHOR = new Date(Date.UTC(1943, 3, 14));
20
+ var BS_ANCHOR = { year: 2e3, month: 1, day: 1 };
21
+
22
+ // src/data/bsMonthData.ts
23
+ var BS_MONTH_DATA = {
24
+ 1970: [31, 31, 32, 31, 31, 30, 30, 29, 30, 29, 30, 30],
25
+ 1971: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
26
+ 1972: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
27
+ 1973: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
28
+ 1974: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
29
+ 1975: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
30
+ 1976: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
31
+ 1977: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
32
+ 1978: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
33
+ 1979: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
34
+ 1980: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
35
+ 1981: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
36
+ 1982: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
37
+ 1983: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
38
+ 1984: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
39
+ 1985: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
40
+ 1986: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
41
+ 1987: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
42
+ 1988: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
43
+ 1989: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
44
+ 1990: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
45
+ 1991: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
46
+ 1992: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
47
+ 1993: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
48
+ 1994: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
49
+ 1995: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
50
+ 1996: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
51
+ 1997: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
52
+ 1998: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
53
+ 1999: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
54
+ 2e3: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
55
+ 2001: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
56
+ 2002: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
57
+ 2003: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
58
+ 2004: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
59
+ 2005: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
60
+ 2006: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
61
+ 2007: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
62
+ 2008: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
63
+ 2009: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
64
+ 2010: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
65
+ 2011: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
66
+ 2012: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
67
+ 2013: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
68
+ 2014: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
69
+ 2015: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
70
+ 2016: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
71
+ 2017: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
72
+ 2018: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
73
+ 2019: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
74
+ 2020: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
75
+ 2021: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
76
+ 2022: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
77
+ 2023: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
78
+ 2024: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
79
+ 2025: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
80
+ 2026: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
81
+ 2027: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
82
+ 2028: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
83
+ 2029: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
84
+ 2030: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
85
+ 2031: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
86
+ 2032: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
87
+ 2033: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
88
+ 2034: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
89
+ 2035: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
90
+ 2036: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
91
+ 2037: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
92
+ 2038: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
93
+ 2039: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
94
+ 2040: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
95
+ 2041: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
96
+ 2042: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
97
+ 2043: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
98
+ 2044: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
99
+ 2045: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
100
+ 2046: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
101
+ 2047: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
102
+ 2048: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
103
+ 2049: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
104
+ 2050: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
105
+ 2051: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
106
+ 2052: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
107
+ 2053: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
108
+ 2054: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
109
+ 2055: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
110
+ 2056: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
111
+ 2057: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
112
+ 2058: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
113
+ 2059: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
114
+ 2060: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
115
+ 2061: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
116
+ 2062: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
117
+ 2063: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
118
+ 2064: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
119
+ 2065: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
120
+ 2066: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
121
+ 2067: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
122
+ 2068: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
123
+ 2069: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
124
+ 2070: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
125
+ 2071: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
126
+ 2072: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
127
+ 2073: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
128
+ 2074: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
129
+ 2075: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
130
+ 2076: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
131
+ 2077: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
132
+ 2078: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
133
+ 2079: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
134
+ 2080: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
135
+ 2081: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
136
+ 2082: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
137
+ 2083: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
138
+ 2084: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
139
+ 2085: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
140
+ 2086: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
141
+ 2087: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
142
+ 2088: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
143
+ 2089: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
144
+ 2090: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
145
+ 2091: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
146
+ 2092: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
147
+ 2093: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
148
+ 2094: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
149
+ 2095: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
150
+ 2096: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
151
+ 2097: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
152
+ 2098: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
153
+ 2099: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
154
+ 2100: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
155
+ 2101: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
156
+ 2102: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
157
+ 2103: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
158
+ 2104: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
159
+ 2105: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
160
+ 2106: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
161
+ 2107: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
162
+ 2108: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
163
+ 2109: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
164
+ 2110: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
165
+ 2111: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
166
+ 2112: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
167
+ 2113: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
168
+ 2114: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
169
+ 2115: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
170
+ 2116: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
171
+ 2117: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
172
+ 2118: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
173
+ 2119: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
174
+ 2120: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
175
+ 2121: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
176
+ 2122: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
177
+ 2123: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
178
+ 2124: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31]
179
+ };
180
+
181
+ // src/core/adToBs.ts
182
+ function adToBs(ad) {
183
+ let days = Math.floor((ad.getTime() - AD_ANCHOR.getTime()) / 864e5);
184
+ let { year, month, day } = __spreadValues({}, BS_ANCHOR);
185
+ while (days > 0) {
186
+ const daysInMonth = BS_MONTH_DATA[year][month - 1];
187
+ day++;
188
+ if (day > daysInMonth) {
189
+ day = 1;
190
+ month++;
191
+ if (month > 12) {
192
+ month = 1;
193
+ year++;
194
+ }
195
+ }
196
+ days--;
197
+ }
198
+ return { year, month, day };
199
+ }
200
+
201
+ // src/core/bsToAd.ts
202
+ function bsToAd(year, month, day) {
203
+ let totalDays = 0;
204
+ for (let y = BS_ANCHOR.year; y < year; y++) {
205
+ totalDays += BS_MONTH_DATA[y].reduce((a, b) => a + b, 0);
206
+ }
207
+ for (let m = 1; m < month; m++) {
208
+ totalDays += BS_MONTH_DATA[year][m - 1];
209
+ }
210
+ totalDays += day - 1;
211
+ return new Date(AD_ANCHOR.getTime() + totalDays * 864e5);
212
+ }
213
+
214
+ // src/hooks/useNepaliDate.ts
215
+ function useNepaliDate(adDate = /* @__PURE__ */ new Date()) {
216
+ const bs = adToBs(adDate);
217
+ const toAD = () => bsToAd(bs.year, bs.month, bs.day);
218
+ return { bs, toAD };
219
+ }
220
+
221
+ // src/components/NepaliCalendar.tsx
222
+ import { useState } from "react";
223
+
224
+ // src/components/DayCell.tsx
225
+ import { jsx } from "react/jsx-runtime";
226
+ var DayCell = ({ day, month, year, isSelected, render }) => {
227
+ return /* @__PURE__ */ jsx("div", { className: `day-cell ${isSelected ? "selected" : ""}`, children: render ? render(day, month, year, isSelected) : day });
228
+ };
229
+
230
+ // src/components/MonthView.tsx
231
+ import { jsx as jsx2 } from "react/jsx-runtime";
232
+ var MonthView = ({ year, month, renderDay }) => {
233
+ const daysInMonth = BS_MONTH_DATA[year][month - 1];
234
+ return /* @__PURE__ */ jsx2("div", { className: "month-view-grid", children: Array.from({ length: daysInMonth }, (_, i) => /* @__PURE__ */ jsx2(DayCell, { day: i + 1, month, year, render: renderDay }, i)) });
235
+ };
236
+
237
+ // src/components/NepaliCalendar.tsx
238
+ import { jsx as jsx3 } from "react/jsx-runtime";
239
+ var NepaliCalendar = ({ date = /* @__PURE__ */ new Date(), renderDay }) => {
240
+ const [current, setCurrent] = useState(adToBs(date));
241
+ return /* @__PURE__ */ jsx3("div", { className: "nepali-calendar", children: /* @__PURE__ */ jsx3(MonthView, { year: current.year, month: current.month, renderDay }) });
242
+ };
243
+ export {
244
+ DayCell,
245
+ MonthView,
246
+ NepaliCalendar,
247
+ adToBs,
248
+ bsToAd,
249
+ useNepaliDate
250
+ };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@gambhirpoudel/nepali-calendar-kit",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.cjs.js",
6
+ "scripts": {
7
+ "build": "tsup src/index.ts --format esm,cjs --dts",
8
+ "test": "vitest run",
9
+ "dev": "tsup src/index.ts --format esm --watch"
10
+ },
11
+ "module": "dist/index.esm.js",
12
+ "types": "dist/index.d.ts",
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "ISC",
16
+ "type": "commonjs",
17
+ "dependencies": {
18
+ "react": "^19.2.3",
19
+ "react-dom": "^19.2.3"
20
+ },
21
+ "devDependencies": {
22
+ "@types/react": "^19.2.8",
23
+ "@types/react-dom": "^19.2.3",
24
+ "tsup": "^8.5.1",
25
+ "typescript": "^5.9.3",
26
+ "vitest": "^4.0.17"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/ZaddyAI/nepali-calendar-kit.git"
31
+ }
32
+ }
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+
3
+ interface DayCellProps {
4
+ day: number;
5
+ month: number;
6
+ year: number;
7
+ isSelected?: boolean;
8
+ render?: (day: number, month: number, year: number, isSelected?: boolean) => React.ReactNode;
9
+ }
10
+
11
+ export const DayCell: React.FC<DayCellProps> = ({ day, month, year, isSelected, render }) => {
12
+ return (
13
+ <div className={`day-cell ${isSelected ? "selected" : ""}`}>
14
+ {render ? render(day, month, year, isSelected) : day}
15
+ </div>
16
+ );
17
+ };
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import { DayCell } from "./DayCell";
3
+ import { BS_MONTH_DATA } from "../data/bsMonthData";
4
+
5
+ interface MonthViewProps {
6
+ year: number;
7
+ month: number;
8
+ renderDay?: (day: number, month: number, year: number) => React.ReactNode;
9
+ }
10
+
11
+ export const MonthView: React.FC<MonthViewProps> = ({ year, month, renderDay }) => {
12
+ const daysInMonth = BS_MONTH_DATA[year][month - 1];
13
+
14
+ return (
15
+ <div className="month-view-grid">
16
+ {Array.from({ length: daysInMonth }, (_, i) => (
17
+ <DayCell key={i} day={i + 1} month={month} year={year} render={renderDay} />
18
+ ))}
19
+ </div>
20
+ );
21
+ };
@@ -0,0 +1,19 @@
1
+ import React, { useState } from "react";
2
+ import { adToBs } from "../core/adToBs";
3
+ import { MonthView } from "./MonthView";
4
+
5
+ interface NepaliCalendarProps {
6
+ date?: Date;
7
+ renderDay?: (day: number, month: number, year: number) => React.ReactNode;
8
+ }
9
+
10
+ export const NepaliCalendar: React.FC<NepaliCalendarProps> = ({ date = new Date(), renderDay }) => {
11
+ const [current, setCurrent] = useState(adToBs(date));
12
+
13
+ return (
14
+ <div className="nepali-calendar">
15
+ <MonthView year={current.year} month={current.month} renderDay={renderDay} />
16
+ {/* You can extend with Month/Year navigation */}
17
+ </div>
18
+ );
19
+ };
@@ -0,0 +1,23 @@
1
+ import { AD_ANCHOR, BS_ANCHOR } from "./constants";
2
+ import { BS_MONTH_DATA } from "../data/bsMonthData";
3
+
4
+ export function adToBs(ad: Date) {
5
+ let days = Math.floor((ad.getTime() - AD_ANCHOR.getTime()) / 86400000);
6
+ let { year, month, day } = { ...BS_ANCHOR };
7
+
8
+ while (days > 0) {
9
+ const daysInMonth = BS_MONTH_DATA[year][month - 1];
10
+ day++;
11
+ if (day > daysInMonth) {
12
+ day = 1;
13
+ month++;
14
+ if (month > 12) {
15
+ month = 1;
16
+ year++;
17
+ }
18
+ }
19
+ days--;
20
+ }
21
+
22
+ return { year, month, day };
23
+ }
@@ -0,0 +1,18 @@
1
+ import { AD_ANCHOR, BS_ANCHOR } from "./constants";
2
+ import { BS_MONTH_DATA } from "../data/bsMonthData";
3
+
4
+ export function bsToAd(year: number, month: number, day: number): Date {
5
+ let totalDays = 0;
6
+
7
+ for (let y = BS_ANCHOR.year; y < year; y++) {
8
+ totalDays += BS_MONTH_DATA[y].reduce((a, b) => a + b, 0);
9
+ }
10
+
11
+ for (let m = 1; m < month; m++) {
12
+ totalDays += BS_MONTH_DATA[year][m - 1];
13
+ }
14
+
15
+ totalDays += day - 1;
16
+
17
+ return new Date(AD_ANCHOR.getTime() + totalDays * 86400000);
18
+ }
@@ -0,0 +1,4 @@
1
+ export const AD_ANCHOR = new Date(Date.UTC(1943, 3, 14)); // 1943-04-14
2
+ export const BS_ANCHOR = { year: 2000, month: 1, day: 1 };
3
+ export const MIN_BS_YEAR = 1970;
4
+ export const MAX_BS_YEAR = 2100;
@@ -0,0 +1,157 @@
1
+ export const BS_MONTH_DATA: Record<number, number[]> = {
2
+ 1970: [31, 31, 32, 31, 31, 30, 30, 29, 30, 29, 30, 30],
3
+ 1971: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
4
+ 1972: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
5
+ 1973: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
6
+ 1974: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
7
+ 1975: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
8
+ 1976: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
9
+ 1977: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
10
+ 1978: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
11
+ 1979: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
12
+ 1980: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
13
+ 1981: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
14
+ 1982: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
15
+ 1983: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
16
+ 1984: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
17
+ 1985: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
18
+ 1986: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
19
+ 1987: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
20
+ 1988: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
21
+ 1989: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
22
+ 1990: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
23
+ 1991: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
24
+ 1992: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
25
+ 1993: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
26
+ 1994: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
27
+ 1995: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
28
+ 1996: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
29
+ 1997: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
30
+ 1998: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
31
+ 1999: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
32
+ 2000: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
33
+ 2001: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
34
+ 2002: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
35
+ 2003: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
36
+ 2004: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
37
+ 2005: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
38
+ 2006: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
39
+ 2007: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
40
+ 2008: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
41
+ 2009: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
42
+ 2010: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
43
+ 2011: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
44
+ 2012: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
45
+ 2013: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
46
+ 2014: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
47
+ 2015: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
48
+ 2016: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
49
+ 2017: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
50
+ 2018: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
51
+ 2019: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
52
+ 2020: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
53
+ 2021: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
54
+ 2022: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
55
+ 2023: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
56
+ 2024: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
57
+ 2025: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
58
+ 2026: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
59
+ 2027: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
60
+ 2028: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
61
+ 2029: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
62
+ 2030: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
63
+ 2031: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
64
+ 2032: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
65
+ 2033: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
66
+ 2034: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
67
+ 2035: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
68
+ 2036: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
69
+ 2037: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
70
+ 2038: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
71
+ 2039: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
72
+ 2040: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
73
+ 2041: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
74
+ 2042: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
75
+ 2043: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
76
+ 2044: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
77
+ 2045: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
78
+ 2046: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
79
+ 2047: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
80
+ 2048: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
81
+ 2049: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
82
+ 2050: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
83
+ 2051: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
84
+ 2052: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
85
+ 2053: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
86
+ 2054: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
87
+ 2055: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
88
+ 2056: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
89
+ 2057: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
90
+ 2058: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
91
+ 2059: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
92
+ 2060: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
93
+ 2061: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
94
+ 2062: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
95
+ 2063: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
96
+ 2064: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
97
+ 2065: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
98
+ 2066: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
99
+ 2067: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
100
+ 2068: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
101
+ 2069: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
102
+ 2070: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
103
+ 2071: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
104
+ 2072: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
105
+ 2073: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
106
+ 2074: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
107
+ 2075: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
108
+ 2076: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
109
+ 2077: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
110
+ 2078: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
111
+ 2079: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
112
+ 2080: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
113
+ 2081: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
114
+ 2082: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
115
+ 2083: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
116
+ 2084: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
117
+ 2085: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
118
+ 2086: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
119
+ 2087: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
120
+ 2088: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
121
+ 2089: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
122
+ 2090: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
123
+ 2091: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
124
+ 2092: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
125
+ 2093: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
126
+ 2094: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
127
+ 2095: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
128
+ 2096: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
129
+ 2097: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
130
+ 2098: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
131
+ 2099: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
132
+ 2100: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
133
+ 2101: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
134
+ 2102: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
135
+ 2103: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
136
+ 2104: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
137
+ 2105: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
138
+ 2106: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
139
+ 2107: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
140
+ 2108: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
141
+ 2109: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
142
+ 2110: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
143
+ 2111: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
144
+ 2112: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
145
+ 2113: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
146
+ 2114: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
147
+ 2115: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
148
+ 2116: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
149
+ 2117: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
150
+ 2118: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
151
+ 2119: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
152
+ 2120: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
153
+ 2121: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
154
+ 2122: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
155
+ 2123: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
156
+ 2124: [31, 31, 32, 31, 32, 30, 29, 30, 29, 30, 29, 31],
157
+ };
@@ -0,0 +1,10 @@
1
+ import { adToBs } from "../core/adToBs";
2
+ import { bsToAd } from "../core/bsToAd";
3
+
4
+ export function useNepaliDate(adDate: Date = new Date()) {
5
+ const bs = adToBs(adDate);
6
+
7
+ const toAD = () => bsToAd(bs.year, bs.month, bs.day);
8
+
9
+ return { bs, toAD };
10
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { adToBs } from "./core/adToBs";
2
+ export { bsToAd } from "./core/bsToAd";
3
+ export { useNepaliDate } from "./hooks/useNepaliDate";
4
+ export { NepaliCalendar } from "./components/NepaliCalendar";
5
+ export { DayCell } from "./components/DayCell";
6
+ export { MonthView } from "./components/MonthView";
@@ -0,0 +1,13 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { adToBs } from "../src/core/adToBs";
3
+ import { bsToAd } from "../src/core/bsToAd";
4
+
5
+ describe("AD ↔ BS Conversion Reversibility", () => {
6
+ it("AD → BS → AD returns the same AD date", () => {
7
+ const ad = new Date("2025-01-13");
8
+ const bs = adToBs(ad);
9
+ const back = bsToAd(bs.year, bs.month, bs.day);
10
+
11
+ expect(back.toISOString()).toBe(ad.toISOString());
12
+ });
13
+ });
@@ -0,0 +1,14 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { adToBs } from "../src/core/adToBs";
3
+ import { bsToAd } from "../src/core/bsToAd";
4
+
5
+ describe("AD ↔ BS Conversion Reversibility", () => {
6
+ it("AD → BS → AD should return the same AD date", () => {
7
+ const ad = new Date("2025-01-13");
8
+ const bs = adToBs(ad);
9
+ const back = bsToAd(bs.year, bs.month, bs.day);
10
+
11
+ expect(back.toISOString()).toBe(ad.toISOString());
12
+ });
13
+ });
14
+
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES6",
4
+ "module": "ESNext",
5
+ "declaration": true,
6
+ "outDir": "dist",
7
+ "strict": true,
8
+ "jsx": "react-jsx",
9
+ "moduleResolution": "node",
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true
13
+ },
14
+ "include": ["src"]
15
+ }
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: "jsdom",
7
+ },
8
+ });