@sonill/nepali-dates 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 +376 -0
- package/data/README.md +84 -0
- package/data/calendar-data.json +105 -0
- package/data/reference-dates.json +50 -0
- package/dist/index.d.mts +371 -0
- package/dist/index.d.ts +371 -0
- package/dist/index.js +682 -0
- package/dist/index.mjs +624 -0
- package/package.json +62 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date format types for conversion output
|
|
3
|
+
*/
|
|
4
|
+
type DateFormat = 'object' | 'iso' | 'string' | 'array';
|
|
5
|
+
/**
|
|
6
|
+
* Date pattern types for string formatting
|
|
7
|
+
*/
|
|
8
|
+
type DatePattern = 'YYYY-MM-DD' | 'YYYY/MM/DD' | 'DD-MM-YYYY' | 'DD/MM/YYYY' | 'MM-DD-YYYY' | 'MM/DD/YYYY';
|
|
9
|
+
/**
|
|
10
|
+
* Locale types for month/day names
|
|
11
|
+
*/
|
|
12
|
+
type Locale = 'en' | 'ne';
|
|
13
|
+
/**
|
|
14
|
+
* Date object representation
|
|
15
|
+
*/
|
|
16
|
+
interface DateObject {
|
|
17
|
+
year: number;
|
|
18
|
+
month: number;
|
|
19
|
+
day: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Date array representation [year, month, day]
|
|
23
|
+
*/
|
|
24
|
+
type DateArray = [number, number, number];
|
|
25
|
+
/**
|
|
26
|
+
* Options for date conversion
|
|
27
|
+
*/
|
|
28
|
+
interface ConversionOptions {
|
|
29
|
+
format?: DateFormat;
|
|
30
|
+
pattern?: DatePattern;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Options for date formatting
|
|
34
|
+
*/
|
|
35
|
+
interface FormatOptions {
|
|
36
|
+
pattern?: DatePattern;
|
|
37
|
+
locale?: Locale;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Calendar data structure: year -> array of days in each month
|
|
41
|
+
*/
|
|
42
|
+
type CalendarData = Record<number, number[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Reference date pair for validation
|
|
45
|
+
*/
|
|
46
|
+
interface ReferenceDatePair {
|
|
47
|
+
bs: DateObject;
|
|
48
|
+
ad: DateObject;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Data range information
|
|
52
|
+
*/
|
|
53
|
+
interface DataRange {
|
|
54
|
+
minYear: number;
|
|
55
|
+
maxYear: number;
|
|
56
|
+
totalYears: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Month navigation result
|
|
60
|
+
*/
|
|
61
|
+
interface MonthNavigation {
|
|
62
|
+
year: number;
|
|
63
|
+
month: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Nepali month names
|
|
67
|
+
*/
|
|
68
|
+
declare enum NepaliMonth {
|
|
69
|
+
Baisakh = 1,
|
|
70
|
+
Jestha = 2,
|
|
71
|
+
Ashar = 3,
|
|
72
|
+
Shrawan = 4,
|
|
73
|
+
Bhadra = 5,
|
|
74
|
+
Ashwin = 6,
|
|
75
|
+
Kartik = 7,
|
|
76
|
+
Mangsir = 8,
|
|
77
|
+
Poush = 9,
|
|
78
|
+
Magh = 10,
|
|
79
|
+
Falgun = 11,
|
|
80
|
+
Chaitra = 12
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Nepali month names in English
|
|
84
|
+
*/
|
|
85
|
+
declare const NEPALI_MONTH_NAMES_EN: Record<number, string>;
|
|
86
|
+
/**
|
|
87
|
+
* Nepali month names in Nepali
|
|
88
|
+
*/
|
|
89
|
+
declare const NEPALI_MONTH_NAMES_NE: Record<number, string>;
|
|
90
|
+
/**
|
|
91
|
+
* English month names
|
|
92
|
+
*/
|
|
93
|
+
declare const ENGLISH_MONTH_NAMES: Record<number, string>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Convert Bikram Sambat (BS) date to Anno Domini (AD) date
|
|
97
|
+
*
|
|
98
|
+
* @param year - BS year
|
|
99
|
+
* @param month - BS month (1-12)
|
|
100
|
+
* @param day - BS day
|
|
101
|
+
* @param options - Conversion options
|
|
102
|
+
* @returns AD date in specified format
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* bsToAd(2080, 10, 15); // Returns { year: 2024, month: 1, day: 27 }
|
|
106
|
+
* bsToAd(2080, 10, 15, { format: 'iso' }); // Returns "2024-01-27"
|
|
107
|
+
* bsToAd(2080, 10, 15, { format: 'array' }); // Returns [2024, 1, 27]
|
|
108
|
+
*/
|
|
109
|
+
declare function bsToAd(year: number, month: number, day: number, options?: ConversionOptions): DateObject | string | DateArray;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Convert Anno Domini (AD) date to Bikram Sambat (BS) date
|
|
113
|
+
*
|
|
114
|
+
* @param year - AD year
|
|
115
|
+
* @param month - AD month (1-12)
|
|
116
|
+
* @param day - AD day
|
|
117
|
+
* @param options - Conversion options
|
|
118
|
+
* @returns BS date in specified format
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* adToBs(2024, 1, 27); // Returns { year: 2080, month: 10, day: 15 }
|
|
122
|
+
* adToBs(2024, 1, 27, { format: 'iso' }); // Returns "2080-10-15"
|
|
123
|
+
* adToBs(2024, 1, 27, { format: 'array' }); // Returns [2080, 10, 15]
|
|
124
|
+
*/
|
|
125
|
+
declare function adToBs(year: number, month: number, day: number, options?: ConversionOptions): DateObject | string | DateArray;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get the total number of days in a Nepali month
|
|
129
|
+
*
|
|
130
|
+
* @param year - BS year
|
|
131
|
+
* @param month - BS month (1-12)
|
|
132
|
+
* @returns Number of days in the month
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* getTotalDaysInMonth(2080, 1); // Returns 31
|
|
136
|
+
*/
|
|
137
|
+
declare function getTotalDaysInMonth(year: number, month: number): number;
|
|
138
|
+
/**
|
|
139
|
+
* Get the total number of days in a Nepali year
|
|
140
|
+
*
|
|
141
|
+
* @param year - BS year
|
|
142
|
+
* @returns Total number of days in the year
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* getTotalDaysInYear(2080); // Returns 365
|
|
146
|
+
*/
|
|
147
|
+
declare function getTotalDaysInYear(year: number): number;
|
|
148
|
+
/**
|
|
149
|
+
* Get the next month
|
|
150
|
+
*
|
|
151
|
+
* @param year - BS year
|
|
152
|
+
* @param month - BS month (1-12)
|
|
153
|
+
* @returns Next month details
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* getNextMonth(2080, 12); // Returns { year: 2081, month: 1 }
|
|
157
|
+
* getNextMonth(2080, 6); // Returns { year: 2080, month: 7 }
|
|
158
|
+
*/
|
|
159
|
+
declare function getNextMonth(year: number, month: number): MonthNavigation;
|
|
160
|
+
/**
|
|
161
|
+
* Get the previous month
|
|
162
|
+
*
|
|
163
|
+
* @param year - BS year
|
|
164
|
+
* @param month - BS month (1-12)
|
|
165
|
+
* @returns Previous month details
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* getPrevMonth(2081, 1); // Returns { year: 2080, month: 12 }
|
|
169
|
+
* getPrevMonth(2080, 7); // Returns { year: 2080, month: 6 }
|
|
170
|
+
*/
|
|
171
|
+
declare function getPrevMonth(year: number, month: number): MonthNavigation;
|
|
172
|
+
/**
|
|
173
|
+
* Get calendar data for a specific year
|
|
174
|
+
*
|
|
175
|
+
* @param year - BS year
|
|
176
|
+
* @returns Array of days in each month
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* getCalendarData(2080); // Returns [31, 32, 31, 32, ...]
|
|
180
|
+
*/
|
|
181
|
+
declare function getCalendarData(year: number): number[];
|
|
182
|
+
/**
|
|
183
|
+
* Get the available data range
|
|
184
|
+
*
|
|
185
|
+
* @returns Data range information
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* getDataRange(); // Returns { minYear: 2000, maxYear: 2100, totalYears: 101 }
|
|
189
|
+
*/
|
|
190
|
+
declare function getDataRange(): DataRange;
|
|
191
|
+
/**
|
|
192
|
+
* Calculate the number of days between two BS dates
|
|
193
|
+
*
|
|
194
|
+
* @param fromYear - Starting BS year
|
|
195
|
+
* @param fromMonth - Starting BS month
|
|
196
|
+
* @param fromDay - Starting BS day
|
|
197
|
+
* @param toYear - Ending BS year
|
|
198
|
+
* @param toMonth - Ending BS month
|
|
199
|
+
* @param toDay - Ending BS day
|
|
200
|
+
* @returns Number of days between dates (can be negative if toDate is before fromDate)
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* getDaysInRange(2080, 1, 1, 2080, 1, 31); // Returns 30
|
|
204
|
+
*/
|
|
205
|
+
declare function getDaysInRange(fromYear: number, fromMonth: number, fromDay: number, toYear: number, toMonth: number, toDay: number): number;
|
|
206
|
+
/**
|
|
207
|
+
* Get all calendar data
|
|
208
|
+
*
|
|
209
|
+
* @returns Complete calendar data object
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* getAllCalendarData(); // Returns { 2000: [...], 2001: [...], ... }
|
|
213
|
+
*/
|
|
214
|
+
declare function getAllCalendarData(): CalendarData;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Format a BS date to string
|
|
218
|
+
*
|
|
219
|
+
* @param year - BS year
|
|
220
|
+
* @param month - BS month (1-12)
|
|
221
|
+
* @param day - BS day
|
|
222
|
+
* @param options - Format options
|
|
223
|
+
* @returns Formatted date string
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* formatBsDate(2080, 10, 15); // Returns "2080-10-15"
|
|
227
|
+
* formatBsDate(2080, 10, 15, { pattern: 'DD/MM/YYYY' }); // Returns "15/10/2080"
|
|
228
|
+
*/
|
|
229
|
+
declare function formatBsDate(year: number, month: number, day: number, options?: FormatOptions): string;
|
|
230
|
+
/**
|
|
231
|
+
* Format an AD date to string
|
|
232
|
+
*
|
|
233
|
+
* @param year - AD year
|
|
234
|
+
* @param month - AD month (1-12)
|
|
235
|
+
* @param day - AD day
|
|
236
|
+
* @param options - Format options
|
|
237
|
+
* @returns Formatted date string
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* formatAdDate(2024, 1, 27); // Returns "2024-01-27"
|
|
241
|
+
* formatAdDate(2024, 1, 27, { pattern: 'DD/MM/YYYY' }); // Returns "27/01/2024"
|
|
242
|
+
*/
|
|
243
|
+
declare function formatAdDate(year: number, month: number, day: number, options?: FormatOptions): string;
|
|
244
|
+
/**
|
|
245
|
+
* Get Nepali month name
|
|
246
|
+
*
|
|
247
|
+
* @param month - Month number (1-12)
|
|
248
|
+
* @param locale - Locale ('en' or 'ne')
|
|
249
|
+
* @returns Month name
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* getNepaliMonthName(1); // Returns "Baisakh"
|
|
253
|
+
* getNepaliMonthName(1, 'ne'); // Returns "बैशाख"
|
|
254
|
+
*/
|
|
255
|
+
declare function getNepaliMonthName(month: number, locale?: Locale): string;
|
|
256
|
+
/**
|
|
257
|
+
* Get English month name
|
|
258
|
+
*
|
|
259
|
+
* @param month - Month number (1-12)
|
|
260
|
+
* @returns Month name
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* getEnglishMonthName(1); // Returns "January"
|
|
264
|
+
*/
|
|
265
|
+
declare function getEnglishMonthName(month: number): string;
|
|
266
|
+
/**
|
|
267
|
+
* Parse a date string to DateObject
|
|
268
|
+
*
|
|
269
|
+
* @param dateString - Date string to parse
|
|
270
|
+
* @param pattern - Expected pattern
|
|
271
|
+
* @returns Parsed date object
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* parseDate('2080-10-15', 'YYYY-MM-DD'); // Returns { year: 2080, month: 10, day: 15 }
|
|
275
|
+
* parseDate('15/10/2080', 'DD/MM/YYYY'); // Returns { year: 2080, month: 10, day: 15 }
|
|
276
|
+
*/
|
|
277
|
+
declare function parseDate(dateString: string, pattern?: DatePattern): DateObject;
|
|
278
|
+
/**
|
|
279
|
+
* Format a date object to ISO string (YYYY-MM-DD)
|
|
280
|
+
*
|
|
281
|
+
* @param date - Date object
|
|
282
|
+
* @returns ISO formatted date string
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* toIsoString({ year: 2080, month: 10, day: 15 }); // Returns "2080-10-15"
|
|
286
|
+
*/
|
|
287
|
+
declare function toIsoString(date: DateObject): string;
|
|
288
|
+
/**
|
|
289
|
+
* Format a date object to array [year, month, day]
|
|
290
|
+
*
|
|
291
|
+
* @param date - Date object
|
|
292
|
+
* @returns Date as array
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* toArray({ year: 2080, month: 10, day: 15 }); // Returns [2080, 10, 15]
|
|
296
|
+
*/
|
|
297
|
+
declare function toArray(date: DateObject): [number, number, number];
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Check if a year exists in the calendar data
|
|
301
|
+
*/
|
|
302
|
+
declare function hasDataForYear(year: number): boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Validate a Nepali (BS) date
|
|
305
|
+
*/
|
|
306
|
+
declare function isValidBsDate(year: number, month: number, day: number): boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Validate an English (AD) date
|
|
309
|
+
*/
|
|
310
|
+
declare function isValidAdDate(year: number, month: number, day: number): boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Check if a year is a leap year (Gregorian calendar)
|
|
313
|
+
*/
|
|
314
|
+
declare function isLeapYear(year: number): boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Get the number of days in a month for AD calendar
|
|
317
|
+
*/
|
|
318
|
+
declare function getDaysInAdMonth(year: number, month: number): number;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Nepali Calendar Data (Bikram Sambat)
|
|
322
|
+
*
|
|
323
|
+
* Each year maps to an array of 12 numbers representing the days in each month.
|
|
324
|
+
* Months: [Baisakh, Jestha, Ashar, Shrawan, Bhadra, Ashwin, Kartik, Mangsir, Poush, Magh, Falgun, Chaitra]
|
|
325
|
+
*
|
|
326
|
+
* Data Sources:
|
|
327
|
+
* - Nepal Panchanga Nirnayak Samiti
|
|
328
|
+
* - Verified against historical records
|
|
329
|
+
*
|
|
330
|
+
* Data Range: BS 2000 - 2100 (AD 1943 - 2043)
|
|
331
|
+
*/
|
|
332
|
+
declare const NEPALI_CALENDAR_DATA: CalendarData;
|
|
333
|
+
/**
|
|
334
|
+
* Get the minimum year in the calendar data
|
|
335
|
+
*/
|
|
336
|
+
declare const MIN_YEAR: number;
|
|
337
|
+
/**
|
|
338
|
+
* Get the maximum year in the calendar data
|
|
339
|
+
*/
|
|
340
|
+
declare const MAX_YEAR: number;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Base reference date for all calculations
|
|
344
|
+
* BS 2000-01-01 = AD 1943-04-14
|
|
345
|
+
*
|
|
346
|
+
* This is the anchor point for all date conversions.
|
|
347
|
+
*/
|
|
348
|
+
declare const BASE_BS_DATE: {
|
|
349
|
+
year: number;
|
|
350
|
+
month: number;
|
|
351
|
+
day: number;
|
|
352
|
+
};
|
|
353
|
+
declare const BASE_AD_DATE: {
|
|
354
|
+
year: number;
|
|
355
|
+
month: number;
|
|
356
|
+
day: number;
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* Reference date pairs for validation and testing
|
|
360
|
+
*
|
|
361
|
+
* These are verified BS-AD date pairs used to validate conversion accuracy.
|
|
362
|
+
* Each pair represents a known accurate conversion point.
|
|
363
|
+
*
|
|
364
|
+
* Sources:
|
|
365
|
+
* - Official Nepal government publications
|
|
366
|
+
* - Historical records and verified events
|
|
367
|
+
* - Cross-referenced with multiple calendar systems
|
|
368
|
+
*/
|
|
369
|
+
declare const REFERENCE_DATES: ReferenceDatePair[];
|
|
370
|
+
|
|
371
|
+
export { BASE_AD_DATE, BASE_BS_DATE, type CalendarData, type ConversionOptions, type DataRange, type DateArray, type DateFormat, type DateObject, type DatePattern, ENGLISH_MONTH_NAMES, type FormatOptions, type Locale, MAX_YEAR, MIN_YEAR, type MonthNavigation, NEPALI_CALENDAR_DATA, NEPALI_MONTH_NAMES_EN, NEPALI_MONTH_NAMES_NE, NepaliMonth, REFERENCE_DATES, type ReferenceDatePair, adToBs, bsToAd, formatAdDate, formatBsDate, getAllCalendarData, getCalendarData, getDataRange, getDaysInAdMonth, getDaysInRange, getEnglishMonthName, getNepaliMonthName, getNextMonth, getPrevMonth, getTotalDaysInMonth, getTotalDaysInYear, hasDataForYear, isLeapYear, isValidAdDate, isValidBsDate, parseDate, toArray, toIsoString };
|