Framework-agnostic TypeScript library for Bikram Sambat operations, location data, validation, and currency formatting.
@nepali-utils/core is a zero-dependency TypeScript library providing utilities for the Bikram Sambat (Nepali) calendar system. It covers dates from BS 2000 to BS 2100 (AD 1943–2043) with high accuracy.
The library is organized into several modules:
The library is framework-agnostic and works with any JavaScript/TypeScript project.
1npm install @nepali-utils/core1pnpm add @nepali-utils/core1yarn add @nepali-utils/coreConvert between Bikram Sambat and Gregorian (AD) dates. All conversion functions are accurate for BS 2000–2100 (AD 1943–2043).
1234import { bsToAd } from "@nepali-utils/core" const date = bsToAd({ year: 2081, month: 5, day: 15 })// → Date (JavaScript Date object)1234import { adToBs } from "@nepali-utils/core" const bsDate = adToBs(new Date())// → { year: 2081, month: 5, day: 15 }1234import { getTodayBs } from "@nepali-utils/core" const today = getTodayBs()// → { year: 2081, month: 5, day: 15 }1234import { getBsDayOfWeek } from "@nepali-utils/core" const dayOfWeek = getBsDayOfWeek({ year: 2081, month: 5, day: 15 })// → 0 (Sunday) through 6 (Saturday)Format BS dates with custom patterns in English or Nepali. Pattern tokens include YYYY, YY, MMMM, MMM, MM, and DD.
12345678910111213import { formatBsDate } from "@nepali-utils/core" formatBsDate(date, "en", { pattern: "YYYY MMMM DD" })// → "2081 Bhadra 15" formatBsDate(date, "ne", { pattern: "YYYY MMMM DD" })// → "२०८१ भदौ १५" formatBsDate(date, "en", { pattern: "YYYY-MM-DD" })// → "2081-05-15" formatBsDate(date, "en", { pattern: "MMMM DD, YYYY" })// → "Bhadra 15, 2081"123456import { toNepaliNumber, parseNepaliNumber } from "@nepali-utils/core" toNepaliNumber(2081) // → "२०८१"toNepaliNumber(12345) // → "१२३४५" parseNepaliNumber("२०८१") // → 20811234567import { getPrevMonth, getNextMonth, MONTHS } from "@nepali-utils/core" getPrevMonth(2081, 5) // → { year: 2081, month: 4 }getNextMonth(2081, 5) // → { year: 2081, month: 6 } MONTHS.en // → ["Baisakh", "Jestha", "Ashad", ...]MONTHS.ne // → ["बैशाख", "जेष्ठ", "असार", ...]Generate calendar grids and query month/year data for building custom calendar UIs.
12345import { generateCalendarGrid, type CalendarDay } from "@nepali-utils/core" const grid: CalendarDay[] = generateCalendarGrid(2081, 5)// Returns an array of CalendarDay objects with day, month, year,// isCurrentMonth, isToday, dayOfWeek, and date properties.12345678910import { getDaysInBsMonth, getDaysInBsYear, isValidBsYear, getBsYearRange, validateBsDate } from "@nepali-utils/core" getDaysInBsMonth(2081, 5) // → number of days in Bhadra 2081 (e.g. 32)getDaysInBsYear(2081) // → total days in BS year 2081 (e.g. 365)isValidBsYear(2081) // → truegetBsYearRange() // → { min: 2000, max: 2100 } // Validate a BS date — throws if invalidvalidateBsDate(2081, 5, 15) // → undefined (valid)validateBsDate(2081, 13, 1) // → throws "Invalid BS month: 13"Compare BS dates with equality and ordering checks.
12345678import { isSameBsDate, isBeforeBsDate, isAfterBsDate } from "@nepali-utils/core" const d1 = { year: 2081, month: 5, day: 15 }const d2 = { year: 2081, month: 6, day: 1 } isSameBsDate(d1, d1) // → trueisBeforeBsDate(d1, d2) // → trueisAfterBsDate(d2, d1) // → trueComplete dataset for Nepal's administrative divisions including all 7 provinces, 77 districts, municipalities, and wards. All data includes English and Nepali names.
All 7 provinces with Nepali and English names, identified by UUID:
123456789import { provinces, getProvinceById, getProvinceByNameEn } from "@nepali-utils/core" provinces // → ProvinceInfo[] (all 7 provinces) getProvinceById("1a2d297a-b4d4-4062-9801-62813c324753")// → { id: "...", name: "कोशी प्रदेश", nameEn: "Koshi Province" } getProvinceByNameEn("Bagmati Province")// → { id: "...", name: "बागमती प्रदेश", nameEn: "Bagmati Province" }All 77 districts, each linked to a province via provinceId:
123456789import { districts, getDistrictById, getDistrictsByProvince } from "@nepali-utils/core" districts // → DistrictInfo[] (all 77 districts) getDistrictById("6accfa6f-c4ab-4b95-b0bf-aaf740375f62")// → { id: "...", provinceId: "...", name: "ताप्लेजुङ", nameEn: "Taplejung", ... } getDistrictsByProvince("1a2d297a-b4d4-4062-9801-62813c324753")// → DistrictInfo[] (districts in Koshi province)12345678910import { municipalities, getMunicipalityById, getMunicipalitiesByDistrict } from "@nepali-utils/core" getMunicipalityById(1)// → { id: 1, districtId: 1, nameEn: "...", nameNe: "...", type: "...", ... } getMunicipalitiesByDistrict(1)// → MunicipalityInfo[] getMunicipalitiesByProvince(1)// → MunicipalityInfo[] (all municipalities in Koshi)12345678910import { wards, getWardsByMunicipality, getWardsByDistrict, getWardsByProvince } from "@nepali-utils/core" getWardsByMunicipality(1)// → WardInfo[] getWardsByDistrict(1)// → WardInfo[] getWardsByProvince(1)// → WardInfo[]Validate Nepali mobile phone numbers with carrier detection and formatting.
1234567891011import { isValidNepaliMobile, getPhoneType, formatNepaliPhone } from "@nepali-utils/core" isValidNepaliMobile("9841234567") // → trueisValidNepaliMobile("12345") // → false getPhoneType("9841234567") // → "NTC" (Nepal Telecom)getPhoneType("9861234567") // → "NTC"getPhoneType("9851234567") // → "Ncell" formatNepaliPhone("9841234567")// → "984-1234567"Format amounts in Nepali currency (रु) and convert numbers to Nepali words.
formatNepaliCurrency accepts options for language, symbol, and decimal control:
123456789101112131415161718192021import { formatNepaliCurrency } from "@nepali-utils/core" // Default — Nepali numerals with रु symbolformatNepaliCurrency(12345.67)// → "रु १२,३४५.६७" // English outputformatNepaliCurrency(12345.67, { lang: "en" })// → "Rs. 12,345.67" // Hide symbolformatNepaliCurrency(1000, { symbol: false })// → "१,०००.००" // Whole number only (no decimals)formatNepaliCurrency(1000, { decimal: false })// → "रु १,०००" // Negative amountsformatNepaliCurrency(-500)// → "रु -५००.००"Converts numbers to Nepali words using the traditional place value system (सय, हजार, लाख, करोड):
12345678910import { toNepaliWords } from "@nepali-utils/core" toNepaliWords(0) // → "शून्य"toNepaliWords(5) // → "पाँच"toNepaliWords(100) // → "एक सय"toNepaliWords(1000) // → "एक हजार"toNepaliWords(12345) // → "बाह्र हजार तीन सय पैंतालीस"toNepaliWords(100000) // → "एक लाख"toNepaliWords(10000000) // → "एक करोड"toNepaliWords(-50) // → "ऋण पचास"All 12 Bikram Sambat months with English and Nepali names:
1234567891011121314151617import { MONTHS } from "@nepali-utils/core" MONTHS// → [// { value: 1, nameEn: "Baisakh", nameNe: "बैशाख" },// { value: 2, nameEn: "Jestha", nameNe: "जेष्ठ" },// { value: 3, nameEn: "Ashadh", nameNe: "आषाढ" },// { value: 4, nameEn: "Shrawan", nameNe: "श्रावण" },// { value: 5, nameEn: "Bhadra", nameNe: "भाद्र" },// { value: 6, nameEn: "Ashwin", nameNe: "आश्विन" },// { value: 7, nameEn: "Kartik", nameNe: "कार्तिक" },// { value: 8, nameEn: "Mangsir", nameNe: "मंसिर" },// { value: 9, nameEn: "Poush", nameNe: "पौष" },// { value: 10, nameEn: "Magh", nameNe: "माघ" },// { value: 11, nameEn: "Falgun", nameNe: "फाल्गुन" },// { value: 12, nameEn: "Chaitra", nameNe: "चैत्र" },// ]7 weekdays with short/long names in both languages:
1234567import { WEEKDAYS } from "@nepali-utils/core" WEEKDAYS[0]// → { value: 0, shortEn: "Sun", shortNe: "आइत", longEn: "Sunday", longNe: "आइतबार" } WEEKDAYS[6]// → { value: 6, shortEn: "Sat", shortNe: "शनि", longEn: "Saturday", longNe: "शनिबार" }| Function | Signature | Description |
|---|---|---|
| bsToAd(year, month, day) | (y: number, m: number, d: number) => Date | BS → AD. Throws if date is invalid or outside BS 2000–2100. |
| adToBs(date) | (date: Date) => DateBS | AD → BS. Throws if date is before BS 2000-01-01 (AD 1943-04-14). |
| getTodayBs() | () => DateBS | Current date in BS. Always succeeds. |
| getBsDayOfWeek(year, month, day) | (y: number, m: number, d: number) => number | Day of week: 0 (Sunday) through 6 (Saturday). Throws on invalid date. |
| Function | Signature | Description |
|---|---|---|
| formatBsDate(date, lang?, opts?) | (d: DateBS, lang?: BsLang, opts?: BsFormatOptions) => string | Format with pattern (YYYY-MM-DD, DD MMMM YYYY, etc.). Default pattern: YYYY-MM-DD. |
| toNepaliNumber(num) | (num: number) => string | Arabic → Nepali digits (e.g. 2081 → २०८१). Handles negative numbers. |
| parseNepaliNumber(str) | (str: string) => number | Nepali → Arabic digits (e.g. २०८१ → 2081). Non-digits pass through. |
| getPrevMonth(year, month) | (y: number, m: number) => { year, month } | Previous month. Wraps from Baisakh (1) to Chaitra (12) of previous year. |
| getNextMonth(year, month) | (y: number, m: number) => { year, month } | Next month. Wraps from Chaitra (12) to Baisakh (1) of next year. |
| Function | Signature | Description |
|---|---|---|
| generateCalendarGrid(year, month, ...) | (y: number, m: number, sel?: DateBS, today?: DateBS, disabledFn?: fn) => CalendarDay[][] | Generates 6×7 grid (weeks × days) with padding, today/selected/disabled state. |
| getDaysInBsMonth(year, month) | (y: number, m: number) => number | Days in a BS month (29–32). Throws if month is outside 1–12 or year unsupported. |
| getDaysInBsYear(year) | (y: number) => number | Total days in a BS year (354–366). Throws if year outside BS 2000–2100. |
| isValidBsYear(year) | (y: number) => boolean | True if year is in BS 2000–2100. Never throws. |
| getBsYearRange() | () => { min: number; max: number } | Returns { min: 2000, max: 2100 }. |
| validateBsDate(year, month, day) | (y: number, m: number, d: number) => void | Throws descriptive Error if month is outside 1–12 or day is outside valid range. |
| Function | Signature | Description |
|---|---|---|
| isSameBsDate(a, b) | (a: DateBS, b: DateBS) => boolean | True if year, month, and day are all equal. |
| isBeforeBsDate(a, b) | (a: DateBS, b: DateBS) => boolean | True if a is chronologically before b (compares year → month → day). |
| isAfterBsDate(a, b) | (a: DateBS, b: DateBS) => boolean | True if a is chronologically after b. |
| Export | Type | Description |
|---|---|---|
| provinces | ProvinceInfo[] | All 7 provinces (Koshi, Madhesh, Bagmati, Gandaki, Lumbini, Karnali, Sudurpashchim) |
| getProvinceById(id) | ProvinceInfo | undefined | Lookup by UUID. Returns undefined if not found. |
| getProvinceByNameEn(name) | ProvinceInfo | undefined | Lookup by English name (e.g. 'Bagmati Province'). Case-sensitive. |
| districts | DistrictInfo[] | All 77 districts |
| getDistrictById(id) | DistrictInfo | undefined | Lookup by UUID. |
| getDistrictsByProvince(provinceId) | DistrictInfo[] | Districts in a province. Empty array if no match. |
| municipalities | MunicipalityInfo[] | All municipalities (nagarpalika and gaupalika) |
| getMunicipalityById(id) | MunicipalityInfo | undefined | Lookup by UUID. |
| getMunicipalitiesByDistrict(districtId) | MunicipalityInfo[] | Municipalities in a district. |
| getMunicipalitiesByProvince(provinceId) | MunicipalityInfo[] | Municipalities in a province. |
| wards | WardInfo[] | All wards across all municipalities |
| getWardsByMunicipality(id) | WardInfo[] | Wards in a municipality. |
| getWardsByDistrict(id) | WardInfo[] | Wards in a district. |
| getWardsByProvince(id) | WardInfo[] | Wards in a province. |
| Function | Signature | Description |
|---|---|---|
| isValidNepaliMobile(phone) | (phone: string) => boolean | Validates 10-digit Nepali mobile. Strips +977/977 prefix, spaces, dashes. Checks prefix against 16 known operator codes. |
| getPhoneType(phone) | (phone: string) => 'mobile' | 'landline' | 'unknown' | Detects mobile (9X, 10 digits), landline (area code match), or unknown. |
| formatNepaliPhone(phone) | (phone: string) => string | Formats mobile as XXX-XXX-XXXX or returns national number for landline. |
| Function | Signature | Description |
|---|---|---|
| formatNepaliCurrency(amount, opts?) | (amount: number, opts?: NepaliCurrencyOptions) => string | Format with रु/Rs. symbol, Indian number grouping, Devanagari or English digits, optional decimals. |
| toNepaliWords(num) | (num: number) => string | Number to Nepali words (सय, हजार, लाख, करोड). Handles 0 and negatives. |
| Option | Type | Default | Description |
|---|---|---|---|
| lang | "en" | "ne" | "ne" | Output language for numerals |
| symbol | boolean | true | Show रु / Rs. prefix |
| decimal | boolean | true | Show .XX decimal places |
Still have questions?
Check the source on GitHub or open an issue.