A JavaScript/TypeScript library for Nepali date conversion and calendar utilities.
- 🔄 Convert dates between Bikram Sambat (BS) and Gregorian calendar (AD)
- 📆 Get current date in Nepali calendar
- 🎨 Format Nepali dates with various format options
- 🈂️ Support for both English and Nepali (Devanagari) language output
- 📊 Get days in a month for any year in the BS calendar
- 📝 TypeScript support with full type definitions
npm install nepalipatrojsOr with yarn:
yarn add nepalipatrojs// ES6 import
import NepaliPatro from 'nepalipatrojs';
// CommonJS require
const NepaliPatro = require('nepalipatrojs').default;The library provides a ready-to-use Nepali datepicker UI for web apps.
- Include the CSS and JS in your HTML:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nepalipatrojs/dist/nepali-patro-js.css" />
<script src="https://cdn.jsdelivr.net/npm/nepalipatrojs/dist/nepali-patro-js.umd.js"></script>- Add an input element:
<input id="dateInput" placeholder="Select Nepali Date" />- Initialize the datepicker:
// For UMD build, NepaliDatePicker is available globally
const input = document.getElementById('dateInput');
const dp = new NepaliDatePicker(input, {
format: 'YYYY/MM/DD', // or 'MMMM D, YYYY', etc.
theme: 'dark', // 'light' (default) or 'dark'
language: 'en', // 'en' (default) or 'np'
});import { NepaliDatePicker } from 'nepalipatrojs';
const input = document.getElementById('dateInput');
const dp = new NepaliDatePicker(input, {
format: 'YYYY/MM/DD',
theme: 'dark',
language: 'np',
});| Option | Type | Default | Description |
|---|---|---|---|
| format | string | 'MMMM D, YYYY' | Date format string |
| theme | 'light' | 'dark' | 'light' | Calendar theme |
| language | 'en' | 'np' | 'en' | Language for month/digits |
The datepicker supports both light and dark themes. You can customize the CSS for .nepali-datepicker-light and .nepali-datepicker-dark classes.
// Using Date object
const adDate = new Date(2022, 0, 1); // January 1, 2022
const bsDate = NepaliPatro.convertADToBS(adDate);
console.log(bsDate);
// Output: { year: 2078, month: 9, day: 17 }
// Using array [year, month, day]
const bsDate2 = NepaliPatro.convertADToBS([2022, 1, 1]); // January 1, 2022
console.log(bsDate2);
// Output: { year: 2078, month: 9, day: 17 }// Using object
const bsDate = { year: 2078, month: 9, day: 17 };
const adDate = NepaliPatro.convertBSToAD(bsDate);
console.log(adDate);
// Output: Date object representing January 1, 2022
// Using array [year, month, day]
const adDate2 = NepaliPatro.convertBSToAD([2078, 9, 17]);
console.log(adDate2);
// Output: Date object representing January 1, 2022const today = NepaliPatro.getCurrentBSDate();
//or use
const today = NepaliPatro.now()
console.log(today);
// Output: { year: 2081, month: 1, day: 28 } (if today is May 10, 2025)const bsDate = { year: 2078, month: 1, day: 15 };
// Default format (YYYY-MM-DD)
const formatted = NepaliPatro.formatBS(bsDate);
console.log(formatted); // Output: 2078-01-15
// Custom format
const customFormatted = NepaliPatro.formatBS(bsDate, 'DD/MM/YYYY');
console.log(customFormatted); // Output: 15/01/2078
// With month name
const withMonthName = NepaliPatro.formatBS(bsDate, 'MMMM D, YYYY');
console.log(withMonthName); // Output: Baisakh 15, 2078
// In Nepali language
const inNepali = NepaliPatro.formatBS(bsDate, 'MMMM D, YYYY', { language: 'ne' });
console.log(inNepali); // Output: बैशाख 15, 2078// Get total days in Jestha 2078 BS
const daysInMonth = NepaliPatro.getDaysInMonth(2078, 2);
console.log(daysInMonth); // Output: 32// Convert numbers to Nepali digits
const nepaliNumber = NepaliPatro.toNepaliDigits(2078);
console.log(nepaliNumber); // Output: २०७८Converts a Gregorian date (AD) to Bikram Sambat date (BS).
Converts a Bikram Sambat date (BS) to Gregorian date (AD).
Returns the current date in BS calendar.
Formats a BS date according to the given format string.
Returns the number of days in a given month and year in BS calendar.
Converts English digits to Nepali digits.
interface NepaliDate {
year: number;
month: number;
day: number;
}
interface NepaliPatroOptions {
language?: 'en' | 'ne';
format?: string;
returnType?: 'string' | 'object';
}| Token | Description | Example |
|---|---|---|
| YYYY | 4-digit year | 2078 |
| YY | 2-digit year | 78 |
| MM | 2-digit month | 01 |
| M | 1-digit month | 1 |
| MMMM | Month name | Baisakh |
| DD | 2-digit day | 02 |
| D | 1-digit day | 2 |
This library works in all modern browsers, Node.js, and with bundlers like Rollup, Webpack, Vite, etc.
Contributions are welcome! Feel free to open issues or submit pull requests.