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

nepali-date-modern

v0.2.0

Published

A modern, TypeScript-based Nepali date library for Bikram Sambat (B.S.) and Gregorian calendar (A.D.) conversions with comprehensive features

Downloads

2

Readme

Nepali Date Modern

A modern, TypeScript-based Nepali date library for Bikram Sambat (B.S.) and Gregorian calendar (A.D.) conversions with comprehensive features.

Note: This is a modernized fork of the original nepali-date package by Ranjan Shrestha. This version includes TypeScript support, enhanced features, and improved maintainability.

Features

  • TypeScript Support - Full TypeScript support with type definitions
  • Extended Date Range - Support for years 2000-2100 BS
  • Accurate Conversions - Precise Bikram Sambat ↔ Gregorian conversions
  • Holiday Detection - Built-in Nepali holiday detection
  • Rich Formatting - Extensive date formatting options in English and Nepali
  • Date Manipulation - Add/subtract days, months, years
  • Date Comparison - Compare dates, calculate differences
  • Leap Year Support - Proper handling of leap years
  • Validation - Comprehensive input validation
  • Modern Build - ES modules, CommonJS, and UMD support

Installation

npm install nepali-date-modern
# or
yarn add nepali-date-modern

Quick Start

import { NepaliDate } from 'nepali-date-modern';

// Create from Nepali date string
const date1 = new NepaliDate('2075-03-22');
console.log(date1.toString()); // "2075/3/22"

// Create from English date
const date2 = new NepaliDate(new Date('2018-07-06'));
console.log(date2.getYear()); // 2075

// Create from components
const date3 = new NepaliDate(2075, 2, 22); // year, month (0-11), day
console.log(date3.getMonth()); // 2 (March)

// Format dates
console.log(date1.format('YYYY-MM-DD')); // "2075-03-22"
console.log(date1.format('yyyy-mm-dd')); // "२०७५-०३-२२"
console.log(date1.format('MMMM D, YYYY')); // "Chaitra 22, 2075"

API Reference

Constructor

new NepaliDate()                    // Current date
new NepaliDate('2075-03-22')       // From Nepali date string
new NepaliDate(new Date())          // From English Date object
new NepaliDate(2075, 2, 22)        // From year, month, day
new NepaliDate(timestamp)           // From timestamp
new NepaliDate(otherNepaliDate)     // Clone existing date

Date Conversion

const nepaliDate = new NepaliDate('2075-03-22');

// Get English date
const englishDate = nepaliDate.getEnglishDate();
console.log(englishDate.toDateString()); // "Fri Jul 06 2018"

// Get timestamp
const timestamp = nepaliDate.getTime();

Date Components

const date = new NepaliDate('2075-03-22');

console.log(date.getYear());    // 2075
console.log(date.getMonth());   // 2 (March, 0-based)
console.log(date.getDate());    // 22
console.log(date.getDay());     // 5 (Friday, 0-based)
console.log(date.getHours());   // Current hour
console.log(date.getMinutes()); // Current minute
console.log(date.getSeconds()); // Current second

Date Manipulation

const date = new NepaliDate('2075-03-22');

// Add/subtract days
const tomorrow = date.addDays(1);
const yesterday = date.addDays(-1);

// Add/subtract months
const nextMonth = date.addMonths(1);
const prevMonth = date.addMonths(-1);

// Add/subtract years
const nextYear = date.addYears(1);
const prevYear = date.addYears(-1);

// Set components
date.setYear(2076);
date.setMonth(4);  // May (0-based)
date.setDate(15);

Date Comparison

const date1 = new NepaliDate('2075-03-22');
const date2 = new NepaliDate('2075-03-23');

console.log(date1.isBefore(date2));  // true
console.log(date2.isAfter(date1));   // true
console.log(date1.equals(date2));    // false

// Calculate difference in days
const diff = date2.diffInDays(date1); // 1

Formatting

The library supports extensive formatting options:

Year Formats

  • YYYY - 4 digit year (2075)
  • yyyy - 4 digit year in Nepali (२०७५)
  • YYY - 3 digit year (075)
  • yyy - 3 digit year in Nepali (०७५)
  • YY - 2 digit year (75)
  • yy - 2 digit year in Nepali (७५)

