npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bs-date

v1.1.0

Published

Converts between Anno Domini (AD/Gregorian) and Bikram Sambat (BS/Nepali) dates.

Readme

BS Date

A JavaScript library for converting between Anno Domini (AD/Gregorian) and Bikram Sambat (BS/Nepali) dates.

Installation

npm install bs-date

Features

  • Convert Bikram Sambat dates to Anno Domini dates
  • Convert Anno Domini dates to Bikram Sambat dates
  • Supports BS years 2000-2090 (AD 1943-2034)
  • Validates date ranges and throws appropriate errors
  • Extends native Date prototype with toBS() method
  • Format dates in Nepali script with toNepali()
  • Get month names in Nepali or romanized format
  • Get day names in Nepali, romanized, or localized English format
  • Convert numbers to Nepali numerals

Usage

Basic Usage

import BSDate from "bs-date";
import "bs-date/src/number-utils.js"; // For Nepali number conversion

// Create a BS date
const bsDate = new BSDate(2082, 5, 25);

// Convert to AD
const adDate = bsDate.toAD();
console.log(adDate); // 2025-09-10T00:00:00.000Z

// Convert AD date to BS
const adDate2 = new Date("2025-09-10");
const bsDate2 = BSDate.fromAD(adDate2);
console.log(bsDate2); // BSDate { year: 2082, month: 5, day: 25 }

// Format in Nepali
console.log(bsDate.toNepali()); // "भाद्र २५, २०८२"

// Get month and day names
console.log(bsDate.monthName()); // "भाद्र"
console.log(bsDate.monthName({ romanized: true })); // "Bhadra"
console.log(bsDate.dayName()); // "मंगलवार"
console.log(bsDate.dayName({ romanized: true })); // "Mangalbar"
console.log(bsDate.dayName({ localized: true })); // "Tuesday"

Using Date Prototype Extension

import "bs-date/src/date-utils.js";

const adDate = new Date("2025-09-10");
const bsDate = adDate.toBS();
console.log(bsDate); // BSDate { year: 2082, month: 5, day: 25 }

Using Native JavaScript Nepali Locale

For displaying dates in Nepali format using native JavaScript localization:

const adDate = new Date("2025-09-10");

// Format AD date in Nepali locale (displays AD date in Nepali numerals)
console.log(adDate.toLocaleDateString("ne-NP")); // "२०२५/९/१०"

// For BS date formatting, combine both approaches
const bsDate = adDate.toBS();
console.log(`BS Date: ${bsDate.toNepali()}`); // "BS Date: भाद्र २५, २०८२"
console.log(`AD Date (Nepali): ${adDate.toLocaleDateString("ne-NP")}`); // "AD Date (Nepali): २०२५/९/१०"

Note: toLocaleDateString('ne-NP') formats the AD date in Nepali numerals and locale format, while toBS() and toNepali() provides the actual BS calendar date in Nepali script.

API Reference

BSDate Class

Constructor

new BSDate(year, month, day);
  • year (number): BS year (2000-2090)
  • month (number): BS month (1-12)
  • day (number): BS day (1-32, varies by month)

Methods

toAD()

Converts the BS date to an AD Date object.

Returns: Date - The equivalent AD date

Throws: BSDateOutOfRangeError - If the BS date is invalid or out of range

toNepali()

Formats the BS date in Nepali script.

Returns: string - The formatted date (e.g., "भाद्र २५, २०८२")

monthName(options)

Gets the month name in Nepali or romanized format.

Parameters:

  • options (object, optional):
    • romanized (boolean): If true, returns romanized month name

Returns: string - The month name

Examples:

bsDate.monthName(); // "भाद्र"
bsDate.monthName({ romanized: true }); // "Bhadra"
dayName(options)

Gets the day name in various formats.

Parameters:

  • options (object, optional):
    • romanized (boolean): If true, returns romanized day name
    • localized (boolean): If true, returns English day name

Returns: string - The day name

Throws: Error - If both romanized and localized are true

Examples:

bsDate.dayName(); // "मंगलवार"
bsDate.dayName({ romanized: true }); // "Mangalbar"
bsDate.dayName({ localized: true }); // "Tuesday"
BSDate.fromAD(adDate)

Static method to create a BSDate from an AD Date.

Parameters:

  • adDate (Date): The AD date to convert

Returns: BSDate - The equivalent BS date

Date Prototype Extension

Date.prototype.toBS()

Converts an AD Date to BSDate.

Returns: BSDate - The equivalent BS date

Throws: DateOutOfRangeError - If the AD date is before April 14, 1943

Number Prototype Extension

Number.prototype.toNepali()

Converts a number to Nepali numerals.

Returns: string - The number in Nepali numerals

Examples:

import "bs-date/src/number-utils.js";

(123).toNepali(); // "१२३"
(2082).toNepali(); // "२०८२"

Supported Date Range

  • BS Range: 2000/01/01 - 2090/12/30
  • AD Range: April 14, 1943 - April 13, 2034

Error Handling

The library throws two types of errors:

BSDateOutOfRangeError

Thrown when:

  • BS year is outside the supported range (2000-2090)
  • BS month is invalid (not 1-12)
  • BS day is invalid for the given month/year
  • Required constructor parameters are missing

DateOutOfRangeError

Thrown when:

  • AD date is before the supported epoch (April 14, 1943)

Examples

Error Handling

import BSDate, { BSDateOutOfRangeError } from "bs-date";

try {
  const invalidDate = new BSDate(1999, 1, 1);
  invalidDate.toAD();
} catch (error) {
  if (error instanceof BSDateOutOfRangeError) {
    console.log("BS date is out of range");
  }
}

Working with Current Date

import BSDate from "bs-date";
import "bs-date/src/date-utils.js";
import "bs-date/src/number-utils.js";

const today = new Date();
const todayBS = today.toBS();
console.log(`Today in BS: ${todayBS.year}/${todayBS.month}/${todayBS.day}`);
console.log(`Today in Nepali: ${todayBS.toNepali()}`);
console.log(`Today is ${todayBS.dayName({ localized: true })}`);

Advanced Usage

import BSDate from "bs-date";
import "bs-date/src/number-utils.js";

const bsDate = new BSDate(2082, 5, 18);

// Different formatting options
console.log("Default format:", bsDate.toNepali()); // "भाद्र १८, २०८२"
console.log("Month (Nepali):", bsDate.monthName()); // "भाद्र"
console.log("Month (English):", bsDate.monthName({ romanized: true })); // "Bhadra"
console.log("Day (Nepali):", bsDate.dayName()); // "बुधबार"
console.log("Day (English romanized):", bsDate.dayName({ romanized: true })); // "Budhbar"
console.log("Day (Localized):", bsDate.dayName({ localized: true })); // "Wednesday"

// Number conversion
console.log("Year in Nepali:", bsDate.year.toNepali()); // "२०८२"
console.log("Day in Nepali:", bsDate.day.toNepali()); // "१८"

BS Calendar Information

The library includes comprehensive data for Bikram Sambat calendar:

  • Months: Baisakh, Jeth, Asar, Shrawan, Bhadra, Ashwin, Kartik, Mangsir, Poush, Magh, Falgun, Chaitra
  • Variable month lengths depending on the year
  • Accurate conversion based on established BS calendar data

Development

Running Tests

npm test

Linting

npm run lint

Development Mode

npm run dev

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Deepak Lamichhane [email protected]