nepali-date-library 1.1.7 → 1.1.8

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 CHANGED
@@ -33,10 +33,6 @@ console.log(today.toString()); // 2081/10/15
33
33
  const bsDate = ADtoBS('2025-02-22'); // "2081-10-10"
34
34
  const adDate = BStoAD('2081-10-14'); // "2025-02-26"
35
35
 
36
- // Convert with custom formats
37
- const customBS = ADtoBS('22/02/2025', 'DD/MM/YYYY', 'YYYY.MM.DD'); // "2081.10.10"
38
- const customAD = BStoAD('10.10.2081', 'DD.MM.YYYY', 'MM-DD-YYYY'); // "10-10-2025"
39
-
40
36
  // Format dates
41
37
  const formatted = today.format('MMMM DD, YYYY'); // "Magh 15, 2081"
42
38
  const nepali = today.format('mmmm dd, yyyy'); // "माघ १५, २०८१"
@@ -61,63 +57,35 @@ import {
61
57
 
62
58
  ### Date Conversion Utilities
63
59
 
64
- #### `ADtoBS(adDate: string, inputFormat?: string, outputFormat?: string): string`
60
+ #### `ADtoBS(adDate: string): string`
65
61
 
66
62
  Converts an Anno Domini (AD) date to a Bikram Sambat (BS) date with custom format support.
67
63
 
68
64
  **Parameters:**
69
65
  - `adDate` - The AD date string
70
- - `inputFormat` - The input date format pattern (default: "YYYY-MM-DD")
71
- - `outputFormat` - The output date format pattern (default: "YYYY-MM-DD")
72
66
 
73
67
  **Returns:** The corresponding BS date in the specified output format
74
68
 
75
69
  **Supported Input/Output Formats:**
76
- - `YYYY-MM-DD`, `YYYY/MM/DD`, `YYYY.MM.DD`
77
- - `DD-MM-YYYY`, `DD/MM/YYYY`, `DD.MM.YYYY`
78
- - `MM-DD-YYYY`, `MM/DD/YYYY`, `MM.DD.YYYY`
79
- - `DD MM YYYY`, `YYYY MM DD`
70
+ - `YYYY-MM-DD`, `YYYY/MM/DD`
80
71
 
81
72
  ```typescript
82
73
  // Default format conversion
83
74
  const bsDate = ADtoBS('2025-02-22'); // "2081-10-10"
84
-
85
- // Custom input format
86
- const bsDate2 = ADtoBS('22/02/2025', 'DD/MM/YYYY'); // "2081-10-10"
87
-
88
- // Custom input and output formats
89
- const bsDate3 = ADtoBS('22.02.2025', 'DD.MM.YYYY', 'YYYY/MM/DD'); // "2081/10/10"
90
-
91
- // US format to Nepali format
92
- const bsDate4 = ADtoBS('02-22-2025', 'MM-DD-YYYY', 'DD.MM.YYYY'); // "10.10.2081"
93
75
  ```
94
76
 
95
- #### `BStoAD(bsDate: string, inputFormat?: string, outputFormat?: string): string`
77
+ #### `BStoAD(bsDate: string): string`
96
78
 
97
79
  Converts a Bikram Sambat (BS) date to an Anno Domini (AD) date with custom format support.
98
80
 
99
81
  **Parameters:**
100
82
  - `bsDate` - The BS date string (supports both English and Nepali numerals)
101
- - `inputFormat` - The input date format pattern (default: "YYYY-MM-DD")
102
- - `outputFormat` - The output date format pattern (default: "YYYY-MM-DD")
103
83
 
104
84
  **Returns:** The corresponding AD date in the specified output format
105
85
 
106
86
  ```typescript
107
87
  // Default format conversion
108
88
  const adDate = BStoAD('2081-10-14'); // "2025-02-26"
109
-
110
- // Custom input format
111
- const adDate2 = BStoAD('14/10/2081', 'DD/MM/YYYY'); // "2025-02-26"
112
-
113
- // Custom input and output formats
114
- const adDate3 = BStoAD('14.10.2081', 'DD.MM.YYYY', 'MM/DD/YYYY'); // "02/26/2025"
115
-
116
- // Nepali numerals support
117
- const adDate4 = BStoAD('२०८१-१०-१४'); // "2025-02-26"
118
-
119
- // Mixed format conversion
120
- const adDate5 = BStoAD('10 14 2081', 'MM DD YYYY', 'DD-MM-YYYY'); // "26-02-2025"
121
89
  ```
122
90
 
123
91
  ### NepaliDate Class
@@ -406,70 +374,6 @@ NepaliDate.maximum(); // Latest supported date
406
374
  const copy = date.clone(); // Deep copy of NepaliDate
407
375
  ```
408
376
 
409
- ## Advanced Format Examples
410
-
411
- ### Multi-Format Date Conversion
412
-
413
- ```typescript
414
- import { ADtoBS, BStoAD } from 'nepali-date-library';
415
-
416
- // Converting from various AD formats to BS
417
- const europeanToBS = ADtoBS('22/02/2025', 'DD/MM/YYYY'); // "2081-10-10"
418
- const americanToBS = ADtoBS('02-22-2025', 'MM-DD-YYYY'); // "2081-10-10"
419
- const dotFormatToBS = ADtoBS('2025.02.22', 'YYYY.MM.DD'); // "2081-10-10"
420
- const spaceFormatToBS = ADtoBS('22 02 2025', 'DD MM YYYY'); // "2081-10-10"
421
-
422
- // Converting with custom output formats
423
- const customOutput1 = ADtoBS('2025-02-22', 'YYYY-MM-DD', 'DD/MM/YYYY'); // "10/10/2081"
424
- const customOutput2 = ADtoBS('22/02/2025', 'DD/MM/YYYY', 'YYYY.MM.DD'); // "2081.10.10"
425
-
426
- // Converting from various BS formats to AD
427
- const bsSlashToAD = BStoAD('10/10/2081', 'DD/MM/YYYY'); // "2025-02-22"
428
- const bsDotToAD = BStoAD('2081.10.10', 'YYYY.MM.DD'); // "2025-02-22"
429
- const bsSpaceToAD = BStoAD('10 10 2081', 'DD MM YYYY'); // "2025-02-22"
430
-
431
- // Converting with custom AD output formats
432
- const adCustom1 = BStoAD('2081-10-10', 'YYYY-MM-DD', 'MM/DD/YYYY'); // "02/22/2025"
433
- const adCustom2 = BStoAD('10/10/2081', 'DD/MM/YYYY', 'DD.MM.YYYY'); // "22.02.2025"
434
- ```
435
-
436
- ### Handling Different Date Sources
437
-
438
- ```typescript
439
- // API data conversion utility
440
- function convertAPIDate(dateStr: string, sourceFormat: string, targetCalendar: 'AD' | 'BS', targetFormat: string = 'YYYY-MM-DD') {
441
- try {
442
- if (targetCalendar === 'BS') {
443
- return ADtoBS(dateStr, sourceFormat, targetFormat);
444
- } else {
445
- return BStoAD(dateStr, sourceFormat, targetFormat);
446
- }
447
- } catch (error) {
448
- throw new Error(`Date conversion failed: ${error.message}`);
449
- }
450
- }
451
-
452
- // Usage examples
453
- const dbDate = convertAPIDate('2025/02/22', 'YYYY/MM/DD', 'BS', 'DD-MM-YYYY'); // "10-10-2081"
454
- const userInput = convertAPIDate('22.10.2081', 'DD.MM.YYYY', 'AD', 'MM/DD/YYYY'); // "02/26/2025"
455
- const csvDate = convertAPIDate('02 22 2025', 'MM DD YYYY', 'BS', 'YYYY/MM/DD'); // "2081/10/10"
456
- ```
457
-
458
- ### Nepali Numeral Support
459
-
460
- The library automatically handles Nepali numerals in input:
461
-
462
- ```typescript
463
- // Both of these work identically
464
- const withEnglishNumerals = BStoAD('2081-10-14');
465
- const withNepaliNumerals = BStoAD('२०८१-१०-१४');
466
-
467
- // Mixed numerals are also supported
468
- const mixedNumerals = BStoAD('२०८१-10-१४');
469
-
470
- // All produce the same result: "2025-02-26"
471
- ```
472
-
473
377
  ### Constants
474
378
 
475
379
  #### Calendar Data
@@ -547,30 +451,6 @@ console.log(nextMonth.format('YYYY-MM-DD')); // "2081-11-15"
547
451
  console.log(nextYear.format('YYYY-MM-DD')); // "2082-10-15"
548
452
  ```
549
453
 
550
- ### Working with Different Date Formats
551
-
552
- ```typescript
553
- import { ADtoBS, BStoAD } from 'nepali-date-library';
554
-
555
- // Database integration - handle various formats
556
- function handleDatabaseDate(dateStr: string, sourceFormat: string): string {
557
- // Convert to standard BS format for storage
558
- return ADtoBS(dateStr, sourceFormat, 'YYYY-MM-DD');
559
- }
560
-
561
- // User interface - display in user's preferred format
562
- function displayUserDate(bsDate: string, userPreference: string): string {
563
- return BStoAD(bsDate, 'YYYY-MM-DD', userPreference);
564
- }
565
-
566
- // Examples
567
- const dbDate1 = handleDatabaseDate('22/02/2025', 'DD/MM/YYYY'); // "2081-10-10"
568
- const dbDate2 = handleDatabaseDate('02.22.2025', 'MM.DD.YYYY'); // "2081-10-10"
569
-
570
- const userDate1 = displayUserDate('2081-10-10', 'DD/MM/YYYY'); // "22/02/2025"
571
- const userDate2 = displayUserDate('2081-10-10', 'MM-DD-YYYY'); // "02-22-2025"
572
- ```
573
-
574
454
  ### Working with Localized Names
575
455
 
576
456
  ```typescript
@@ -1,2 +1,12 @@
1
- import { NepaliDate } from '../NepaliDate';
2
- export default function format(nepaliDate: NepaliDate, formatStr: string): string;
1
+ /**
2
+ * Converts a Anno Domini (AD) date to an Bikram Sambat(BS) Date.
3
+ * @param {string} adDate - The Anno Domini (AD) date in "YYYY-MM-DD" format.
4
+ * @returns {string} - The corresponding Bikram Sambat(BS) date in "YYYY-MM-DD" format.
5
+ */
6
+ export declare const ADtoBS: (adDate: string) => string;
7
+ /**
8
+ * Converts a Bikram Sambat(BS) to an Anno Domini (AD) Date.
9
+ * @param bsDate - The Bikram Sambat(BS) date in "YYYY-MM-DD" format.
10
+ * @returns {string} - The corresponding Anno Domini (AD) date in "YYYY-MM-DD" format.
11
+ */
12
+ export declare function BStoAD(bsDate: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nepali-date-library",
3
3
  "private": false,
4
- "version": "1.1.7",
4
+ "version": "1.1.8",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"