@nepalpatro/bsad-converter
v1.1.0
Published
BS ⇄ AD — Bikram Sambat ↔ Gregorian date converter + Nepali calendar. Zero dependencies, offline, bilingual, isomorphic.
Maintainers
Readme
bsad-converter
Bikram Sambat (BS) ↔ Gregorian (AD) date conversion and the Nepali calendar (पात्रो). Zero dependencies · offline · bilingual (English + Nepali) · works in the browser and Node · TypeScript types included.
The calendar data is the verified medic/bikram-sambat month-length table — a widely-used, verified source. Epoch: 1 Baishakh 1970 BS = 13 April 1913 AD. Range: 1970–2090 BS (≈ 1913–2034 AD).
Install
npm install @nepalpatro/bsad-converterUsage
import { adToBs, bsToAd, today, monthCalendar, toNepaliDigits } from "@nepalpatro/bsad-converter";
// English → Nepali
const bs = adToBs("2026-06-25"); // or adToBs(new Date())
bs.formattedEn; // "Ashadh 11, 2083 BS"
bs.formattedNe; // "असार ११, २०८३ बि.सं."
bs.weekdayNe; // "बिहीबार"
bs.events; // [] (or [{ en, ne }] on a national day)
// Nepali → English
bsToAd(2083, 1, 1); // "2026-04-14" (Nepali New Year)
// Today, in Nepal time (Asia/Kathmandu)
today().formattedNe; // "असार ११, २०८३ बि.सं."
// A month as a calendar grid
const m = monthCalendar(2083, 1); // Baishakh 2083
m.days; // 31
m.firstWeekday.index; // 2 (Tuesday; 0 = Sunday)
m.dayList[0]; // { day:1, dayNe:"१", ad:"2026-04-14", weekday:2, …, events:[…] }
toNepaliDigits(2083); // "२०८३"CommonJS works too:
const { adToBs } = require("@nepalpatro/bsad-converter");API
| Export | Signature | Returns |
|---|---|---|
| adToBs | (input: Date \| string) => BsDate | BS date (bilingual, weekday, events) |
| bsToAd | (year, month, day) => string | Gregorian "YYYY-MM-DD" |
| bsToAdDate | (year, month, day) => Date | Gregorian Date (UTC midnight) |
| today | () => BsDate | today in Nepal (Asia/Kathmandu) |
| monthCalendar | (year, month) => CalMonth | one BS month grid |
| yearCalendar | (year) => CalMonth[] | all 12 BS months |
| toNepaliDigits | (value: string \| number) => string | Devanagari numerals |
| consts | MIN_BS_YEAR, MAX_BS_YEAR, AD_MIN, AD_MAX, BS_MONTHS | range + raw table |
BsDate = { year, month, day, monthEn, monthNe, iso, formattedEn, formattedNe, weekdayEn, weekdayNe, events }.
CalDay = { day, dayNe, ad, weekday /* 0=Sun..6=Sat */, weekdayEn, weekdayNe, events }.
CalEvent = { en, ne }.
Out-of-range or invalid input throws DateConversionError:
import { adToBs, DateConversionError } from "@nepalpatro/bsad-converter";
try { adToBs("2099-01-01"); } catch (e) { /* e instanceof DateConversionError */ }Events
events covers fixed national days only (New Year, Republic / Constitution / Democracy / Martyrs' Day, Prithvi Jayanti, Maghe Sankranti, + fixed AD days: Labour Day, Women's Day, Christmas). Movable lunar festivals (Dashain, Tihar, Holi, Buddha Jayanti …) are intentionally not included — they shift yearly and require the official Nepal Panchanga.
Date picker
Build a Nepali (BS) date selector on top of monthCalendar(). See examples/date-picker.html for a complete, runnable widget — BS calendar grid, today + Saturday holidays highlighted, an AD input that jumps to the month, and the selected date shown in both BS and AD.
import { monthCalendar, toNepaliDigits } from "@nepalpatro/bsad-converter";
const cal = monthCalendar(2083, 3); // असार 2083
cal.firstWeekday.index; // leading blank cells before day 1 (0 = Sunday)
cal.dayList.forEach(d => {
// d.dayNe = "१२", d.ad = "2026-06-26", d.weekday (6 = Saturday), d.events
// → render one cell per day; on click, surface d.ad + the BS date
});Notes
- Timezone:
today()uses Asia/Kathmandu (UTC+5:45, no DST). - Sovereign: pure local computation; contacts no network and needs no API key.
- A live HTTP API and a citizen calendar page exist at https://nepal.gov.np/calendar.
License
MIT licensed
