API Documentation

Complete API reference for every class, method, and utility.

NepaliDate

The core date manipulation object — immutable, chainable, inspired by Moment.js. All arithmetic methods return a new instance.

Construction

new NepaliDate(bsYear, bsMonth, bsDay)
Create a NepaliDate from BS year, month (1-indexed), and day. The instance is frozen (immutable).
NepaliDate.fromAD(jsDate)
Create a NepaliDate from a native JavaScript Date object.
Returns NepaliDate
NepaliDate.parse(str, formatStr = 'YYYY-MM-DD', locale = 'en')
Parse a formatted BS date string. Supports both English and Nepali numerals.
Returns NepaliDate
NepaliDate.today()
Returns today's date in Bikram Sambat.
Returns NepaliDate
NepaliDate.fromTimestamp(ms)
Create a NepaliDate from a Unix timestamp in milliseconds.
Returns NepaliDate

Getters

PropertyTypeDescription
.yearnumberBS year
.monthnumberBS month (1-indexed, 1 = Baisakh)
.daynumberBS day of month
.weekDaynumberDay of week (0 = Sunday, 6 = Saturday)
.quarternumberQuarter (1–4)
.dayOfYearnumberDay number within the BS year
.weekOfYearnumberWeek number within the BS year
.daysInMonthnumberTotal days in the current month
.daysInYearnumberTotal days in the current year
.isLeapYearbooleanTrue if the BS year has 366 days

Conversion

.toAD()
Convert to a native JavaScript Date object in Gregorian calendar.
Returns Date
.toObject()
Returns a plain object with year, month, day, and weekDay properties.
Returns { year, month, day, weekDay }
.toTimestamp()
Returns the equivalent Unix timestamp in milliseconds.
Returns number
.format(formatStr = 'YYYY-MM-DD', locale = 'en')
Format the date as a string. Tokens: YYYY, MM, DD, MMMM, MMM, dddd, ddd.
Returns string

Arithmetic

.add(value, unit) / .subtract(value, unit)
Add or subtract time. Units: 'day', 'week', 'month', 'year'. Returns a new instance.
Returns NepaliDate
.startOf(unit) / .endOf(unit)
Get the first or last moment of the given unit. Units: 'month', 'year', 'week'.
Returns NepaliDate
.addDays(n) / .addMonths(n) / .addYears(n)
Shorthand helpers for .add(n, unit).
Returns NepaliDate
.subtractDays(n) / .subtractMonths(n) / .subtractYears(n)
Shorthand helpers for .subtract(n, unit).
Returns NepaliDate

Comparison

.isBefore(other) / .isAfter(other)
Compare two NepaliDate instances chronologically.
Returns boolean
.isSame(other, granularity = 'day')
Check equality at a given granularity: 'day', 'month', or 'year'.
Returns boolean
.isBetween(start, end, inclusive = '[]')
Check if the date falls within a range. Inclusive modes: '[]', '()', '[)', '(]'.
Returns boolean
.isToday() / .isWeekend() / .isValid()
Convenience boolean checks. isWeekend() returns true for Saturday (weekDay === 6).
Returns boolean
.diff(other, unit = 'day')
Calculate the signed difference between two dates. Units: 'day', 'week', 'month', 'year'.
Returns number

Cloning & Mutation

.clone()
Create an identical copy of this NepaliDate.
Returns NepaliDate
.set(field, value)
Return a new NepaliDate with the given field changed. Fields: 'year', 'month', 'day'. Day is clamped to valid range.
Returns NepaliDate

CalendarEngine

A headless calendar state machine. Holds view state, selection, and disabled-date logic. Zero DOM or framework knowledge — adapters consume its state snapshots.

Constructor Options

OptionTypeDescription
valueNepaliDateCurrently selected date
defaultDateNepaliDateDate to show on first render
minDateNepaliDateEarliest selectable date
maxDateNepaliDateLatest selectable date
locale'en' | 'np'Display locale (default: 'en')
weekStartsOnnumberFirst day of week (0 = Sun, default: 0)
disabledDaysstring[]Weekday names to disable, e.g. ['Sat']
disabledDatesNepaliDate[]Specific dates to disable
onChangeFunctionCalled with NepaliDate on selection
onMonthChangeFunctionCalled with { year, month } on navigation

