@remotemerge/nepali-date-converter 1.0.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/LICENSE +1 -1
- package/README.md +379 -89
- package/ndc-browser.js +1 -2
- package/ndc-node.js +1 -2
- package/ndc.js +298 -303
- package/package.json +3 -3
- package/src/date-helper.d.ts +8 -0
- package/src/index.d.ts +26 -0
- package/index.d.ts +0 -26
- package/ndc-browser.js.map +0 -1
- package/ndc-node.js.map +0 -1
- package/ndc.js.map +0 -1
- /package/{years.d.ts → src/years.d.ts} +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,184 +1,474 @@
|
|
|
1
1
|
# 📅 Nepali Date Converter
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@remotemerge/nepali-date-converter)
|
|
4
|
-
[](https://www.npmjs.com/package/@remotemerge/nepali-date-converter)
|
|
4
|
+
[](https://github.com/remotemerge/nepali-date-converter/actions/workflows/test.yml)
|
|
5
|
+
[](https://github.com/remotemerge/nepali-date-converter/actions/workflows/test.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/@remotemerge/nepali-date-converter)
|
|
7
|
+
[](https://bundlephobia.com/package/@remotemerge/nepali-date-converter)
|
|
8
|
+
[](LICENSE)
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
> **Fast, accurate, and lightweight JavaScript library for converting dates between Nepali Bikram Sambat (BS) and Gregorian/English (AD) calendars.**
|
|
11
|
+
|
|
12
|
+
**Nepali Date Converter (NDC)** is a modern, production-ready JavaScript library designed for seamless date conversions between the **Bikram Sambat (BS)** calendar used in Nepal and the **Gregorian (AD)** calendar used internationally. Whether you're building Nepali calendar applications, event management systems, government portals, or localization features, NDC provides **100% accurate** date conversions for the range **1975 BS to 2099 BS** (1918 AD to 2043 AD).
|
|
13
|
+
|
|
14
|
+
Built with **TypeScript** and powered by **Bun**, this library is optimized for performance with a tiny bundle size (~5 KiB minified), making it perfect for web applications, Node.js services, mobile apps, and server-side rendering.
|
|
10
15
|
|
|
11
16
|
---
|
|
12
17
|
|
|
13
18
|
## ✨ Features
|
|
14
19
|
|
|
15
|
-
- **Accurate
|
|
16
|
-
- **Wide Date Range**: Supports
|
|
17
|
-
- **Lightweight**:
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
20
|
+
- 🎯 **Accurate Conversions**: 100% accurate date conversions between Bikram Sambat (BS) and Gregorian (AD) calendars
|
|
21
|
+
- 📆 **Wide Date Range**: Supports **1975 BS to 2099 BS** (April 13, 1918 AD to April 13, 2043 AD)
|
|
22
|
+
- ⚡ **Lightweight & Fast**: Only **~5 KiB** minified and **~1.8 KiB** gzipped — optimized for fast page loads
|
|
23
|
+
- 🇳🇵 **Nepali Unicode Support**: Accepts Nepali numerals (०-९) and multiple date format separators
|
|
24
|
+
- 🔒 **TypeScript Native**: Full TypeScript support with built-in type definitions and autocompletion
|
|
25
|
+
- 🌐 **Universal Compatibility**: Works in Node.js (v20+), modern browsers, and all major bundlers (Vite, Webpack, Rollup, esbuild)
|
|
26
|
+
- 🚀 **Modern Tooling**: Built with Bun, Vite, Oxlint, and Oxfmt for fast development and builds
|
|
27
|
+
- 🧪 **Well-Tested**: Comprehensive test suite validating every date in the supported range
|
|
28
|
+
- 🐳 **Docker Ready**: Includes Docker configuration for consistent cross-platform development
|
|
29
|
+
- 📦 **Zero Dependencies**: Minimal runtime footprint with only essential dependencies
|
|
21
30
|
|
|
22
31
|
---
|
|
23
32
|
|
|
24
|
-
##
|
|
33
|
+
## 📦 Installation
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
### npm
|
|
27
36
|
|
|
28
37
|
```bash
|
|
29
38
|
npm install @remotemerge/nepali-date-converter
|
|
30
39
|
```
|
|
31
40
|
|
|
32
|
-
|
|
41
|
+
### Yarn
|
|
33
42
|
|
|
34
43
|
```bash
|
|
35
44
|
yarn add @remotemerge/nepali-date-converter
|
|
36
45
|
```
|
|
37
46
|
|
|
47
|
+
### pnpm
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pnpm add @remotemerge/nepali-date-converter
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Bun
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
bun add @remotemerge/nepali-date-converter
|
|
57
|
+
```
|
|
58
|
+
|
|
38
59
|
---
|
|
39
60
|
|
|
40
|
-
##
|
|
41
|
-
|
|
61
|
+
## 🚀 Quick Start
|
|
62
|
+
|
|
63
|
+
The Nepali Date Converter library is straightforward to use. Import the `DateConverter` class, instantiate it with a date string in `YYYY-MM-DD` format, and call either `.toAd()` to convert from Bikram Sambat to Gregorian, or `.toBs()` to convert from Gregorian to Bikram Sambat.
|
|
42
64
|
|
|
43
|
-
###
|
|
65
|
+
### ES Modules (Recommended)
|
|
44
66
|
|
|
45
|
-
#### ES Modules (Recommended for Modern JavaScript/TypeScript Projects)
|
|
46
67
|
```javascript
|
|
47
|
-
import DateConverter from
|
|
68
|
+
import DateConverter from "@remotemerge/nepali-date-converter";
|
|
69
|
+
|
|
70
|
+
// Convert BS to AD
|
|
71
|
+
const adDate = new DateConverter("2080-01-15").toAd();
|
|
72
|
+
console.log(adDate);
|
|
73
|
+
// Output: { year: 2023, month: 4, date: 28, day: 'Friday' }
|
|
74
|
+
|
|
75
|
+
// Convert AD to BS
|
|
76
|
+
const bsDate = new DateConverter("2023-04-28").toBs();
|
|
77
|
+
console.log(bsDate);
|
|
78
|
+
// Output: { year: 2080, month: 1, date: 15, day: 'Friday' }
|
|
48
79
|
```
|
|
49
80
|
|
|
50
|
-
|
|
81
|
+
### CommonJS
|
|
82
|
+
|
|
51
83
|
```javascript
|
|
52
|
-
const DateConverter = require(
|
|
84
|
+
const DateConverter = require("@remotemerge/nepali-date-converter");
|
|
85
|
+
|
|
86
|
+
const converted = new DateConverter("2080-01-15").toAd();
|
|
87
|
+
console.log(converted);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Browser (CDN)
|
|
91
|
+
|
|
92
|
+
```html
|
|
93
|
+
|
|
94
|
+
<script src="https://cdn.jsdelivr.net/npm/@remotemerge/nepali-date-converter@1/dist/ndc-browser.js"></script>
|
|
95
|
+
<script>
|
|
96
|
+
const converted = new DateConverter("2080-01-15").toAd();
|
|
97
|
+
console.log(converted);
|
|
98
|
+
</script>
|
|
53
99
|
```
|
|
54
100
|
|
|
55
101
|
---
|
|
56
102
|
|
|
57
|
-
|
|
103
|
+
## 📖 API Reference
|
|
58
104
|
|
|
59
|
-
|
|
105
|
+
The `DateConverter` class provides a simple, intuitive API for converting dates between the Nepali Bikram Sambat calendar and the Gregorian calendar. All methods return plain JavaScript objects with full type safety when using TypeScript.
|
|
60
106
|
|
|
61
|
-
|
|
62
|
-
// Convert BS date '2079-10-17' to AD
|
|
63
|
-
const converted = new DateConverter('2079-10-17').toAd();
|
|
64
|
-
console.log(converted);
|
|
65
|
-
```
|
|
107
|
+
### Constructor
|
|
66
108
|
|
|
67
|
-
**Output**:
|
|
68
109
|
```text
|
|
69
|
-
|
|
110
|
+
new DateConverter(date: string)
|
|
70
111
|
```
|
|
71
112
|
|
|
72
|
-
|
|
73
|
-
- **Output**: An object containing the converted Gregorian date (`year`, `month`, `date`) and the day of the week (`day`).
|
|
74
|
-
|
|
75
|
-
---
|
|
113
|
+
**Parameters:**
|
|
76
114
|
|
|
77
|
-
|
|
115
|
+
- `date` (string): Date string in `YYYY-MM-DD` format. Accepts both BS (Nepali) and AD (Gregorian) dates.
|
|
116
|
+
- Supports multiple separators: `-`, `/`, `.`, `,`, `|`
|
|
117
|
+
- Supports Nepali Unicode numerals (e.g., `२०८०-०१-१५` for 2080-01-15)
|
|
118
|
+
- Automatically detects whether the input is BS or AD based on the date range
|
|
78
119
|
|
|
79
|
-
|
|
120
|
+
**Examples:**
|
|
80
121
|
|
|
81
122
|
```javascript
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
123
|
+
new DateConverter("2080-01-15"); // Standard BS format with hyphen
|
|
124
|
+
new DateConverter("2080/01/15"); // Slash separator
|
|
125
|
+
new DateConverter("२०८०-०१-१५"); // Nepali numerals (Devanagari script)
|
|
85
126
|
```
|
|
86
127
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
128
|
+
### Methods
|
|
129
|
+
|
|
130
|
+
#### `.toAd()`
|
|
131
|
+
|
|
132
|
+
Converts a Bikram Sambat (BS) date to its equivalent Gregorian (AD) date. This method is essential for displaying Nepali dates in international format for web applications, mobile apps, and data processing systems.
|
|
133
|
+
|
|
134
|
+
**Returns:**
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
{
|
|
138
|
+
year: number; // AD year (e.g., 2023)
|
|
139
|
+
month: number; // AD month (1-12)
|
|
140
|
+
date: number; // AD day of month (1-31)
|
|
141
|
+
day: string; // Day name (e.g., "Monday", "Tuesday")
|
|
142
|
+
}
|
|
90
143
|
```
|
|
91
144
|
|
|
92
|
-
|
|
93
|
-
- **Output**: An object containing the converted Bikram Sambat date (`year`, `month`, `date`) and the day of the week (`day`).
|
|
145
|
+
**Example:**
|
|
94
146
|
|
|
95
|
-
|
|
147
|
+
```javascript
|
|
148
|
+
// Convert Nepali date to English/Gregorian date
|
|
149
|
+
const result = new DateConverter("2080-01-15").toAd();
|
|
150
|
+
// { year: 2023, month: 4, date: 28, day: 'Friday' }
|
|
151
|
+
```
|
|
96
152
|
|
|
97
|
-
|
|
153
|
+
#### `.toBs()`
|
|
98
154
|
|
|
99
|
-
|
|
155
|
+
Converts a Gregorian (AD) date to its equivalent Bikram Sambat (BS) date. Use this method when you need to display dates in Nepali calendar format for local audiences, festivals, and government systems in Nepal.
|
|
100
156
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
157
|
+
**Returns:**
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
{
|
|
161
|
+
year: number; // BS year (e.g., 2080)
|
|
162
|
+
month: number; // BS month (1-12)
|
|
163
|
+
date: number; // BS day of month (1-32, varies by month)
|
|
164
|
+
day: string; // Day name (e.g., "Monday", "Tuesday")
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Example:**
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
// Convert English/Gregorian date to Nepali date
|
|
172
|
+
const result = new DateConverter("2023-04-28").toBs();
|
|
173
|
+
// { year: 2080, month: 1, date: 15, day: 'Friday' }
|
|
108
174
|
```
|
|
109
175
|
|
|
110
176
|
---
|
|
111
177
|
|
|
112
|
-
|
|
178
|
+
## 💡 Usage Examples
|
|
113
179
|
|
|
114
|
-
|
|
115
|
-
2. **Historical Data**: Work with historical records that use the Bikram Sambat calendar.
|
|
116
|
-
3. **Localization**: Display dates in the Nepali calendar for Nepali-speaking users.
|
|
180
|
+
The Nepali Date Converter library is versatile and can be used in various real-world scenarios. Below are practical examples demonstrating how to integrate the library into your applications, from festival date conversions to historical data processing and multilingual support.
|
|
117
181
|
|
|
118
|
-
|
|
182
|
+
### Basic Conversions
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
import DateConverter from "@remotemerge/nepali-date-converter";
|
|
119
186
|
|
|
120
|
-
|
|
187
|
+
// Festival date conversion - Dashain, Tihar, and other Nepali festivals
|
|
188
|
+
const dashainDate = new DateConverter("2080-07-01").toAd();
|
|
189
|
+
console.log(`Dashain 2080 starts: ${dashainDate.month}/${dashainDate.date}/${dashainDate.year}`);
|
|
121
190
|
|
|
122
|
-
|
|
123
|
-
|
|
191
|
+
// Historical record conversion - Nepal history, government documents
|
|
192
|
+
const historicalDate = new DateConverter("1950-01-01").toBs();
|
|
193
|
+
console.log(`January 1, 1950 AD = ${historicalDate.year}-${historicalDate.month}-${historicalDate.date} BS`);
|
|
194
|
+
|
|
195
|
+
// Birthday and anniversary conversions
|
|
196
|
+
const birthdayBS = new DateConverter("2024-06-15").toBs();
|
|
197
|
+
console.log(`Your Nepali birthday: ${birthdayBS.year}/${birthdayBS.month}/${birthdayBS.date}`);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Error Handling
|
|
124
201
|
|
|
125
202
|
```javascript
|
|
126
203
|
try {
|
|
127
|
-
const converted = new DateConverter(
|
|
204
|
+
const converted = new DateConverter("2100-01-01").toAd();
|
|
128
205
|
} catch (error) {
|
|
129
|
-
console.error(error.message);
|
|
206
|
+
console.error(error.message);
|
|
207
|
+
// "The input date is out of supported range."
|
|
130
208
|
}
|
|
131
209
|
```
|
|
132
210
|
|
|
133
|
-
|
|
134
|
-
The library includes built-in TypeScript support, so you get full type checking and autocompletion in your editor.
|
|
211
|
+
### TypeScript Usage
|
|
135
212
|
|
|
136
213
|
```typescript
|
|
137
|
-
import DateConverter from
|
|
214
|
+
import DateConverter from "@remotemerge/nepali-date-converter";
|
|
215
|
+
|
|
216
|
+
const converter = new DateConverter("2080-01-15");
|
|
217
|
+
const result = converter.toAd();
|
|
138
218
|
|
|
139
|
-
|
|
140
|
-
console.log(
|
|
219
|
+
// Full type safety and autocompletion
|
|
220
|
+
console.log(result.year); // number
|
|
221
|
+
console.log(result.month); // number
|
|
222
|
+
console.log(result.date); // number
|
|
223
|
+
console.log(result.day); // string
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Multiple Date Formats
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
// All of these work identically:
|
|
230
|
+
new DateConverter("2080-01-15").toAd(); // Hyphen
|
|
231
|
+
new DateConverter("2080/01/15").toAd(); // Slash
|
|
232
|
+
new DateConverter("2080.01.15").toAd(); // Dot
|
|
233
|
+
new DateConverter("2080,01,15").toAd(); // Comma
|
|
234
|
+
new DateConverter("2080|01|15").toAd(); // Pipe
|
|
235
|
+
new DateConverter("२०८०-०१-१५").toAd(); // Nepali numerals
|
|
141
236
|
```
|
|
142
237
|
|
|
143
238
|
---
|
|
144
239
|
|
|
145
|
-
##
|
|
240
|
+
## 🇳🇵 About Bikram Sambat Calendar
|
|
146
241
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
242
|
+
**Bikram Sambat (BS)**, also known as **Bikrami calendar** or **Nepali calendar**, is the official calendar of Nepal and is widely used throughout the country for government, business, and cultural purposes. Named after the legendary Indian king Vikramaditya, this lunar calendar system is approximately 56.7 years ahead of the Gregorian calendar.
|
|
243
|
+
|
|
244
|
+
### Key Facts About Bikram Sambat
|
|
245
|
+
|
|
246
|
+
- **Official Calendar of Nepal**: Used by the Government of Nepal for fiscal years, official documents, and public holidays
|
|
247
|
+
- **Lunar-Based System**: Months are based on lunar cycles, with each month having 29–32 days
|
|
248
|
+
- **New Year**: Falls in mid-April (Baishakh 1), marking the beginning of spring in Nepal
|
|
249
|
+
- **Cultural Significance**: Determines dates for major festivals like Dashain, Tihar, Holi, and Teej
|
|
250
|
+
- **Historical Origins**: Dates back to 57 BC, making it one of the oldest calendar systems still in use
|
|
251
|
+
- **Geographic Usage**: Primarily used in Nepal and parts of India (especially in northern states)
|
|
252
|
+
|
|
253
|
+
The Nepali Date Converter library handles the complex mathematics required to convert between these two calendar systems accurately, accounting for varying month lengths and leap years in the Bikram Sambat system.
|
|
151
254
|
|
|
152
255
|
---
|
|
153
256
|
|
|
154
|
-
##
|
|
257
|
+
## 🛠️ Development
|
|
155
258
|
|
|
156
|
-
|
|
259
|
+
This section provides a comprehensive guide for developers who want to contribute to the Nepali Date Converter project or build it locally. The project uses modern JavaScript tooling, including Bun for package management and testing, Vite for building, and Oxlint/Oxfmt for code quality.
|
|
157
260
|
|
|
158
|
-
|
|
261
|
+
### Prerequisites
|
|
159
262
|
|
|
160
|
-
|
|
263
|
+
- **Bun** >= 1.3.11 (required for development and building)
|
|
264
|
+
- Node.js >= 20 (for consuming the package)
|
|
161
265
|
|
|
162
|
-
|
|
163
|
-
- Returns: `{ year: number, month: number, date: number, day: string }`
|
|
266
|
+
### Setup
|
|
164
267
|
|
|
165
|
-
|
|
166
|
-
|
|
268
|
+
```bash
|
|
269
|
+
# Navigate to the source directory
|
|
270
|
+
cd html
|
|
271
|
+
|
|
272
|
+
# Install dependencies
|
|
273
|
+
bun install
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Available Scripts
|
|
277
|
+
|
|
278
|
+
| Command | Description |
|
|
279
|
+
|--------------------|---------------------------------------------------------------------|
|
|
280
|
+
| `bun run dev` | Start development server with hot reload (localhost:3000) |
|
|
281
|
+
| `bun run build` | Build production bundles (ESM, CJS, IIFE) + TypeScript declarations |
|
|
282
|
+
| `bun run test` | Run test suite using Bun's native test runner |
|
|
283
|
+
| `bun run lint` | Run Oxlint and Oxfmt checks |
|
|
284
|
+
| `bun run lint:fix` | Auto-fix linting and formatting issues |
|
|
285
|
+
|
|
286
|
+
### Project Structure
|
|
287
|
+
|
|
288
|
+
```text
|
|
289
|
+
html/
|
|
290
|
+
├── src/
|
|
291
|
+
│ ├── index.ts # Main DateConverter class
|
|
292
|
+
│ └── years.ts # Nepali calendar data (1975-2099 BS)
|
|
293
|
+
├── __tests__/
|
|
294
|
+
│ ├── bs.spec.ts # AD to BS conversion tests
|
|
295
|
+
│ ├── ad.spec.ts # BS to AD conversion tests
|
|
296
|
+
│ └── data.json # Test data fixtures
|
|
297
|
+
├── dist/ # Generated build output
|
|
298
|
+
│ ├── ndc.js # ESM bundle
|
|
299
|
+
│ ├── ndc-node.js # CommonJS bundle
|
|
300
|
+
│ ├── ndc-browser.js # IIFE bundle (browser-ready)
|
|
301
|
+
│ └── *.d.ts # TypeScript declarations
|
|
302
|
+
├── scripts/
|
|
303
|
+
│ └── post-build.ts # Post-build package.json generator
|
|
304
|
+
├── package.json
|
|
305
|
+
├── tsconfig.json
|
|
306
|
+
├── vite.config.ts
|
|
307
|
+
├── oxlint.config.ts
|
|
308
|
+
└── oxfmt.config.ts
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Building
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
cd html
|
|
315
|
+
bun run build
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
This generates:
|
|
319
|
+
|
|
320
|
+
- **ndc.js** - ES Module (for modern bundlers)
|
|
321
|
+
- **ndc-node.js** - CommonJS (for Node.js)
|
|
322
|
+
- **ndc-browser.js** - IIFE (for direct browser usage)
|
|
323
|
+
- **TypeScript declaration files** (.d.ts)
|
|
324
|
+
- **Packaged dist/** - Ready for npm distribution
|
|
325
|
+
|
|
326
|
+
### Testing
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
# Run all tests
|
|
330
|
+
bun run test
|
|
331
|
+
|
|
332
|
+
# Run specific test file
|
|
333
|
+
bun test __tests__/bs.spec.ts
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Tests validate conversion accuracy across the entire supported date range using comprehensive fixtures.
|
|
337
|
+
|
|
338
|
+
### Linting & Formatting
|
|
339
|
+
|
|
340
|
+
The project uses modern tooling:
|
|
341
|
+
|
|
342
|
+
- **Oxlint** - Fast Rust-based linter (ESLint replacement)
|
|
343
|
+
- **Oxfmt** - Code formatter
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
# Check for issues
|
|
347
|
+
bun run lint
|
|
348
|
+
|
|
349
|
+
# Auto-fix issues
|
|
350
|
+
bun run lint:fix
|
|
351
|
+
```
|
|
167
352
|
|
|
168
353
|
---
|
|
169
354
|
|
|
170
|
-
##
|
|
355
|
+
## 🐳 Docker Development
|
|
171
356
|
|
|
172
|
-
|
|
357
|
+
For consistent development environments, the project includes Docker support:
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
# Start development environment
|
|
361
|
+
bash start-docker.sh
|
|
362
|
+
|
|
363
|
+
# Or use the CLI wrapper
|
|
364
|
+
bash app-cli.sh
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
The Docker setup:
|
|
368
|
+
|
|
369
|
+
- Uses Bun 1.3.11 base image
|
|
370
|
+
- Configures proper UID/GID mapping
|
|
371
|
+
- Runs development server on port 3000
|
|
372
|
+
- Maintains file ownership across host/container
|
|
173
373
|
|
|
174
374
|
---
|
|
175
375
|
|
|
176
|
-
##
|
|
376
|
+
## 📊 Bundle Analysis
|
|
177
377
|
|
|
178
|
-
|
|
378
|
+
| Format | File | Size (minified) | Size (gzipped) |
|
|
379
|
+
|--------|------------------|-----------------|----------------|
|
|
380
|
+
| ESM | `ndc.js` | ~5 KiB | ~1.8 KiB |
|
|
381
|
+
| CJS | `ndc-node.js` | ~5 KiB | ~1.8 KiB |
|
|
382
|
+
| IIFE | `ndc-browser.js` | ~5 KiB | ~1.8 KiB |
|
|
179
383
|
|
|
180
384
|
---
|
|
181
385
|
|
|
182
|
-
##
|
|
386
|
+
## 🌟 Common Use Cases
|
|
387
|
+
|
|
388
|
+
The Nepali Date Converter library is widely used in various applications and systems. Here are some of the most common scenarios where developers integrate this library:
|
|
389
|
+
|
|
390
|
+
### 🏛️ Government & Public Sector
|
|
391
|
+
|
|
392
|
+
- **Government Portals**: Converting official dates for documents, certificates, and public notices
|
|
393
|
+
- **Municipal Systems**: Local government applications for citizen services
|
|
394
|
+
- **Legal Documents**: Court dates, legal filings, and official records in Nepal
|
|
395
|
+
|
|
396
|
+
### 🎉 Festival & Event Management
|
|
397
|
+
|
|
398
|
+
- **Festival Calendars**: Displaying dates for Dashain, Tihar, Holi, Teej, and other Nepali festivals
|
|
399
|
+
- **Event Planning**: Scheduling events that use both BS and AD dates
|
|
400
|
+
- **Cultural Applications**: Preserving and displaying Nepali cultural events
|
|
401
|
+
|
|
402
|
+
### 💼 Business & Enterprise
|
|
403
|
+
|
|
404
|
+
- **Accounting Systems**: Nepali fiscal year calculations and financial reporting
|
|
405
|
+
- **Payroll Systems**: Employee salary calculations using BS dates
|
|
406
|
+
- **ERP Systems**: Enterprise resource planning for Nepali companies
|
|
407
|
+
- **HR Applications**: Leave management, attendance tracking with Nepali dates
|
|
408
|
+
|
|
409
|
+
### 📱 Web & Mobile Applications
|
|
410
|
+
|
|
411
|
+
- **Calendar Apps**: Dual calendar displays showing both BS and AD dates
|
|
412
|
+
- **Date Pickers**: UI components for selecting Nepali dates
|
|
413
|
+
- **News Portals**: Displaying publication dates in both calendar systems
|
|
414
|
+
- **Social Media**: Timestamp conversions for Nepali audiences
|
|
415
|
+
|
|
416
|
+
### 🎓 Education & Research
|
|
417
|
+
|
|
418
|
+
- **Academic Calendars**: School and university schedules in Nepal
|
|
419
|
+
- **Historical Research**: Converting historical dates for research papers
|
|
420
|
+
- **Data Analysis**: Processing datasets with mixed calendar systems
|
|
421
|
+
|
|
422
|
+
### 🏥 Healthcare
|
|
423
|
+
|
|
424
|
+
- **Medical Records**: Patient records using Nepali dates
|
|
425
|
+
- **Appointment Systems**: Scheduling with BS date displays
|
|
426
|
+
- **Pharmacy Applications**: Medicine expiry date tracking
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
## 🤝 Contributing
|
|
431
|
+
|
|
432
|
+
We welcome contributions from the community! Whether you're fixing a bug, adding features, improving documentation, or reporting issues, your help makes this library better for everyone in the Nepali developer community. Below is a comprehensive guide to contributing to the Nepali Date Converter project.
|
|
433
|
+
|
|
434
|
+
### Reporting Issues
|
|
435
|
+
|
|
436
|
+
- **Bug Reports**: Open an issue with clear steps to reproduce the behavior
|
|
437
|
+
- **Feature Requests**: Describe the use case and expected behavior in detail
|
|
438
|
+
- **Documentation Issues**: Suggest improvements or report outdated information
|
|
439
|
+
|
|
440
|
+
### Code Contributions
|
|
441
|
+
|
|
442
|
+
1. Fork the repository
|
|
443
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
444
|
+
3. Make your changes
|
|
445
|
+
4. Run tests: `bun run test`
|
|
446
|
+
5. Run linter: `bun run lint:fix`
|
|
447
|
+
6. Commit your changes (follow [Conventional Commits](https://www.conventionalcommits.org/))
|
|
448
|
+
7. Push to your branch
|
|
449
|
+
8. Open a Pull Request
|
|
450
|
+
|
|
451
|
+
### Development Guidelines
|
|
452
|
+
|
|
453
|
+
- **TypeScript**: Write TypeScript with strict mode enabled for type safety
|
|
454
|
+
- **Testing**: Add comprehensive tests for all new functionality
|
|
455
|
+
- **Code Style**: Follow existing code patterns and conventions
|
|
456
|
+
- **Quality Checks**: Ensure `bun run lint` passes with no errors or warnings
|
|
457
|
+
- **Documentation**: Update documentation and examples when adding features
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
## 📄 License
|
|
462
|
+
|
|
463
|
+
This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## 🙏 Acknowledgments
|
|
468
|
+
|
|
469
|
+
- Calendar data sourced from official Nepali calendar specifications
|
|
470
|
+
- Built with modern tooling: [Bun](https://bun.sh/), [Vite](https://vitejs.dev/), and [Oxlint](https://oxc.rs/)
|
|
471
|
+
|
|
472
|
+
---
|
|
183
473
|
|
|
184
|
-
|
|
474
|
+
**Made with ❤️ for the Nepali developer community**
|
package/ndc-browser.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
var DateConverter=function(){
|
|
2
|
-
//# sourceMappingURL=ndc-browser.js.map
|
|
1
|
+
var DateConverter=(function(){function e(e,t){let n=new Date(e.getTime());return n.setUTCDate(n.getUTCDate()+t),n}function t(e,t){let n=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()),r=Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate());return Math.round((n-r)/(1440*60*1e3))}function n(e){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()))}function r(e){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),23,59,59,999))}function i(e,t){let n=e.getTime();return n>=t.start.getTime()&&n<=t.end.getTime()}var a=[];return a[1975]=[31,31,32,32,31,30,30,29,30,29,30,30,365],a[1976]=[31,32,31,32,31,30,30,30,29,29,30,31,366],a[1977]=[30,32,31,32,31,31,29,30,30,29,29,31,365],a[1978]=[31,31,32,31,31,31,30,29,30,29,30,30,365],a[1979]=a[1975],a[1980]=a[1976],a[1981]=[31,31,31,32,31,31,29,30,30,29,29,31,365],a[1982]=a[1978],a[1983]=a[1975],a[1984]=a[1976],a[1985]=[31,31,31,32,31,31,29,30,30,29,30,30,365],a[1986]=a[1978],a[1987]=[31,32,31,32,31,30,30,29,30,29,30,30,365],a[1988]=a[1976],a[1989]=[31,31,31,32,31,31,30,29,30,29,30,30,365],a[1990]=a[1978],a[1991]=[31,32,31,32,31,30,30,30,29,29,30,30,365],a[1992]=[31,32,31,32,31,30,30,30,29,30,29,31,366],a[1993]=a[1989],a[1994]=a[1978],a[1995]=a[1991],a[1996]=a[1992],a[1997]=a[1978],a[1998]=[31,31,32,31,32,30,30,29,30,29,30,30,365],a[1999]=a[1976],a[2e3]=[30,32,31,32,31,30,30,30,29,30,29,31,365],a[2001]=a[1978],a[2002]=a[1975],a[2003]=a[1976],a[2004]=a[2e3],a[2005]=a[1978],a[2006]=a[1975],a[2007]=a[1976],a[2008]=a[1981],a[2009]=a[1978],a[2010]=a[1975],a[2011]=a[1976],a[2012]=a[1985],a[2013]=a[1978],a[2014]=a[1975],a[2015]=a[1976],a[2016]=a[1985],a[2017]=a[1978],a[2018]=a[1987],a[2019]=a[1992],a[2020]=a[1989],a[2021]=a[1978],a[2022]=a[1991],a[2023]=a[1992],a[2024]=a[1989],a[2025]=a[1978],a[2026]=a[1976],a[2027]=a[2e3],a[2028]=a[1978],a[2029]=a[1998],a[2030]=a[1976],a[2031]=a[2e3],a[2032]=a[1978],a[2033]=a[1975],a[2034]=a[1976],a[2035]=a[1977],a[2036]=a[1978],a[2037]=a[1975],a[2038]=a[1976],a[2039]=a[1985],a[2040]=a[1978],a[2041]=a[1975],a[2042]=a[1976],a[2043]=a[1985],a[2044]=a[1978],a[2045]=a[1987],a[2046]=a[1976],a[2047]=a[1989],a[2048]=a[1978],a[2049]=a[1991],a[2050]=a[1992],a[2051]=a[1989],a[2052]=a[1978],a[2053]=a[1991],a[2054]=a[1992],a[2055]=a[1978],a[2056]=a[1998],a[2057]=a[1976],a[2058]=a[2e3],a[2059]=a[1978],a[2060]=a[1975],a[2061]=a[1976],a[2062]=[30,32,31,32,31,31,29,30,29,30,29,31,365],a[2063]=a[1978],a[2064]=a[1975],a[2065]=a[1976],a[2066]=a[1981],a[2067]=a[1978],a[2068]=a[1975],a[2069]=a[1976],a[2070]=a[1985],a[2071]=a[1978],a[2072]=a[1987],a[2073]=a[1976],a[2074]=a[1989],a[2075]=a[1978],a[2076]=a[1991],a[2077]=a[1992],a[2078]=a[1989],a[2079]=a[1978],a[2080]=a[1991],a[2081]=a[1992],a[2082]=a[1978],a[2083]=a[1978],a[2084]=a[1976],a[2085]=a[2e3],a[2086]=a[1978],a[2087]=a[1975],a[2088]=a[1976],a[2089]=a[2e3],a[2090]=a[1978],a[2091]=a[1975],a[2092]=a[1976],a[2093]=a[1981],a[2094]=a[1978],a[2095]=a[1975],a[2096]=a[1976],a[2097]=a[1985],a[2098]=a[1978],a[2099]=a[1975],class{epochStart=new Date(Date.UTC(1918,3,13));epochEnd=new Date(Date.UTC(2043,3,13));errorMsg=`The input date is out of supported range.`;year;month;day;constructor(e){let[t,n,r]=this.parse(e);this.year=t,this.month=n,this.day=r}parse(e){let[t,n,r]=this.toEnglishDigits(e).replace(/[./|,]/g,`-`).trim().split(`-`).map(Number);return[t,n,r]}toEnglishDigits(e){let t=[`०`,`१`,`२`,`३`,`४`,`५`,`६`,`७`,`८`,`९`];return e.replace(/[०१२३४५६७८९]/g,e=>t.indexOf(e).toString())}toDayName(e){return[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`][e]}toAdDate(t,n,r){let i=0;for(let e=1975;e<t;e++)i+=a[e][12];for(let e=0;e<n-1;e++)i+=a[t][e];return i+=r-1,e(this.epochStart,i)}toBsDate(e){let t=e;for(let e in a){if(t>=a[e][12]){t-=a[e][12];continue}for(let n=0;n<12;n++){if(t>=a[e][n]){t-=a[e][n];continue}return{year:Number(e),month:n+1,date:t+1}}}throw Error(this.errorMsg)}toAd(){if(this.year<1975||this.year>2099)throw Error(this.errorMsg);let e=this.toAdDate(this.year,this.month,this.day);return{year:e.getFullYear(),month:e.getMonth()+1,date:e.getDate(),day:this.toDayName(e.getDay())}}toBs(){let e=new Date(Date.UTC(this.year,this.month-1,this.day));if(!i(e,{start:n(this.epochStart),end:r(this.epochEnd)}))throw Error(this.errorMsg);let a=t(e,this.epochStart);return{...this.toBsDate(a),day:this.toDayName(e.getUTCDay())}}}})();
|