bn-calendar 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,1682 @@
1
+ # Bangla Calendar
2
+
3
+ > Comprehensive Bengali calendar system library built for any JavaScript and TypeScript environment.
4
+
5
+ <p>
6
+ <!-- Package Info -->
7
+ <a href="https://www.npmjs.com/package/bn-calendar" aria-label="NPM Downloads">
8
+ <img src="https://img.shields.io/npm/dm/bn-calendar.svg?label=DOWNLOADS&style=flat&color=red&logo=npm" alt="Downloads" />
9
+ </a>
10
+ <a href="https://www.npmjs.com/package/bn-calendar" aria-label="Latest Version">
11
+ <img src="https://img.shields.io/npm/v/bn-calendar.svg?label=NPM&style=flat&color=teal&logo=npm" alt="Latest Version" />
12
+ </a>
13
+ <a href="https://bundlejs.com/?q=bn-calendar" aria-label="Bundle Size">
14
+ <img src="https://img.shields.io/bundlejs/size/bn-calendar?label=Bundle%20Size&style=flat&color=blue&logo=npm" alt="Bundle Size" />
15
+ </a>
16
+
17
+ <!-- Project Metadata -->
18
+ <a href="https://github.com/nazmul-nhb/bn-calendar" aria-label="TypeScript">
19
+ <img src="https://img.shields.io/badge/BUILT%20with-TypeScript-3178C6?style=flat&logo=typescript&logoColor=blue" alt="Built with TypeScript" />
20
+ </a>
21
+ <a href="https://github.com/nazmul-nhb/bn-calendar/actions" aria-label="Build Status">
22
+ <img src="https://img.shields.io/github/actions/workflow/status/nazmul-nhb/bn-calendar/publish.yml?label=BUILD%20%26%20PUBLISH&style=flat&logo=github" alt="Build Status" />
23
+ </a>
24
+ <a href="https://github.com/nazmul-nhb/bn-calendar" aria-label="Project Status">
25
+ <img src="https://img.shields.io/badge/STATUS-maintained-brightgreen?style=flat&logo=git" alt="Maintained" />
26
+ </a>
27
+ <a href="https://github.com/nazmul-nhb/bn-calendar/commits/main" aria-label="Last Commit">
28
+ <img src="https://img.shields.io/github/last-commit/nazmul-nhb/bn-calendar?style=flat&label=LAST%20COMMIT&logo=git" alt="Last Commit" />
29
+ </a>
30
+
31
+ <!-- GitHub Meta -->
32
+ <a href="https://github.com/nazmul-nhb/bn-calendar/stargazers" aria-label="GitHub Stars">
33
+ <img src="https://img.shields.io/github/stars/nazmul-nhb/bn-calendar?style=flat&label=STARS&logo=github" alt="GitHub stars" />
34
+ </a>
35
+ <a href="https://github.com/nazmul-nhb/bn-calendar/issues" aria-label="Open Issues">
36
+ <img src="https://img.shields.io/github/issues/nazmul-nhb/bn-calendar?style=flat&label=ISSUES&logo=github" alt="Open Issues" />
37
+ </a>
38
+ <a href="https://github.com/nazmul-nhb/bn-calendar/pulls" aria-label="Open Pull Requests">
39
+ <img src="https://img.shields.io/github/issues-pr/nazmul-nhb/bn-calendar?style=flat&label=PRs&logo=github" alt="Pull Requests" />
40
+ </a>
41
+
42
+ <!-- License Info -->
43
+ <a href="https://www.npmjs.com/package/bn-calendar" aria-label="License">
44
+ <img src="https://img.shields.io/npm/l/bn-calendar.svg?label=LICENSE&style=flat&color=orange&logo=open-source-initiative" alt="License" />
45
+ </a>
46
+ </p>
47
+
48
+ <!-- markdownlint-disable-file MD024 -->
49
+
50
+ `bn-calendar` is a comprehensive Bengali calendar system library built for any JavaScript and TypeScript environment. It supports creation, manipulation, and conversion between Bengali and Gregorian calendars with full support for both `'revised-2019'` (default) and `'revised-1966'` variants.
51
+
52
+ ## Features
53
+
54
+ - **Bidirectional Conversion**: Seamlessly convert dates between Gregorian and Bengali calendar systems.
55
+ - **Multiple Variants**: Full support for both `'revised-2019'` (official Bangladesh calendar) and `'revised-1966'` leap year rules.
56
+ - **Rich API**: Extensive methods for date manipulation, formatting, and calculations.
57
+ - **Universal Utilities**: Handy functions to handle conversion between Bangla (`০-৯`) and Latin (`0-9`) digits.
58
+ - **Lightweight & Fast**: Zero dependencies, fully tree-shakable, and optimized for performance.
59
+ - **Universal Compatibility**: Works seamlessly in Node.js, browsers, and any JS/TS environment.
60
+ - **Type-Safe**: Written in TypeScript with comprehensive type definitions.
61
+
62
+ ---
63
+
64
+ ## Install
65
+
66
+ ### NPM
67
+
68
+ ```bash
69
+ npm i bn-calendar
70
+ ```
71
+
72
+ ### PNPM
73
+
74
+ ```bash
75
+ pnpm add bn-calendar
76
+ ```
77
+
78
+ ### YARN
79
+
80
+ ```bash
81
+ yarn add bn-calendar
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Import
87
+
88
+ ```ts
89
+ // Main class
90
+ import { BanglaCalendar } from 'bn-calendar';
91
+
92
+ // Utilities
93
+ import { banglaToDigit, digitToBangla } from 'bn-calendar/utils';
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Constructor
99
+
100
+ Creates a new `BanglaCalendar` instance from various input formats.
101
+
102
+ ### Constructor Signatures
103
+
104
+ **Signature 1:** From current date with optional configuration
105
+
106
+ ```typescript
107
+ constructor(config?: BnCalendarConfig)
108
+ ```
109
+
110
+ **Signature 2:** From Bangla or Gregorian date string
111
+
112
+ ```typescript
113
+ constructor(date: string, config?: BnCalendarConfig)
114
+ ```
115
+
116
+ **Signature 3:** From Date object
117
+
118
+ ```typescript
119
+ constructor(date: Date, config?: BnCalendarConfig)
120
+ ```
121
+
122
+ **Signature 4:** From timestamp or Bangla year (Latin digits)
123
+
124
+ ```typescript
125
+ constructor(tsOrBnYear: number, config?: BnCalendarConfig)
126
+ ```
127
+
128
+ **Signature 5:** From Bangla year (Bangla digits)
129
+
130
+ ```typescript
131
+ constructor(bnYear: BanglaYear, config?: BnCalendarConfig)
132
+ ```
133
+
134
+ **Signature 6:** From Bangla year and month (Latin digits)
135
+
136
+ ```typescript
137
+ constructor(bnYear: number, bnMonth: NumberRange<1, 12>, config?: BnCalendarConfig)
138
+ ```
139
+
140
+ **Signature 7:** From Bangla year and month (Bangla digits)
141
+
142
+ ```typescript
143
+ constructor(bnYear: BanglaYear, bnMonth: BanglaMonth, config?: BnCalendarConfig)
144
+ ```
145
+
146
+ **Signature 8:** From Bangla year, month, and day (Latin digits)
147
+
148
+ ```typescript
149
+ constructor(
150
+ bnYear: number,
151
+ bnMonth: NumberRange<1, 12>,
152
+ bnDate: NumberRange<1, 31>,
153
+ config?: BnCalendarConfig
154
+ )
155
+ ```
156
+
157
+ **Signature 9:** From Bangla year, month, and day (Bangla digits)
158
+
159
+ ```typescript
160
+ constructor(
161
+ bnYear: BanglaYear,
162
+ bnMonth: BanglaMonth,
163
+ bnDate: BanglaDate,
164
+ config?: BnCalendarConfig
165
+ )
166
+ ```
167
+
168
+ ### Parameters
169
+
170
+ - `date`: Various date formats including Bangla date strings, Gregorian date strings, Date objects, timestamps, or individual date components
171
+ - `bnYear`: Bengali year in either Bangla (`০-৯৯৯৯`) or Latin (`0-9999`) digits
172
+ - `bnMonth`: Bengali month (1-12 or `১-১২`)
173
+ - `bnDate`: Bengali day of month (1-31 or `১-৩১`)
174
+ - `config`: Optional configuration object with `variant` property (`'revised-2019'` or `'revised-1966'`)
175
+
176
+ ### Behavior
177
+
178
+ - Automatically detects input format and parses accordingly
179
+ - Defaults to current date if no valid input is provided
180
+ - Uses `'revised-2019'` variant by default
181
+ - Validates all date components
182
+ - Handles leap years according to the selected variant
183
+
184
+ ### Examples
185
+
186
+ ```typescript
187
+ // Current date
188
+ new BanglaCalendar();
189
+
190
+ // From Bangla date string
191
+ new BanglaCalendar('১৪৩২-১১-০৮');
192
+
193
+ // From Gregorian date string
194
+ new BanglaCalendar('2023-04-14');
195
+
196
+ // From Date object
197
+ new BanglaCalendar(new Date('2023-04-14'));
198
+
199
+ // From Bangla year, month, date (Latin)
200
+ new BanglaCalendar(1430, 1, 1);
201
+
202
+ // From Bangla year, month, date (Bangla)
203
+ new BanglaCalendar('১৪৩০', '১', '১');
204
+
205
+ // With specific variant
206
+ new BanglaCalendar('১৪৩০', '১', '১', { variant: 'revised-1966' });
207
+ ```
208
+
209
+ ---
210
+
211
+ ## Available Methods
212
+
213
+ - **Instance Methods**
214
+ - [valueOf](#valueof)
215
+ - [isLeapYear](#isleapyear)
216
+ - [toDate](#todate)
217
+ - [getSeasonName](#getseasonname)
218
+ - [getMonthName](#getmonthname)
219
+ - [getDayName](#getdayname)
220
+ - [startOfMonth](#startofmonth)
221
+ - [endOfMonth](#endofmonth)
222
+ - [startOfYear](#startofyear)
223
+ - [endOfYear](#endofyear)
224
+ - [daysInMonth](#daysinmonth)
225
+ - [toJSON](#tojson)
226
+ - [toString](#tostring)
227
+ - [toStringEn](#tostringen)
228
+ - [format](#format)
229
+ - [addDays](#adddays)
230
+ - [addWeeks](#addweeks)
231
+ - [addMonths](#addmonths)
232
+ - [addYears](#addyears)
233
+ - [$hasVariantConfig](#hasvariantconfig)
234
+
235
+ - **Static Methods**
236
+ - [isBanglaYear](#isbanglayear)
237
+ - [isBanglaYearEn](#isbanglayear)
238
+ - [isBanglaMonth](#isbanglamonth)
239
+ - [isBanglaMonthEn](#isbanglamonthen)
240
+ - [isBanglaDate](#isbangladate)
241
+ - [isBanglaDateEn](#isbangladateen)
242
+ - [isBanglaDateString](#isbangladatestring)
243
+
244
+ - **Symbol Methods**
245
+
246
+ - [Symbol.toPrimitive](#symboltoprimitive)
247
+ - [Symbol.toStringTag](#symboltostringtag)
248
+
249
+ ---
250
+
251
+ ## Properties
252
+
253
+ ### variant
254
+
255
+ ```typescript
256
+ readonly variant: BnCalendarVariant
257
+ ```
258
+
259
+ The calendar variant being used (`'revised-2019'` or `'revised-1966'`).
260
+
261
+ **Example:**
262
+
263
+ ```typescript
264
+ const cal2019 = new BanglaCalendar(); // Default: 'revised-2019'
265
+ console.log(cal2019.variant); // 'revised-2019'
266
+
267
+ const cal1966 = new BanglaCalendar({ variant: 'revised-1966' });
268
+ console.log(cal1966.variant); // 'revised-1966'
269
+
270
+ // Different leap year behavior
271
+ console.log(cal2019.isLeapYear()); // Follows Gregorian rules
272
+ console.log(cal1966.isLeapYear()); // Follows Bangla year % 4 === 2 rule
273
+ ```
274
+
275
+ ### year
276
+
277
+ ```typescript
278
+ readonly year: Readonly<{
279
+ bn: BanglaYear; // Bangla year in Bangla digits
280
+ en: number; // Bangla year in Latin digits
281
+ }>
282
+ ```
283
+
284
+ **Example:**
285
+
286
+ ```typescript
287
+ const bnCal = new BanglaCalendar('১৪৩০-০১-০১');
288
+ console.log(bnCal.year.bn); // '১৪৩০' (Bangla digits)
289
+ console.log(bnCal.year.en); // 1430 (Latin digits)
290
+
291
+ // Type-safe access
292
+ const banglaYear: string = bnCal.year.bn; // Type: BanglaYear
293
+ const latinYear: number = bnCal.year.en; // Type: number
294
+ ```
295
+
296
+ ### month
297
+
298
+ ```typescript
299
+ readonly month: Readonly<{
300
+ bn: BanglaMonth; // Bangla month in Bangla digits (১-১২)
301
+ en: NumberRange<1, 12>; // Bangla month in Latin digits (1-12)
302
+ }>
303
+ ```
304
+
305
+ **Example:**
306
+
307
+ ```typescript
308
+ const bnCal = new BanglaCalendar('১৪৩০-০৫-১৫'); // ভাদ্র ১৫
309
+ console.log(bnCal.month.bn); // '৫' (Bangla digits)
310
+ console.log(bnCal.month.en); // 5 (Latin digits, 1-based)
311
+
312
+ // Get month name to verify
313
+ console.log(bnCal.getMonthName()); // 'ভাদ্র'
314
+ console.log(bnCal.getMonthName('en')); // 'Bhadro'
315
+
316
+ // Type-safe access
317
+ const monthNumber: number = bnCal.month.en; // Type: NumberRange<1, 12>
318
+ ```
319
+
320
+ ### date
321
+
322
+ ```typescript
323
+ readonly date: Readonly<{
324
+ bn: BanglaDate; // Bangla day of month in Bangla digits (১-৩১)
325
+ en: NumberRange<1, 31>; // Bangla day of month in Latin digits (1-31)
326
+ }>
327
+ ```
328
+
329
+ **Example:**
330
+
331
+ ```typescript
332
+ const bnCal = new BanglaCalendar('১৪৩০-০৫-১৫'); // ১৫ ভাদ্র
333
+ console.log(bnCal.date.bn); // '১৫' (Bangla digits)
334
+ console.log(bnCal.date.en); // 15 (Latin digits)
335
+
336
+ // Type-safe access
337
+ const dayNumber: number = bnCal.date.en; // Type: NumberRange<1, 31>
338
+ ```
339
+
340
+ ### gregorian
341
+
342
+ ```typescript
343
+ readonly gregorian: Readonly<{
344
+ year: number; // Gregorian year
345
+ month: NumberRange<1, 12>; // Gregorian month (1-12)
346
+ date: NumberRange<1, 31>; // Gregorian day of month (1-31)
347
+ }>
348
+ ```
349
+
350
+ **Example:**
351
+
352
+ ```typescript
353
+ const bnCal = new BanglaCalendar('১৪৩০-০১-০১'); // ১ বৈশাখ ১৪৩০
354
+ console.log(bnCal.gregorian.year); // 2023
355
+ console.log(bnCal.gregorian.month); // 4 (April)
356
+ console.log(bnCal.gregorian.date); // 14
357
+
358
+ // Verify conversion
359
+ const gregorianDate = bnCal.toDate();
360
+ console.log(gregorianDate); // Date: Fri Apr 14 2023 00:00:00 GMT+0000
361
+
362
+ // Conversion works both ways
363
+ const fromGregorian = new BanglaCalendar(new Date(2023, 3, 14)); // April 14, 2023
364
+ console.log(fromGregorian.toJSON()); // '১৪৩০-০১-০১'
365
+ ```
366
+
367
+ ### weekDay
368
+
369
+ ```typescript
370
+ readonly weekDay: Enumerate<7>
371
+ ```
372
+
373
+ Day of the week (0-6, where 0 is Sunday/রবিবার).
374
+
375
+ **Example:**
376
+
377
+ ```typescript
378
+ const bnCal = new BanglaCalendar('১৪৩০-০১-০১'); // Friday, April 14, 2023
379
+ console.log(bnCal.weekDay); // 5 (Friday)
380
+
381
+ // Get day name to verify
382
+ console.log(bnCal.getDayName()); // 'শুক্রবার'
383
+ console.log(bnCal.getDayName('en')); // 'Shukrobar (Friday)'
384
+
385
+ // Check specific days
386
+ if (bnCal.weekDay === 0) {
387
+ console.log('It is Sunday (রবিবার)');
388
+ } else if (bnCal.weekDay === 5) {
389
+ console.log('It is Friday (শুক্রবার)');
390
+ }
391
+ ```
392
+
393
+ ### isoWeekDay
394
+
395
+ ```typescript
396
+ readonly isoWeekDay: NumberRange<1, 7>
397
+ ```
398
+
399
+ ISO weekday (1 = Monday, 7 = Sunday).
400
+
401
+ **Example:**
402
+
403
+ ```typescript
404
+ const bnCal = new BanglaCalendar('১৪৩০-০১-০১'); // Friday, April 14, 2023
405
+ console.log(bnCal.isoWeekDay); // 5 (Friday in ISO format)
406
+
407
+ // Compare with weekDay
408
+ console.log(bnCal.weekDay); // 5 (0-based, Sunday=0)
409
+ console.log(bnCal.isoWeekDay); // 5 (1-based, Monday=1)
410
+
411
+ // Useful for ISO-compliant calculations
412
+ const isWeekend = bnCal.isoWeekDay >= 6; // Saturday or Sunday
413
+ console.log(isWeekend); // false (Friday is not weekend)
414
+
415
+ // ISO week starts on Monday
416
+ const mondayDate = bnCal.addDays(1 - bnCal.isoWeekDay); // Get Monday of the week
417
+ console.log(mondayDate.toJSON()); // Get Monday's date
418
+ ```
419
+
420
+ ---
421
+
422
+ ## Examples
423
+
424
+ ### Basic Usage
425
+
426
+ ```typescript
427
+ const today = new BanglaCalendar();
428
+ console.log(today.toString()); // "শুক্রবার, ১ বৈশাখ, ১৪৩০ [গ্রীষ্ম]"
429
+ console.log(today.toJSON()); // "১৪৩০-০১-০১"
430
+
431
+ const specificDate = new BanglaCalendar('১৪৩২-১১-০৮');
432
+ console.log(specificDate.getMonthName()); // "ফাল্গুন"
433
+ ```
434
+
435
+ ### Date Conversion
436
+
437
+ ```typescript
438
+ const bnDate = new BanglaCalendar('১৪৩০', '১', '১');
439
+ const gregorianDate = bnDate.toDate();
440
+ console.log(gregorianDate.toISOString()); // "2023-04-14T00:00:00.000Z"
441
+ ```
442
+
443
+ ### Month Operations
444
+
445
+ ```typescript
446
+ const date = new BanglaCalendar('১৪৩০', '৫', '১৫');
447
+ console.log(date.startOfMonth().toString()); // "১ জ্যৈষ্ঠ ১৪৩০"
448
+ console.log(date.endOfMonth().toString()); // "৩১ জ্যৈষ্ঠ ১৪৩০"
449
+ ```
450
+
451
+ ---
452
+
453
+ ## Aliases
454
+
455
+ `BanglaCalendar` can also be imported using **BnCalendar** and **Bongabdo** aliases.
456
+
457
+ ---
458
+
459
+ ## API Reference for BanglaCalendar
460
+
461
+ ## valueOf()
462
+
463
+ Gets the numeric timestamp (in milliseconds) for the current Bangla date.
464
+
465
+ ### Signature
466
+
467
+ ```typescript
468
+ valueOf(): number
469
+ ```
470
+
471
+ ### Return Value
472
+
473
+ Unix timestamp in milliseconds representing the Gregorian equivalent of the current Bangla date.
474
+
475
+ ### Example
476
+
477
+ ```typescript
478
+ const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
479
+ const timestamp = bnCal.valueOf(); // 1681430400000 (equivalent to April 14, 2023)
480
+ ```
481
+
482
+ ### Remarks
483
+
484
+ - Internally calls [**`toDate().getTime()`**](#todate) to convert the Bangla date to Gregorian and get its timestamp
485
+ - The time component is normalized to midnight UTC during conversion
486
+ - This method is automatically called when the instance is used in numeric contexts
487
+
488
+ ---
489
+
490
+ ## isLeapYear()
491
+
492
+ Checks if the current Bangla year is a leap year according to the selected calendar variant.
493
+
494
+ ### Signature
495
+
496
+ ```typescript
497
+ isLeapYear(): boolean
498
+ ```
499
+
500
+ ### Return Value
501
+
502
+ `true` if the year is a leap year, `false` otherwise.
503
+
504
+ ### Example
505
+
506
+ ```typescript
507
+ const date = new BanglaCalendar(1430, 1, 1);
508
+ const isLeap = date.isLeapYear(); // false
509
+ ```
510
+
511
+ ### Remarks
512
+
513
+ - **Revised-2019**: Follows Gregorian leap year rules (divisible by 4, not by 100 unless also divisible by 400)
514
+ - **Revised-1966**: Leap year when `bnYear % 4 === 2`
515
+
516
+ ---
517
+
518
+ ## toDate()
519
+
520
+ Converts the Bangla calendar date to a JavaScript Date object.
521
+
522
+ ### Signature
523
+
524
+ ```typescript
525
+ toDate(): Date
526
+ ```
527
+
528
+ ### Return Value
529
+
530
+ Gregorian Date object equivalent to the Bangla date.
531
+
532
+ ### Example
533
+
534
+ ```typescript
535
+ const bnDate = new BanglaCalendar('১৪৩০', '১', '১');
536
+ const gregorianDate = bnDate.toDate(); // Date for April 14, 2023
537
+ ```
538
+
539
+ ### Remarks
540
+
541
+ - Time component is always set to `00:00:00` in UTC
542
+ - Accounts for calendar variant and leap year rules
543
+
544
+ ---
545
+
546
+ ## getSeasonName()
547
+
548
+ Gets the Bangla season name for the current date.
549
+
550
+ ### Signature
551
+
552
+ ```typescript
553
+ getSeasonName<Locale extends $BnEn = 'bn'>(locale?: Locale): BanglaSeasonName<Locale>
554
+ ```
555
+
556
+ ### Parameters
557
+
558
+ - `locale`: Output locale (`'bn'` for Bengali, `'en'` for English). Defaults to `'bn'`.
559
+
560
+ ### Return Value
561
+
562
+ Name of the season in the specified locale.
563
+
564
+ ### Example
565
+
566
+ ```typescript
567
+ const bnCal = new BanglaCalendar('2023-04-14');
568
+ bnCal.getSeasonName(); // "গ্রীষ্ম"
569
+ bnCal.getSeasonName('en'); // "Grisma (Summer)"
570
+ ```
571
+
572
+ ### Seasons
573
+
574
+ - গ্রীষ্ম (Summer): Mid-April to Mid-June
575
+ - বর্ষা (Monsoon): Mid-June to Mid-August
576
+ - শরৎ (Autumn): Mid-August to Mid-October
577
+ - হেমন্ত (Late Autumn): Mid-October to Mid-December
578
+ - শীত (Winter): Mid-December to Mid-February
579
+ - বসন্ত (Spring): Mid-February to Mid-April
580
+
581
+ ---
582
+
583
+ ## getMonthName()
584
+
585
+ Gets the Bangla name of the month for the current date.
586
+
587
+ ### Signature
588
+
589
+ ```typescript
590
+ getMonthName<Locale extends $BnEn = 'bn'>(locale?: Locale): BanglaMonthName<Locale>
591
+ ```
592
+
593
+ ### Parameters
594
+
595
+ - `locale`: Output locale (`'bn'` for Bengali, `'en'` for English). Defaults to `'bn'`.
596
+
597
+ ### Return Value
598
+
599
+ Name of the month in the specified locale.
600
+
601
+ ### Example
602
+
603
+ ```typescript
604
+ const bnCal = new BanglaCalendar('2023-04-14');
605
+ bnCal.getMonthName(); // "বৈশাখ"
606
+ bnCal.getMonthName('en'); // "Boishakh"
607
+ ```
608
+
609
+ ---
610
+
611
+ ## getDayName()
612
+
613
+ Gets the Bangla name of the weekday for the current date.
614
+
615
+ ### Signature
616
+
617
+ ```typescript
618
+ getDayName<Locale extends $BnEn = 'bn'>(locale?: Locale): BanglaDayName<Locale>
619
+ ```
620
+
621
+ ### Parameters
622
+
623
+ - `locale`: Output locale (`'bn'` for Bengali, `'en'` for English). Defaults to `'bn'`.
624
+
625
+ ### Return Value
626
+
627
+ Name of the weekday in the specified locale.
628
+
629
+ ### Example
630
+
631
+ ```typescript
632
+ const bnCal = new BanglaCalendar('2023-04-14'); // Friday
633
+ bnCal.getDayName(); // "শুক্রবার"
634
+ bnCal.getDayName('en'); // "Shukrobar (Friday)"
635
+ ```
636
+
637
+ ---
638
+
639
+ ## startOfMonth()
640
+
641
+ Gets a new BanglaCalendar instance representing the first day of the current month.
642
+
643
+ ### Signature
644
+
645
+ ```typescript
646
+ startOfMonth(): BanglaCalendar
647
+ ```
648
+
649
+ ### Return Value
650
+
651
+ A BanglaCalendar instance set to the 1st day of the current month.
652
+
653
+ ### Example
654
+
655
+ ```typescript
656
+ const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
657
+ const startOfMonth = bnCal.startOfMonth(); // ১ জ্যৈষ্ঠ ১৪৩০
658
+ ```
659
+
660
+ ### Remarks
661
+
662
+ - Preserves the calendar variant of the original
663
+ - Time component is set to midnight UTC
664
+
665
+ ---
666
+
667
+ ## endOfMonth()
668
+
669
+ Gets a new `BanglaCalendar` instance representing the last day of the current month.
670
+
671
+ ### Signature
672
+
673
+ ```typescript
674
+ endOfMonth(): BanglaCalendar
675
+ ```
676
+
677
+ ### Return Value
678
+
679
+ A `BanglaCalendar` instance set to the last day of the current month.
680
+
681
+ ### Example
682
+
683
+ ```typescript
684
+ const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
685
+ const endOfMonth = bnCal.endOfMonth(); // ৩১ জ্যৈষ্ঠ ১৪৩০
686
+ ```
687
+
688
+ ### Remarks
689
+
690
+ - Accounts for month length variations (29/30/31 days)
691
+ - Includes leap year adjustments
692
+
693
+ ---
694
+
695
+ ## startOfYear()
696
+
697
+ Gets a new `BanglaCalendar` instance representing the first day of the current year (১ বৈশাখ).
698
+
699
+ ### Signature
700
+
701
+ ```typescript
702
+ startOfYear(): BanglaCalendar
703
+ ```
704
+
705
+ ### Return Value
706
+
707
+ A `BanglaCalendar` instance set to ১ বৈশাখ of the current year.
708
+
709
+ ### Example
710
+
711
+ ```typescript
712
+ const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
713
+ const startOfYear = bnCal.startOfYear(); // ১ বৈশাখ ১৪৩০
714
+ ```
715
+
716
+ ---
717
+
718
+ ## endOfYear()
719
+
720
+ Gets a new `BanglaCalendar` instance representing the last day of the current year (৩০ চৈত্র).
721
+
722
+ ### Signature
723
+
724
+ ```typescript
725
+ endOfYear(): BanglaCalendar
726
+ ```
727
+
728
+ ### Return Value
729
+
730
+ A `BanglaCalendar` instance set to ৩০ চৈত্র of the current year.
731
+
732
+ ### Example
733
+
734
+ ```typescript
735
+ const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
736
+ const endOfYear = bnCal.endOfYear(); // ৩০ চৈত্র ১৪৩০
737
+ ```
738
+
739
+ ---
740
+
741
+ ## daysInMonth()
742
+
743
+ Gets the number of days in a Bangla month.
744
+
745
+ ### Signature
746
+
747
+ ```typescript
748
+ daysInMonth(month?: NumberRange<1, 12>): NumberRange<29, 31>
749
+ ```
750
+
751
+ ### Parameters
752
+
753
+ - `month`: Optional Bangla month (1-12 in Latin digits). If not provided, uses the current month.
754
+
755
+ ### Return Value
756
+
757
+ Number of days in the specified month (29, 30, or 31).
758
+
759
+ ### Example
760
+
761
+ ```typescript
762
+ const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
763
+ bnCal.daysInMonth(); // 31 (বৈশাখ has 31 days)
764
+ bnCal.daysInMonth(12); // 30 (চৈত্র has 30 days)
765
+ ```
766
+
767
+ ---
768
+
769
+ ## toJSON()
770
+
771
+ Returns a string representation of the Bangla date in ISO-like format (`YYYY-MM-DD` with Bangla digits).
772
+
773
+ ### Signature
774
+
775
+ ```typescript
776
+ toJSON(): string
777
+ ```
778
+
779
+ ### Return Value
780
+
781
+ Bangla date string in the format: `"YYYY-MM-DD"` (e.g., `"১৪৩০-০১-০১"`).
782
+
783
+ ### Example
784
+
785
+ ```typescript
786
+ const bnCal = new BanglaCalendar('2023-04-14');
787
+ console.log(bnCal.toJSON()); // "১৪৩০-০১-০১"
788
+ ```
789
+
790
+ ### Remarks
791
+
792
+ - Automatically called by `JSON.stringify()`
793
+ - Output follows: `"বছর-মাস-দিন"` with zero-padded Bangla digits
794
+
795
+ ---
796
+
797
+ ## toString()
798
+
799
+ Returns a string representation of the Bangla date in Bengali format.
800
+
801
+ ### Signature
802
+
803
+ ```typescript
804
+ toString(): string
805
+ ```
806
+
807
+ ### Return Value
808
+
809
+ Bangla date string in the format: "শুক্রবার, ১৫ জ্যৈষ্ঠ, ১৪৩০ [গ্রীষ্ম]".
810
+
811
+ ### Example
812
+
813
+ ```typescript
814
+ const bnCal = new BanglaCalendar('2023-04-14');
815
+ console.log(bnCal.toString()); // "শুক্রবার, ১ বৈশাখ, ১৪৩০ [গ্রীষ্ম]"
816
+ ```
817
+
818
+ ### Remarks
819
+
820
+ - Equivalent to [toStringEn()](#tostringen) with `'bn'` locale
821
+
822
+ ---
823
+
824
+ ## toStringEn()
825
+
826
+ Returns a string representation of the Bangla date in English/Latin format.
827
+
828
+ ### Signature
829
+
830
+ ```typescript
831
+ toStringEn(): string
832
+ ```
833
+
834
+ ### Return Value
835
+
836
+ Bangla date string in the format: "Shukrobar (Friday), 15 Joishtho, 1430 [Grisma (Summer)]".
837
+
838
+ ### Example
839
+
840
+ ```typescript
841
+ const bnCal = new BanglaCalendar('2023-04-14');
842
+ console.log(bnCal.toStringEn()); // "Shukrobar (Friday), 1 Boishakh, 1430 [Grisma (Summer)]"
843
+ ```
844
+
845
+ ---
846
+
847
+ ## format()
848
+
849
+ Formats the current date as a Bangla calendar date string using customizable tokens.
850
+
851
+ ### Signature
852
+
853
+ ```typescript
854
+ format(format?: BanglaDateFormat): string
855
+ ```
856
+
857
+ ### Parameters
858
+
859
+ - `format`: Format string using tokens (default: `'ddd, DD mmmm (SS), YYYY বঙ্গাব্দ'`)
860
+
861
+ ### Return Value
862
+
863
+ Formatted Bangla date string according to the specified format.
864
+
865
+ ### Examples
866
+
867
+ ```typescript
868
+ const bnCal = new BanglaCalendar('2023-04-14');
869
+
870
+ bnCal.format();
871
+ // Returns: 'শুক্রবার, বৈশাখ ০১ (গ্রীষ্মকাল), ১৪৩০ বঙ্গাব্দ'
872
+
873
+ bnCal.format('YYYY-MM-DD');
874
+ // Returns: '১৪৩০-০১-০১'
875
+
876
+ bnCal.format('mmmm DD, YYYY');
877
+ // Returns: 'বৈশাখ ০১, ১৪৩০'
878
+ ```
879
+
880
+ ### Format Tokens
881
+
882
+ - **Year**: `YYYY`/`yyyy` (full year), `YY`/`yy` (last 2 digits)
883
+ - **Month**: `M`/`MM` (padded), `mmm` (short name), `mmmm` (full name)
884
+ - **Day**: `D`/`DD` (padded), `Do` (cardinal)
885
+ - **Weekday**: `d` (short), `dd` (without 'বার'), `ddd` (full)
886
+ - **Season**: `S` (season), `SS` (season with 'কাল' suffix)
887
+
888
+ ### Escaping Text
889
+
890
+ To output raw text (not interpreted as a token), wrap it in square brackets:
891
+
892
+ - `[আজ] ddd` → `আজ রবিবার`
893
+ - `[year ]YYYY` → `year ২০২৫`
894
+
895
+ ---
896
+
897
+ ## addDays()
898
+
899
+ Adds (or subtracts) days to (or from) the current Bangla date.
900
+
901
+ ### Signature
902
+
903
+ ```typescript
904
+ addDays(days: number): BanglaCalendar
905
+ ```
906
+
907
+ ### Parameters
908
+
909
+ - `days`: Number of days to add (negative values subtract days)
910
+
911
+ ### Return Value
912
+
913
+ A new `BanglaCalendar` instance with the adjusted date.
914
+
915
+ ### Example
916
+
917
+ ```typescript
918
+ const bnCal = new BanglaCalendar('১৪৩০', '১', '১'); // ১ বৈশাখ ১৪৩০
919
+
920
+ // Add days
921
+ bnCal.addDays(7); // ৮ বৈশাখ ১৪৩০
922
+ bnCal.addDays(35); // ৫ জ্যৈষ্ঠ ১৪৩০
923
+
924
+ // Subtract days
925
+ bnCal.addDays(-3); // ২৮ চৈত্র ১৪২৯
926
+
927
+ // Cross year boundary
928
+ const lateDate = new BanglaCalendar('১৪৩০', '১২', '২৫');
929
+ lateDate.addDays(10); // ৫ বৈশাখ ১৪৩১
930
+ ```
931
+
932
+ ### Remarks
933
+
934
+ - Preserves the calendar variant of the original instance
935
+ - Handles month and year transitions automatically
936
+ - Accounts for varying month lengths and leap years
937
+ - Negative values subtract days from the current date
938
+ - Time component remains at midnight UTC
939
+
940
+ ---
941
+
942
+ ## addWeeks()
943
+
944
+ Adds (or subtracts) weeks to (or from) the current Bangla date.
945
+
946
+ ### Signature
947
+
948
+ ```typescript
949
+ addWeeks(weeks: number): BanglaCalendar
950
+ ```
951
+
952
+ ### Parameters
953
+
954
+ - `weeks`: Number of weeks to add (negative values subtract weeks)
955
+
956
+ ### Return Value
957
+
958
+ A new `BanglaCalendar` instance with the adjusted date.
959
+
960
+ ### Example
961
+
962
+ ```typescript
963
+ const bnCal = new BanglaCalendar('১৪৩০', '১', '১'); // ১ বৈশাখ ১৪৩০
964
+
965
+ // Add weeks
966
+ bnCal.addWeeks(2); // ১৫ বৈশাখ ১৪৩০
967
+ bnCal.addWeeks(5); // ৫ জ্যৈষ্ঠ ১৪৩০
968
+
969
+ // Subtract weeks
970
+ bnCal.addWeeks(-1); // ২৪ চৈত্র ১৪২৯
971
+ ```
972
+
973
+ ### Remarks
974
+
975
+ - Each week is treated as exactly 7 days
976
+ - Preserves the calendar variant of the original instance
977
+ - Handles month and year transitions automatically
978
+ - Useful for scheduling recurring weekly events
979
+ - Negative values subtract weeks from the current date
980
+
981
+ ---
982
+
983
+ ## addMonths()
984
+
985
+ Adds (or subtracts) months to (or from) the current Bangla date.
986
+
987
+ ### Signature
988
+
989
+ ```typescript
990
+ addMonths(months: number, overflow?: boolean): BanglaCalendar
991
+ ```
992
+
993
+ ### Parameters
994
+
995
+ - `months`: Number of months to add (negative values subtract months)
996
+ - `overflow`: Controls behavior when day doesn't exist in target month (default: `true`)
997
+ - `true`: Invalid dates overflow to the next month
998
+ - `false`: Clamps to the last valid day of the target month
999
+
1000
+ ### Return Value
1001
+
1002
+ A new `BanglaCalendar` instance with the adjusted date.
1003
+
1004
+ ### Example
1005
+
1006
+ ```typescript
1007
+ const normal = new BanglaCalendar('১৪৩০', '২', '১৫');
1008
+ normal.addMonths(1); // ১৫ আষাঢ় ১৪৩০
1009
+ normal.addMonths(1, false); // ১৫ আষাঢ় ১৪৩০
1010
+
1011
+ // Edge case: 31st doesn't exist in কার্তিক (30 days)
1012
+ const edgeCase = new BanglaCalendar('১৪৩০', '৬', '৩১'); // ৩১ আশ্বিন ১৪৩০
1013
+ edgeCase.addMonths(1); // ১ অগ্রহায়ণ ১৪৩০ (overflow)
1014
+ edgeCase.addMonths(1, false); // ৩০ কার্তিক ১৪৩০ (clamped)
1015
+
1016
+ // Subtract months
1017
+ edgeCase.addMonths(-1); // ১ আশ্বিন ১৪৩০
1018
+ edgeCase.addMonths(-1, false); // ৩১ ভাদ্র ১৪৩০
1019
+ ```
1020
+
1021
+ ### Remarks
1022
+
1023
+ - When `overflow=true` (default): Follows JavaScript `Date` behavior where invalid dates overflow
1024
+ - When `overflow=false`: Clamps to the last valid day of the target month
1025
+ - Preserves the calendar variant of the original instance
1026
+ - Handles year transitions automatically
1027
+ - Negative values subtract months from the current date
1028
+
1029
+ ---
1030
+
1031
+ ## addYears()
1032
+
1033
+ Adds (or subtracts) years to (or from) the current Bangla date.
1034
+
1035
+ ### Signature
1036
+
1037
+ ```typescript
1038
+ addYears(years: number, overflow?: boolean): BanglaCalendar
1039
+ ```
1040
+
1041
+ ### Parameters
1042
+
1043
+ - `years`: Number of years to add (negative values subtract years)
1044
+ - `overflow`: Controls behavior for leap year adjustments (default: `true`)
1045
+ - `true`: Allows date overflow when day doesn't exist in target year
1046
+ - `false`: Clamps to last valid day of month in non-leap years
1047
+
1048
+ ### Return Value
1049
+
1050
+ A new `BanglaCalendar` instance with the adjusted date.
1051
+
1052
+ ### Example
1053
+
1054
+ ```typescript
1055
+ const bnCal = new BanglaCalendar('১৪৩০', '১', '১৫'); // ১৫ বৈশাখ ১৪৩০
1056
+
1057
+ // Add years
1058
+ bnCal.addYears(1); // ১৫ বৈশাখ ১৪৩১
1059
+ bnCal.addYears(5); // ১৫ বৈশাখ ১৪৩৫
1060
+
1061
+ // Subtract years
1062
+ bnCal.addYears(-1); // ১৫ বৈশাখ ১৪২৯
1063
+
1064
+ // Leap year adjustment
1065
+ const leapDay = new BanglaCalendar('১৪৩১', '১১', '৩০'); // ৩০ ফাল্গুন ১৪৩১ (leap year)
1066
+ leapDay.addYears(1, false); // ২৯ ফাল্গুন ১৪৩২ (non-leap year has 29 days)
1067
+ ```
1068
+
1069
+ ### Remarks
1070
+
1071
+ - Preserves the calendar variant of the original instance
1072
+ - Negative values subtract years from the current date
1073
+ - Year addition follows Bangla calendar years
1074
+ - The month and day generally remain the same unless affected by leap year rules
1075
+ - When `overflow=false`, dates in ফাল্গুন (month 11) are adjusted for leap year differences
1076
+
1077
+ ---
1078
+
1079
+ ## $hasVariantConfig()
1080
+
1081
+ Checks if a value is a configuration object that contains a valid calendar `variant`.
1082
+
1083
+ ### Signature
1084
+
1085
+ ```typescript
1086
+ $hasVariantConfig(value: unknown): value is { variant: BnCalendarVariant }
1087
+ ```
1088
+
1089
+ ### Parameters
1090
+
1091
+ - `value`: The value to check
1092
+
1093
+ ### Return Value
1094
+
1095
+ `true` if the value contains a valid `variant` property, `false` otherwise.
1096
+
1097
+ ### Example
1098
+
1099
+ ```typescript
1100
+ const bnCal = new BanglaCalendar();
1101
+
1102
+ // Valid configuration objects
1103
+ bnCal.$hasVariantConfig({ variant: 'revised-2019' }); // true
1104
+ bnCal.$hasVariantConfig({ variant: 'revised-1966' }); // true
1105
+
1106
+ // Invalid configuration objects
1107
+ bnCal.$hasVariantConfig({ variant: 'invalid' }); // false
1108
+ bnCal.$hasVariantConfig({}); // false
1109
+ bnCal.$hasVariantConfig(null); // false
1110
+ ```
1111
+
1112
+ ### Remarks
1113
+
1114
+ - This method is used internally by the constructor to extract variant configuration from various parameter positions
1115
+ - Can be useful for type-checking configuration objects before passing them to the constructor
1116
+ - Validates if the object has a `variant` property and it contains one of the 2 supported values: `'revised-2019'` or `'revised-1966'`
1117
+
1118
+ ---
1119
+
1120
+ ## Static Methods
1121
+
1122
+ ## isBanglaYear()
1123
+
1124
+ Checks whether a value is a valid Bangla year in Bangla digits (`০–৯৯৯৯`).
1125
+
1126
+ ### Signature
1127
+
1128
+ ```typescript
1129
+ static isBanglaYear(value: unknown): value is BanglaYear
1130
+ ```
1131
+
1132
+ ### Example
1133
+
1134
+ ```typescript
1135
+ BanglaCalendar.isBanglaYear('১৪৩০'); // true
1136
+ BanglaCalendar.isBanglaYear('১০০০০'); // false (too many digits)
1137
+ BanglaCalendar.isBanglaYear('1430'); // false (Latin digits)
1138
+ ```
1139
+
1140
+ ---
1141
+
1142
+ ## isBanglaYearEn()
1143
+
1144
+ Checks whether a value is a valid Bangla year in Latin digits (`0–9999`).
1145
+
1146
+ ### Signature
1147
+
1148
+ ```typescript
1149
+ static isBanglaYearEn(value: number): boolean
1150
+ ```
1151
+
1152
+ ### Example
1153
+
1154
+ ```typescript
1155
+ BanglaCalendar.isBanglaYearEn(1430); // true
1156
+ BanglaCalendar.isBanglaYearEn(10000); // false
1157
+ BanglaCalendar.isBanglaYearEn(-1); // false
1158
+ ```
1159
+
1160
+ ---
1161
+
1162
+ ## isBanglaMonth()
1163
+
1164
+ Checks whether a value is a valid Bangla month in Bangla digits (`১–১২`).
1165
+
1166
+ ### Signature
1167
+
1168
+ ```typescript
1169
+ static isBanglaMonth(value: unknown): value is BanglaMonth
1170
+ ```
1171
+
1172
+ ### Example
1173
+
1174
+ ```typescript
1175
+ BanglaCalendar.isBanglaMonth('১'); // true
1176
+ BanglaCalendar.isBanglaMonth('১২'); // true
1177
+ BanglaCalendar.isBanglaMonth('১৩'); // false
1178
+ ```
1179
+
1180
+ ---
1181
+
1182
+ ## isBanglaMonthEn()
1183
+
1184
+ Checks whether a value is a valid Bangla month in Latin digits (`1–12`).
1185
+
1186
+ ### Signature
1187
+
1188
+ ```typescript
1189
+ static isBanglaMonthEn(value: unknown): value is NumberRange<1, 12>
1190
+ ```
1191
+
1192
+ ### Example
1193
+
1194
+ ```typescript
1195
+ BanglaCalendar.isBanglaMonthEn(1); // true
1196
+ BanglaCalendar.isBanglaMonthEn(12); // true
1197
+ BanglaCalendar.isBanglaMonthEn(13); // false
1198
+ ```
1199
+
1200
+ ---
1201
+
1202
+ ## isBanglaDate()
1203
+
1204
+ Checks whether a value is a valid Bangla date of month in Bangla digits (`১–৩১`).
1205
+
1206
+ ### Signature
1207
+
1208
+ ```typescript
1209
+ static isBanglaDate(value: unknown): value is BanglaDate
1210
+ ```
1211
+
1212
+ ### Example
1213
+
1214
+ ```typescript
1215
+ BanglaCalendar.isBanglaDate('১'); // true
1216
+ BanglaCalendar.isBanglaDate('৩১'); // true
1217
+ BanglaCalendar.isBanglaDate('৩২'); // false
1218
+ ```
1219
+
1220
+ ---
1221
+
1222
+ ## isBanglaDateEn()
1223
+
1224
+ Checks whether a value is a valid Bangla date of month in Latin digits (`1–31`).
1225
+
1226
+ ### Signature
1227
+
1228
+ ```typescript
1229
+ static isBanglaDateEn(value: unknown): value is NumberRange<1, 31>
1230
+ ```
1231
+
1232
+ ### Example
1233
+
1234
+ ```typescript
1235
+ BanglaCalendar.isBanglaDateEn(1); // true
1236
+ BanglaCalendar.isBanglaDateEn(31); // true
1237
+ BanglaCalendar.isBanglaDateEn(32); // false
1238
+ ```
1239
+
1240
+ ---
1241
+
1242
+ ## isBanglaDateString()
1243
+
1244
+ Checks whether a string follows the Bangla date format pattern (`YYYY-MM-DD` with Bangla digits).
1245
+
1246
+ ### Signature
1247
+
1248
+ ```typescript
1249
+ static isBanglaDateString(value: unknown): value is string
1250
+ ```
1251
+
1252
+ ### Example
1253
+
1254
+ ```typescript
1255
+ BanglaCalendar.isBanglaDateString('১৪৩০-০১-০১'); // true
1256
+ BanglaCalendar.isBanglaDateString('1430-01-01'); // false (Latin digits)
1257
+ BanglaCalendar.isBanglaDateString('১৪৩০-১৩-০১'); // false (invalid month)
1258
+ ```
1259
+
1260
+ ### Remarks
1261
+
1262
+ - Accepts both zero-padded and non-padded Bangla digits
1263
+ - Validates year, month, and date components separately
1264
+
1265
+ ---
1266
+
1267
+ ## [Symbol.toPrimitive]
1268
+
1269
+ Converts the `BanglaCalendar` instance to a primitive value based on the provided hint.
1270
+
1271
+ ### Signature
1272
+
1273
+ ```typescript
1274
+ [Symbol.toPrimitive](hint: string): string | number
1275
+ ```
1276
+
1277
+ ### Parameters
1278
+
1279
+ - `hint`: The conversion hint - either `'number'` or `'string'` (defaults to `'string'`)
1280
+
1281
+ ### Return Value
1282
+
1283
+ - If `hint` is `'number'`: Returns the timestamp (same as [valueOf()](#valueof))
1284
+ - Otherwise: Returns the ISO-like Bangla date string (same as [toJSON()](#tojson))
1285
+
1286
+ ### Behavior
1287
+
1288
+ - **`hint === 'number'`**: Returns numeric timestamp via [valueOf()](#valueof)
1289
+ - **`hint === 'string'` or any other hint**: Returns formatted string via [toJSON()](#tojson)
1290
+
1291
+ ### Example
1292
+
1293
+ ```typescript
1294
+ const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
1295
+
1296
+ // String context (default)
1297
+ String(bnCal); // "১৪৩০-০১-০১"
1298
+ `${bnCal}`; // "১৪৩০-০১-০১"
1299
+
1300
+ // Numeric context
1301
+ +bunCal; // 1681430400000
1302
+ bnCal * 1; // 1681430400000
1303
+
1304
+ // Using explicit hint
1305
+ bnCal[Symbol.toPrimitive]('number'); // 1681430400000
1306
+ bnCal[Symbol.toPrimitive]('string'); // "১৪৩০-০১-০১"
1307
+ bnCal[Symbol.toPrimitive]('default'); // "১৪৩০-০১-০১"
1308
+ ```
1309
+
1310
+ ### Remarks
1311
+
1312
+ - This method enables implicit type conversion in JavaScript/TypeScript
1313
+ - Follows standard JavaScript object-to-primitive conversion protocol
1314
+ - Ensures predictable behavior in arithmetic operations and string concatenation
1315
+
1316
+ ---
1317
+
1318
+ ## [Symbol.toStringTag]
1319
+
1320
+ Provides a string tag used by `Object.prototype.toString()`.
1321
+
1322
+ ### Signature
1323
+
1324
+ ```typescript
1325
+ get [Symbol.toStringTag](): string
1326
+ ```
1327
+
1328
+ ### Return Value
1329
+
1330
+ ISO-like Bangla date string in the format `"YYYY-MM-DD"` with Bangla digits.
1331
+
1332
+ ### Example
1333
+
1334
+ ```typescript
1335
+ const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
1336
+
1337
+ console.log(bnCal);
1338
+ // BanglaCalendar [১৪৩০-০১-০১] {
1339
+ // variant: 'revised-2019',
1340
+ // year: { bn: '১৪৩০', en: 1430 },
1341
+ // month: { bn: '১', en: 1 },
1342
+ // date: { bn: '১', en: 1 },
1343
+ // gregorian: { year: 2023, month: 4, date: 14 },
1344
+ // weekDay: 5,
1345
+ // isoWeekDay: 5
1346
+ // }
1347
+
1348
+ Object.prototype.toString.call(bnCal); // "[object ১৪৩০-০১-০১]"
1349
+
1350
+ bnCal[Symbol.toStringTag]; // "১৪৩০-০১-০১"
1351
+ ```
1352
+
1353
+ ### Remarks
1354
+
1355
+ - Returns the same value as [toJSON()](#tojson) method
1356
+ - Used by `Object.prototype.toString()` to identify the object type
1357
+ - Provides a human-readable representation in debugging contexts
1358
+
1359
+ ---
1360
+
1361
+ ## Utilities
1362
+
1363
+ The digit conversion utilities provide seamless conversion between Bangla (Bengali) digits (`০-৯`) and Latin (Arabic) digits (`0-9`). These functions are essential for applications that need to handle multilingual numeric representations, particularly in Bengali-language interfaces.
1364
+
1365
+ ### banglaToDigit()
1366
+
1367
+ Converts Bangla digits to Latin digits with flexible output options.
1368
+
1369
+ #### Signature
1370
+
1371
+ ```typescript
1372
+ banglaToDigit<Force extends boolean = true>(bnDigit: string, forceNumber?: Force): BnDigitResult<Force>
1373
+ ```
1374
+
1375
+ #### Parameters
1376
+
1377
+ - `bnDigit`: A string containing Bangla digits (`০-৯`)
1378
+ - `forceNumber`:
1379
+ - `true` (default): Returns a `number` (strips non-digit characters)
1380
+ - `false`: Returns a `string` (preserves non-digit characters)
1381
+
1382
+ #### Return Value
1383
+
1384
+ - When `forceNumber = true`: `number` (or `0` or `NaN` if no digits found)
1385
+ - When `forceNumber = false`: `string`
1386
+
1387
+ #### Behavior
1388
+
1389
+ | Input | `forceNumber = true` | `forceNumber = false` |
1390
+ | --------------------------- | ---------------------------- | ------------------------------------ |
1391
+ | Contains only Bangla digits | Returns converted number | Returns converted string |
1392
+ | Contains mixed characters | Returns number (digits only) | Returns string with converted digits |
1393
+ | Empty string | Returns `NaN` | Returns empty string |
1394
+ | No digits in string | Returns `0` or `NaN` | Returns the input string |
1395
+
1396
+ #### Examples
1397
+
1398
+ ```typescript
1399
+ // Default behavior (forceNumber = true)
1400
+ banglaToDigit('১২৩'); // 123
1401
+ banglaToDigit('৪৫৬৭'); // 4567
1402
+ banglaToDigit('১২৩abc'); // 123 (non-digits stripped)
1403
+ banglaToDigit('abc'); // 0 (no digits)
1404
+ banglaToDigit(''); // NaN
1405
+
1406
+ // Force string output (forceNumber = false)
1407
+ banglaToDigit('১২৩', false); // "123"
1408
+ banglaToDigit('১২৩abc', false); // "123abc" (preserves non-digits)
1409
+ banglaToDigit('৪৫৬৭', false); // "4567"
1410
+ banglaToDigit('abc', false); // "abc" (empty string)
1411
+ banglaToDigit('', false); // "" (empty string)
1412
+
1413
+ // Complex examples
1414
+ banglaToDigit('আমার বয়স ২৫ বছর'); // 25
1415
+ banglaToDigit('ফোন: ০১৭১২৩৪৫৬৭৮', false); // "ফোন: 01712345678"
1416
+ ```
1417
+
1418
+ #### Use Cases
1419
+
1420
+ - Parsing numeric input from Bengali users
1421
+ - Converting database values stored in Bangla digits to numbers for calculations
1422
+ - Processing multilingual forms that accept Bangla numbers
1423
+ - Localization utilities for Bengali applications
1424
+
1425
+ ---
1426
+
1427
+ ### digitToBangla()
1428
+
1429
+ Converts Latin digits to Bangla digits with optional non-digit preservation.
1430
+
1431
+ #### Signature
1432
+
1433
+ ```typescript
1434
+ digitToBangla(digit: number | string, preserveNonDigit = true): string
1435
+ ```
1436
+
1437
+ #### Parameters
1438
+
1439
+ - `digit`: A number or string containing Latin digits (0-9)
1440
+ - `preserveNonDigit`:
1441
+ - `true` (default): Preserves non-digit characters in output
1442
+ - `false`: Strips non-numeric characters from output
1443
+
1444
+ #### Return Value
1445
+
1446
+ `string` - Converted Bangla digit string (or empty string for invalid input)
1447
+
1448
+ #### Behavior
1449
+
1450
+ | Input | `preserveNonDigit = true` | `preserveNonDigit = false` |
1451
+ | ---------------------------- | --------------------------------- | ------------------------------ |
1452
+ | Number | Returns Bangla digits | Returns Bangla digits |
1453
+ | String with only digits | Returns Bangla digits | Returns Bangla digits |
1454
+ | String with mixed characters | Converts digits, preserves others | Converts digits, strips others |
1455
+ | Empty string | Returns empty string | Returns empty string |
1456
+ | Non-numeric string | Returns original string | Returns empty string |
1457
+
1458
+ #### Examples
1459
+
1460
+ ```typescript
1461
+ // Default behavior (preserveNonDigit = true)
1462
+ digitToBangla(123); // "১২৩"
1463
+ digitToBangla(4567); // "৪৫৬৭"
1464
+ digitToBangla('123'); // "১২৩"
1465
+ digitToBangla('12ab34'); // "১২ab৩৪"
1466
+ digitToBangla('abc'); // "abc"
1467
+ digitToBangla(''); // ""
1468
+
1469
+ // Strip non-digits (preserveNonDigit = false)
1470
+ digitToBangla('12ab34', false); // "১২৩৪" (non-digits removed)
1471
+ digitToBangla('abc', false); // "" (no digits)
1472
+ digitToBangla('১২৩', false); // "১২৩" (already Bangla digits)
1473
+ digitToBangla('', false); // ""
1474
+
1475
+ // Complex examples
1476
+ digitToBangla('Phone: 01712345678');
1477
+ // "Phone: ০১৭১২৩৪৫৬৭৮"
1478
+
1479
+ digitToBangla('আমার বয়স 25 বছর');
1480
+ // "আমার বয়স ২৫ বছর"
1481
+
1482
+ digitToBangla('Price: $99.99', false);
1483
+ // "৯৯৯৯" (strips all non-digits)
1484
+ ```
1485
+
1486
+ #### Use Cases
1487
+
1488
+ - Displaying numbers in Bengali interfaces
1489
+ - Formatting prices, quantities, and measurements in Bengali
1490
+ - Generating multilingual receipts and invoices
1491
+ - Localizing numeric data for Bengali users
1492
+
1493
+ ---
1494
+
1495
+ ### Type Definitions
1496
+
1497
+ #### BanglaDigit
1498
+
1499
+ ```typescript
1500
+ type BanglaDigit = '০' | '১' | '২' | '৩' | '৪' | '৫' | '৬' | '৭' | '৮' | '৯';
1501
+ ```
1502
+
1503
+ #### BnDigitResult
1504
+
1505
+ ```typescript
1506
+ type BnDigitResult<Force extends boolean> = Force extends true ? number : string;
1507
+ ```
1508
+
1509
+ ---
1510
+
1511
+ ### Complete Examples
1512
+
1513
+ #### Example 1: Form Processing
1514
+
1515
+ ```typescript
1516
+ // User inputs Bangla digits in a form
1517
+ const userInput = '২৫০০';
1518
+ const numericValue = banglaToDigit(userInput); // 2500
1519
+
1520
+ // Process the number
1521
+ const discounted = numericValue * 0.9; // 2250
1522
+
1523
+ // Display result in Bangla
1524
+ const displayValue = digitToBangla(discounted); // "২২৫০"
1525
+ ```
1526
+
1527
+ #### Example 2: Multilingual Price Display
1528
+
1529
+ ```typescript
1530
+ function formatPrice(price: number, locale: 'bn' | 'en' = 'en'): string {
1531
+ if (locale === 'bn') {
1532
+ const banglaPrice = digitToBangla(price);
1533
+ return `৳${banglaPrice}`;
1534
+ }
1535
+ return `$${price.toFixed(2)}`;
1536
+ }
1537
+
1538
+ formatPrice(1250, 'bn'); // "৳১২৫০"
1539
+ formatPrice(1250, 'en'); // "$1250.00"
1540
+ ```
1541
+
1542
+ #### Example 3: Phone Number Formatting
1543
+
1544
+ ```typescript
1545
+ // Standardize phone number input
1546
+ function formatPhoneNumber(phone: string): string {
1547
+ // Convert any Bangla digits to Latin
1548
+ const latinPhone = banglaToDigit(phone, false); // "01712345678"
1549
+
1550
+ // Format with hyphens
1551
+ return `${latinPhone.slice(0, 3)}-${latinPhone.slice(3, 6)}-${latinPhone.slice(6)}`;
1552
+ }
1553
+
1554
+ formatPhoneNumber('০১৭১২৩৪৫৬৭৮'); // "017-123-45678"
1555
+ ```
1556
+
1557
+ > [!TIP]
1558
+ > **Best Practices**
1559
+ >
1560
+ > - **Use `banglaToDigit()` with `forceNumber = true`** when you need to perform calculations
1561
+ > - **Use `banglaToDigit()` with `forceNumber = false`** when you need to preserve text formatting
1562
+ > - **Use `digitToBangla()` with `preserveNonDigit = true`** for displaying formatted text
1563
+ > - **Use `digitToBangla()` with `preserveNonDigit = false`** for generating clean numeric strings
1564
+ > - **Always validate input** before conversion to handle edge cases
1565
+
1566
+ ---
1567
+
1568
+ ## Type Definitions
1569
+
1570
+ ### LocaleCode
1571
+
1572
+ ```typescript
1573
+ type $BnEn = 'bn' | 'en'
1574
+ ```
1575
+
1576
+ Supported locale codes for Bangla calendar output.
1577
+
1578
+ ### BanglaYear
1579
+
1580
+ ```typescript
1581
+ type BanglaYear = BanglaDigit | `${$BnOnes}${BanglaDigit}` | `${$BnOnes}${BanglaDigit}${BanglaDigit}` | Repeat<BanglaDigit, 4>
1582
+ ```
1583
+
1584
+ Bangla year from `০-৯৯৯৯`.
1585
+
1586
+ ### BanglaMonth
1587
+
1588
+ ```typescript
1589
+ type BanglaMonth = $BnOnes | $BnOnesPadded | '১০' | '১১' | '১২'
1590
+ ```
1591
+
1592
+ Bangla month from `১-১২`.
1593
+
1594
+ ### BanglaDate
1595
+
1596
+ ```typescript
1597
+ type BanglaDate = $BnOnes | $BnOnesPadded | `১${BanglaDigit}` | `২${BanglaDigit}` | '৩০' | '৩১'
1598
+ ```
1599
+
1600
+ Bangla date of month from `১-৩১`.
1601
+
1602
+ ### BnCalendarVariant
1603
+
1604
+ ```typescript
1605
+ type BnCalendarVariant = 'revised-2019' | 'revised-1966'
1606
+ ```
1607
+
1608
+ Calendar variant types.
1609
+
1610
+ ### BnCalendarConfig
1611
+
1612
+ ```typescript
1613
+ interface BnCalendarConfig {
1614
+ variant?: BnCalendarVariant;
1615
+ }
1616
+ ```
1617
+
1618
+ Configuration object for Bangla Calendar system.
1619
+
1620
+ ### BanglaDateFormat
1621
+
1622
+ ```typescript
1623
+ type BanglaDateFormat = LooseLiteral<DateFormatToken | DateWithSeasonToken>
1624
+ ```
1625
+
1626
+ Format tokens for Bangla date formatting.
1627
+
1628
+ ---
1629
+
1630
+ ## 🔗 Related Packages
1631
+
1632
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
1633
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-toolbox">
1634
+ <img src="https://img.shields.io/badge/Utility_Library-nhb--toolbox-blue" alt="nhb-toolbox" />
1635
+ </a>
1636
+ </div>
1637
+
1638
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
1639
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-hooks">
1640
+ <img src="https://img.shields.io/badge/React_Hooks-nhb--hooks-blue" alt="nhb-hooks" />
1641
+ </a>
1642
+ </div>
1643
+
1644
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
1645
+ <a target="_blank" href="https://www.npmjs.com/package/locality-idb">
1646
+ <img src="https://img.shields.io/badge/IndexedDB_ORM-locality--idb-darkviolet" alt="locality-idb" />
1647
+ </a>
1648
+ </div>
1649
+
1650
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
1651
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-scripts">
1652
+ <img src="https://img.shields.io/badge/Development_Scripts-nhb--scripts-red" alt="nhb-scripts" />
1653
+ </a>
1654
+ </div>
1655
+
1656
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
1657
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-express">
1658
+ <img src="https://img.shields.io/badge/Express_Server_Scaffolder-nhb--express-orange" alt="nhb-express" />
1659
+ </a>
1660
+ </div>
1661
+
1662
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
1663
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-anagram-generator">
1664
+ <img src="https://img.shields.io/badge/Anagram_Generator-nhb--anagram--generator-teal" alt="nhb-anagram-generator" />
1665
+ </a>
1666
+ </div>
1667
+
1668
+ ---
1669
+
1670
+ ## License
1671
+
1672
+ This project is licensed under the [Apache License 2.0](LICENSE) with the following additional requirement:
1673
+
1674
+ **Additional Requirement:**
1675
+
1676
+ > Any fork, derivative work, or redistribution of this project must include clear attribution to [**Nazmul Hassan**](https://github.com/nazmul-nhb) in both the source code and any publicly available documentation.
1677
+
1678
+ You are free to use, modify, and distribute this project under the terms of the Apache 2.0 License, provided that appropriate credit is given.
1679
+
1680
+ ---
1681
+
1682
+ Built with ❤️ by [**Nazmul Hassan**](https://nazmul-nhb.dev)