getState()

Returns a complete, serializable snapshot of the current UI state.

PropertyTypeDescription
viewYearnumberCurrently displayed BS year
viewMonthnumberCurrently displayed BS month (1-indexed)
viewMode'day' | 'month' | 'year'Current view mode
weeksDayCell[][]6 rows × 7 cols of day cells
monthsMonthCell[]12 month items for month picker
yearsYearCell[]~12 items in current decade window
selectedDateNepaliDate | nullCurrently selected date
todayDateNepaliDateToday's BS date
locale'en' | 'np'Current locale
canGoBackbooleanCan navigate to previous month
canGoForwardbooleanCan navigate to next month

DayCell Shape

PropertyType
dateNepaliDate
labelstring — formatted day number
isTodayboolean
isSelectedboolean
isDisabledboolean
isOutsideMonthboolean
weekDaynumber

Navigation Methods

.goToPrevMonth() / .goToNextMonth()
Navigate to the previous or next month. Respects min/max bounds.
.goToPrevYear() / .goToNextYear()
Navigate to the previous or next year.
.goToMonth(year, month)
Navigate directly to a specific year and month.
.goToToday()
Navigate to today's month.
.setViewMode(mode)
Switch between 'day', 'month', and 'year' views.

Selection Methods

.selectDate(nepaliDate)
Select a date. Fires onChange callback. Skips disabled dates.
.clearSelection()
Clear the currently selected date.
.setValue(nepaliDate)
Set the value programmatically. Does not fire onChange.

Subscriptions

.subscribe(listener)
Subscribe to state changes. The listener is called immediately with the current state, then on every subsequent change.
Returns Function — unsubscribe callback
.destroy()
Remove all subscriptions and clean up.

RangePicker

Extends CalendarEngine. Adds two-phase range selection with hover preview.

Additional Options

OptionTypeDescription
startDateNepaliDateInitial range start
endDateNepaliDateInitial range end
minRangenumberMin days between start and end
maxRangenumberMax days between start and end
onRangeChangeFunctionCalled with { start, end }

Additional State Properties

PropertyType
startDateNepaliDate | null
endDateNepaliDate | null
hoverDateNepaliDate | null
selectionPhase'idle' | 'start-selected' | 'complete'

Each DayCell also includes: isRangeStart, isRangeEnd, isInRange, isRangeHover.

Methods

.selectDate(nepaliDate)
First click = range start, second click = range end. Validates min/max range constraints.
.hoverDate(nepaliDate)
Update the hover date for range preview (only active during 'start-selected' phase).
.setRange(start, end)
Set the range programmatically. Fires onRangeChange if both dates are set.
.clearRange()
Clear both start and end dates, reset to 'idle' phase.
.swapIfInverted()
Ensures start < end. Called automatically after range selection.

Vanilla JS Adapter

Renders the picker into a DOM container and wires events to the engine.

createPicker(container, options = {})
Mount a date picker into an HTMLElement. If the container is an <input>, the picker wraps it automatically.

Additional Options

OptionTypeDescription
rangebooleanUse RangePicker instead of CalendarEngine
inputSelectorstringCSS selector for an input to sync value to
formatstringDate format string (default: 'YYYY-MM-DD')
syncInputbooleanAuto-update the input value on selection
openOnInitbooleanShow the panel immediately (default: false)

Return Value

PropertyTypeDescription
engineCalendarEngine | RangePickerDirect engine reference
destroy()FunctionUnmount and clean up all listeners
open()FunctionShow the picker panel
close()FunctionHide the picker panel
getValue()FunctionGet selected date or range { start, end }
setValue()FunctionSet value programmatically

React Adapter

Import from nepali-datepicker/react.

useNepaliDatePicker(options = {})
Headless hook — wraps the CalendarEngine and returns reactive state + bound action handlers.

