Packages/@nepali-utils/core

@nepali-utils/core

Framework-agnostic TypeScript library for Bikram Sambat (Nepali) date operations, number conversion, calendar utilities, location data, validation, and currency formatting.

v0.1.0MITTypeScriptZero deps
bash
1
npm install @nepali-utils/core

Date Conversion

Convert between Bikram Sambat and Gregorian (AD) dates with high accuracy for dates from BS 2000 to BS 2100 (AD 1943–2043).

1
2
3
4
5
6
7
8
9
10
import { bsToAd, adToBs, getTodayBs } from "@nepali-utils/core"
const today = getTodayBs()
// → { year: 2081, month: 5, day: 15 }
const adDate = bsToAd(today)
// → Date (JavaScript Date object)
const backToBs = adToBs(adDate)
// → { year: 2081, month: 5, day: 15 }

Date Comparison

Compare BS dates with equality and ordering checks.

1
2
3
4
5
import { isSameBsDate, isBeforeBsDate, isAfterBsDate } from "@nepali-utils/core"
isSameBsDate(date1, date2) // → boolean
isBeforeBsDate(date1, date2) // → boolean
isAfterBsDate(date1, date2) // → boolean

Formatting

Format BS dates with custom patterns in English or Nepali (Devanagari).

1
2
3
4
5
6
7
8
9
10
import { formatBsDate, toNepaliNumber, parseNepaliNumber } from "@nepali-utils/core"
formatBsDate(date, "en", { pattern: "YYYY MMMM DD" })
// → "2081 Bhadra 15"
formatBsDate(date, "ne", { pattern: "YYYY MMMM DD" })
// → "२०८१ भदौ १५"
toNepaliNumber(2081) // → "२०८१"
parseNepaliNumber("२०८१") // → 2081

Calendar Data

Get calendar grid data, month details, and year ranges for building custom calendar UIs.

1
2
3
4
5
6
7
import { generateCalendarGrid, getDaysInBsMonth, MONTHS } from "@nepali-utils/core"
const grid = generateCalendarGrid(2081, 5)
// Returns array of CalendarDay objects for rendering
getDaysInBsMonth(2081, 5) // → number of days in Bhadra 2081
MONTHS.ne // → ["बैशाख", "जेष्ठ", ...]

Location Data

Complete dataset for Nepal's provinces, districts, municipalities, and wards with utility functions for lookups.

1
2
3
4
5
6
7
8
9
import {
provinces, getProvinceById,
districts, getDistrictsByProvince,
municipalities, getMunicipalitiesByDistrict,
} from "@nepali-utils/core"
provinces // → all 7 provinces
getProvinceById(1) // → ProvinceInfo
getDistrictsByProvince(1) // → districts in province 1

Validation

Validate Nepali phone numbers with carrier detection.

1
2
3
4
5
6
7
import { isValidNepaliMobile, getPhoneType } from "@nepali-utils/core"
isValidNepaliMobile("9841234567") // → true
getPhoneType("9841234567") // → "NTC"
formatNepaliPhone("9841234567")
// → "984-1234567"

Currency

Format amounts in Nepali currency and convert numbers to Nepali words.

1
2
3
4
5
6
7
import { formatNepaliCurrency, toNepaliWords } from "@nepali-utils/core"
formatNepaliCurrency(12345.67)
// → "रु १२,३४५.६७"
toNepaliWords(12345)
// → "बाह्र हजार तीन सय पैंतालीस"