Month Formats

  • M - month number (1-12)
  • m - month number in Nepali (१-१२)
  • MM - month with zero padding (01-12)
  • mm - month in Nepali with zero padding (०१-१२)
  • MMM - short month name (Bai, Jes, Asa, etc.)
  • mmm - short month name in Nepali (बै, जे, अ, etc.)
  • MMMM - full month name (Baisakh, Jestha, etc.)
  • mmmm - full month name in Nepali (बैसाख, जेष्ठ, etc.)

Day Formats

  • D - day of month (1-31)
  • d - day of month in Nepali (१-३१)
  • DD - day with zero padding (01-31)
  • dd - day in Nepali with zero padding (०१-३१)
  • DDD - weekday short (Sun, Mon, etc.)
  • ddd - weekday short in Nepali (आइत, सोम, etc.)
  • DDDD - weekday full (Sunday, Monday, etc.)
  • dddd - weekday full in Nepali (आइतबार, सोमबार, etc.)

Examples

const date = new NepaliDate('2075-03-22');

console.log(date.format('YYYY-MM-DD'));           // "2075-03-22"
console.log(date.format('yyyy-mm-dd'));           // "२०७५-०३-२२"
console.log(date.format('MMMM D, YYYY'));         // "Chaitra 22, 2075"
console.log(date.format('mmmm d, yyyy'));         // "चैत्र २२, २०७५"
console.log(date.format('DDDD, MMMM D'));         // "Friday, Chaitra 22"
console.log(date.format('dddd, mmmm d'));         // "शुक्रबार, चैत्र २२"
console.log(date.format('"Today is" DDDD'));      // "Today is Friday"

Holiday Detection

const date = new NepaliDate('2075-01-01');

// Check if date is a holiday
if (date.isHoliday()) {
  console.log('It\'s a holiday!');
}

// Get holiday details
const holidays = date.getHolidays();
holidays.forEach(holiday => {
  console.log(`${holiday.name} (${holiday.nameNepali})`);
  console.log(`Type: ${holiday.type}`);
});

Leap Year Support

const date = new NepaliDate('2076-01-01');
console.log(date.isLeapYear()); // true

const nonLeapDate = new NepaliDate('2075-01-01');
console.log(nonLeapDate.isLeapYear()); // false

Static Methods

// Create from timestamp
const date1 = NepaliDate.fromTimestamp(Date.now());

// Create from English date string
const date2 = NepaliDate.fromEnglishDate('2018-07-06');

// Get current date
const now = NepaliDate.now();

// Get supported date range
const minDate = NepaliDate.minimum();
const maxDate = NepaliDate.maximum();

Validation

The library includes comprehensive validation:

// Valid dates
new NepaliDate('2075-03-22');  // ✅
new NepaliDate('2075/03/22');  // ✅
new NepaliDate('2075.03.22');  // ✅

// Invalid dates (will throw errors)
new NepaliDate('1999-01-01');  // ❌ Year out of range
new NepaliDate('2101-01-01');  // ❌ Year out of range
new NepaliDate('2075-13-01');  // ❌ Invalid month
new NepaliDate('2075-03-32');  // ❌ Invalid day
new NepaliDate('invalid');      // ❌ Invalid format

Supported Date Range

  • Nepali Years: 2000 BS to 2100 BS
  • Gregorian Years: 1943 AD to 2043 AD

Build Outputs

The library is built with multiple formats:

  • CommonJS: dist/index.js
  • ES Modules: dist/index.esm.js
  • TypeScript Definitions: dist/index.d.ts

Development

# Install dependencies
npm install

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Lint code
npm run lint

# Build library
npm run build

# Development mode (build + test)
npm run dev

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run tests and linting
  6. Submit a pull request

License

MIT License - see LICENSE file for details.

Changelog

v0.2.0 - Modernized Fork

  • TypeScript Support - Full TypeScript rewrite with type definitions
  • Extended Date Range - Support for years 2000-2100 BS
  • Holiday Detection - Built-in Nepali holiday detection
  • Rich Formatting - Enhanced formatting options in English and Nepali
  • Date Manipulation - Add/subtract days, months, years
  • Date Comparison - Compare dates, calculate differences
  • Modern Build - ES modules, CommonJS, and UMD support
  • 🐛 Bug Fixes - Fixed date calculation issues
  • 📚 Documentation - Comprehensive API documentation
  • 🔄 Fork - Modernized version of the original nepali-date package

v0.1.3 (Original Package)

  • Initial release with basic functionality by Ranjan Shrestha