@gambhirpoudel/nepali-calendar-kit 1.0.0 → 1.0.3

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.

Potentially problematic release.


This version of @gambhirpoudel/nepali-calendar-kit might be problematic. Click here for more details.

@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ interface Props {
3
+ day: number;
4
+ month: number;
5
+ year: number;
6
+ renderDay?: (day: number, month: number, year: number) => React.ReactNode;
7
+ }
8
+ export declare const DayCell: React.FC<Props>;
9
+ export {};
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export const DayCell = ({ day, month, year, renderDay }) => {
3
+ return (_jsx("div", { className: "nepali-day", children: renderDay ? renderDay(day, month, year) : day }));
4
+ };
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ interface Props {
3
+ year: number;
4
+ month: number;
5
+ renderDay?: (day: number, month: number, year: number) => React.ReactNode;
6
+ }
7
+ export declare const MonthView: React.FC<Props>;
8
+ export {};
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { DayCell } from "./DayCell";
3
+ import { BS_MONTH_DATA } from "../data/bsMonthData";
4
+ export const MonthView = ({ year, month, renderDay }) => {
5
+ const days = BS_MONTH_DATA[year]?.[month] ?? 30;
6
+ return (_jsx("div", { className: "nepali-month", children: Array.from({ length: days }, (_, i) => (_jsx(DayCell, { day: i + 1, month: month, year: year, renderDay: renderDay }, i))) }));
7
+ };
@@ -0,0 +1,6 @@
1
+ export interface NepaliCalendarProps {
2
+ date?: Date;
3
+ renderDay?: (day: number, month: number, year: number) => React.ReactNode;
4
+ className?: string;
5
+ }
6
+ export declare const NepaliCalendar: React.FC<NepaliCalendarProps>;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { adToBs } from "../core/adToBs";
3
+ import { MonthView } from "./MonthView";
4
+ import { useState } from "react";
5
+ export const NepaliCalendar = ({ date = new Date(), renderDay, className, }) => {
6
+ const [current] = useState(adToBs(date));
7
+ return (_jsx("div", { className: className ?? "nepali-calendar", children: _jsx(MonthView, { year: current.year, month: current.month, renderDay: renderDay }) }));
8
+ };
@@ -0,0 +1,5 @@
1
+ export declare function adToBs(ad: Date): {
2
+ year: number;
3
+ month: number;
4
+ day: number;
5
+ };
@@ -0,0 +1,20 @@
1
+ import { AD_ANCHOR, BS_ANCHOR } from "./constants";
2
+ import { BS_MONTH_DATA } from "../data/bsMonthData";
3
+ export function adToBs(ad) {
4
+ let days = Math.floor((ad.getTime() - AD_ANCHOR.getTime()) / 86400000);
5
+ let { year, month, day } = { ...BS_ANCHOR };
6
+ while (days > 0) {
7
+ const daysInMonth = BS_MONTH_DATA[year][month - 1];
8
+ day++;
9
+ if (day > daysInMonth) {
10
+ day = 1;
11
+ month++;
12
+ if (month > 12) {
13
+ month = 1;
14
+ year++;
15
+ }
16
+ }
17
+ days--;
18
+ }
19
+ return { year, month, day };
20
+ }
@@ -0,0 +1 @@
1
+ export declare function bsToAd(year: number, month: number, day: number): Date;
@@ -0,0 +1,13 @@
1
+ import { AD_ANCHOR, BS_ANCHOR } from "./constants";
2
+ import { BS_MONTH_DATA } from "../data/bsMonthData";
3
+ export function bsToAd(year, month, day) {
4
+ let totalDays = 0;
5
+ for (let y = BS_ANCHOR.year; y < year; y++) {
6
+ totalDays += BS_MONTH_DATA[y].reduce((a, b) => a + b, 0);
7
+ }
8
+ for (let m = 1; m < month; m++) {
9
+ totalDays += BS_MONTH_DATA[year][m - 1];
10
+ }
11
+ totalDays += day - 1;
12
+ return new Date(AD_ANCHOR.getTime() + totalDays * 86400000);
13
+ }
@@ -0,0 +1,8 @@
1
+ export declare const AD_ANCHOR: Date;
2
+ export declare const BS_ANCHOR: {
3
+ year: number;
4
+ month: number;
5
+ day: number;
6
+ };
7
+ export declare const MIN_BS_YEAR = 1970;
8
+ export declare const MAX_BS_YEAR = 2100;
@@ -1,4 +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;
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 @@
1
+ export declare const BS_MONTH_DATA: Record<number, number[]>;
@@ -0,0 +1,157 @@
1
+ export const BS_MONTH_DATA = {
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,8 @@
1
+ export declare function useNepaliDate(adDate?: Date): {
2
+ bs: {
3
+ year: number;
4
+ month: number;
5
+ day: number;
6
+ };
7
+ toAD: () => Date;
8
+ };
@@ -0,0 +1,12 @@
1
+ import { adToBs } from "../core/adToBs";
2
+ import { bsToAd } from "../core/bsToAd";
3
+ export function useNepaliDate(adDate = new Date()) {
4
+ const bs = adToBs(adDate);
5
+ const toAD = () => {
6
+ return bsToAd(bs.year, bs.month, bs.day);
7
+ };
8
+ return {
9
+ bs,
10
+ toAD,
11
+ };
12
+ }
package/dist/index.d.ts CHANGED
@@ -1,42 +1,6 @@
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 };
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 { MonthView } from "./components/MonthView";
6
+ export { DayCell } from "./components/DayCell";
package/dist/index.js CHANGED
@@ -1,279 +1,6 @@
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
- });
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 { MonthView } from "./components/MonthView";
6
+ export { DayCell } from "./components/DayCell";