Return Value

PropertyDescription
stateReactive getState() snapshot
engineDirect engine reference
goToPrevMonthBound action
goToNextMonthBound action
goToPrevYearBound action
goToNextYearBound action
goToTodayBound action
setViewModeBound action
selectDateBound action
clearSelectionBound action
hoverDateBound action (range mode)
setRangeBound action (range mode)
clearRangeBound action (range mode)
<NepaliDatePicker options={...} children={renderFn} />
Render-prop component. Passes the same object as useNepaliDatePicker to the children render function.

Vue 3 Adapter

Import from nepali-datepicker/vue.

useNepaliDatePicker(options = {})
Vue 3 composable. Wraps CalendarEngine with reactive ref state. Returns the same interface as the React adapter.
Returns { state: Ref, engine, ...actions }

Svelte Adapter

Import from nepali-datepicker/svelte.

createNepaliPickerStore(options = {})
Returns a Svelte-compatible readable store. Use $store syntax to access state reactively.
Returns { subscribe, engine, ...actions }

Locale & Formatting

Two built-in locales: English ('en') and Nepali Devanagari ('np').

formatDate(nepaliDate, formatStr, locale = 'en')
Format a NepaliDate to a string. Tokens: YYYY, MM, DD, MMMM (full month), MMM (short month), dddd (full weekday), ddd (short weekday).
Returns string
parseDate(str, formatStr, locale = 'en')
Parse a formatted BS date string back into a NepaliDate. Supports both English and Nepali numerals.
Returns NepaliDate
LOCALES
Object containing en and np locale data: months, days, daysLong, today, clear, numberFormat(n).

Nepali Month Names

#EnglishNepali
1Baisakhबैशाख
2Jesthaजेठ
3Ashadhअसार
4Shrawanश्रावण
5Bhadraभाद्र
6Ashwinआश्विन
7Kartikकार्तिक
8Mangsirमंसिर
9Poushपुष
10Maghमाघ
11Falgunफाल्गुण
12Chaitraचैत्र

Converter

Bidirectional conversion between Bikram Sambat and Gregorian dates. Epoch anchor: 1 Baisakh 2000 BS = April 14, 1943 AD.

adToBS(adYear, adMonth, adDay)
Convert a Gregorian date to Bikram Sambat. Month is 1-indexed.
Returns { year, month, day }
bsToAD(bsYear, bsMonth, bsDay)
Convert a Bikram Sambat date to Gregorian. Month is 1-indexed.
Returns { year, month, day }
BS_CALENDAR_DATA
The raw lookup table: { [bsYear]: number[12] }. Each array contains the number of days in each month for that year. Range: 2000–2100 BS.

Styling

The optional Material stylesheet uses CSS custom properties for full theming control. Import: import 'nepali-datepicker/dist/material.css'

CSS Custom Properties

VariableDefaultDescription
--ndp-primary#1976D2Primary accent color
--ndp-primary-dark#115293Darker primary
--ndp-primary-light#E3F2FDLight primary (range bg)
--ndp-surface#FFFFFFPanel background
--ndp-on-surface#212121Text on surface
--ndp-on-surface-muted#757575Muted text
--ndp-radius-md8pxPanel border radius
--ndp-cell-size36pxDay cell size
--ndp-width280pxPanel width
--ndp-font'Roboto'Font family
--ndp-font-np'Noto Sans Devanagari'Nepali font
--ndp-transition150ms easeTransition timing

Component Classes

ClassDescription
.ndp-containerOuter wrapper
.ndp-panelFloating calendar panel
.ndp-headerMonth/year navigation row
.ndp-grid7-column CSS grid for day cells
.ndp-cellIndividual day cell
.ndp-cell--todayToday's date indicator
.ndp-cell--selectedSelected date (filled)
.ndp-cell--disabledDisabled cell
.ndp-cell--range-startRange start
.ndp-cell--range-endRange end
.ndp-cell--in-rangeDays within the selected range
.ndp-footerBottom action bar
.ndp-inputInput trigger styling