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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bikram-js

v1.0.2

Published

Bikram Sambat date and Tithi library

Downloads

192

Readme

Bikram-JS

License NPM Version Build Status

Bikram-js is an npm package for converting Gregorian dates to Bikram Sambat dates, calculating Tithis, and providing various functionalities related to the Bikram Sambat calendar. This package is useful for developers needing accurate Nepali date conversions and Tithi calculations in their applications.

Repository Structure

  • Root Folder: Contains the source code for the bikram-js npm package.
  • example Folder: Contains an example implementation of a calendar and date converter to demonstrate the use of the bikram-js package.

Features

  • Convert Gregorian dates to Bikram Sambat dates and vice versa
  • Calculate Tithi (lunar day) for a given Gregorian date and longitude
  • Retrieve Nepali month and weekday names

Installation

You can install the package via npm:

npm install bikram-js
# Or for development purposes:
npm install bikram-js --save-dev

Usage

Bikram and Tithi Class

The Bikram class provides methods for converting between Gregorian and Bikram Sambat dates and retrieving Nepali month and weekday names.

Example

Usage Examples (these examples are in test section of this package too)

Here are some examples of how to use the bikram-js package:

Convert Gregorian Date to Bikram Sambat

import { Bikram } from 'bikram-js';

const bikram = new Bikram();
bikram.fromGregorian(2024, 1, 1);

console.log(bikram.getYear());  // 2080
console.log(bikram.getMonth()); // 9
console.log(bikram.getDay());   // 16

Calculate Tithi

import { Tithi } from 'bikram-js';

const testTithi = new Tithi();
const tithiResult = testTithi.calculateTithi(2024, 1, 1);

console.log(tithiResult.tithi); // "पञ्चमी"
console.log(tithiResult.paksha); // "कृष्ण"

Convert Bikram Sambat Date to Gregorian

import { Bikram } from 'bikram-js';

const bikram = new Bikram();
const gregorianDate = bikram.toGregorian(2081, 1, 1);

console.log(gregorianDate.year);  // 2024
console.log(gregorianDate.month); // 4
console.log(gregorianDate.day);   // 13

Calculate Total Days in Bikram Month

import { Bikram } from 'bikram-js';

const bikram = new Bikram();
const totalDays = bikram.daysInMonth(2081, 8);
console.log(totalDays); // 30

const totalDaysFebruary = bikram.daysInMonth(2081, 2);
console.log(totalDaysFebruary); // 32

Calculate Tithi for Leap Year

import { Tithi } from 'bikram-js';

const testTithi = new Tithi();
const tithiResult = testTithi.calculateTithi(2020, 2, 29);

console.log(tithiResult.tithi); // "पञ्चमी"
console.log(tithiResult.paksha); // "शुक्ल"

Get Nepali Weekday Name from Gregorian Date

import { Bikram } from 'bikram-js';

const bikram = new Bikram();
console.log(bikram.getWeekdayName(2024, 12, 5)); // 'बिहीबार'
console.log(bikram.getWeekdayName(2024, 12, 6)); // 'शुक्रबार' 
console.log(bikram.getWeekdayName(2024, 12, 7)); // 'शनिबार'
console.log(bikram.getWeekdayName(2024, 12, 8)); // 'आइतबार'

Get Nepali Weekday Name from Bikram Sambat Date

import { Bikram } from 'bikram-js';

const bikram = new Bikram();
const gregorianDate = bikram.toGregorian(2081, 8, 20);
const testDay = bikram.getWeekdayName(gregorianDate.year, gregorianDate.month, gregorianDate.day);
console.log(testDay); // "बिहीबार"

Handle Leap Years Correctly

import { Bikram } from 'bikram-js';

const bikram = new Bikram();
console.log(bikram.getWeekdayName(2020, 2, 29)); // 'शनिबार'

Handle Edge Cases Correctly

import { Bikram } from 'bikram-js';

const bikram = new Bikram();
console.log(bikram.getWeekdayName(2024, 1, 1)); // 'सोमबार'
console.log(bikram.getWeekdayName(2024, 12, 31)); // 'मंगलबार'

Get Nepali Month Name for a Given Gregorian Date

import { Bikram } from 'bikram-js';

const bikram = new Bikram();
bikram.fromGregorian(2024, 12, 5);
const testMonthName = bikram.getMonthName(bikram.getMonth());
console.log(testMonthName); // 'मंसिर'

Handle Invalid Month Numbers Gracefully

import { Bikram } from 'bikram-js';

const bikram = new Bikram();
try {
    bikram.getMonthName(0);
} catch (error) {
    console.error(error);
}
try {
    bikram.getMonthName(13);
} catch (error) {
    console.error(error);
}

Documentation

Detailed documentation of functions are available in the docs/docs folder of this repository. You can find comprehensive guides and examples on using the bikram-js library.

To view the documentation:

  1. Navigate to the docs/docs folder.
  2. Open the markdown files to read the documentation.

License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for more details.

Contributing

Contributions are welcome! you can fork this repo, create modifications and send pull request.

Acknowledgements

The Bikram Sambat and Tithi functionalities are implemented using calculations from a port of the Perl script Pancanga library by M. Fushimi and M. Yano. For detailed information, consult the original documentation:

Special thanks to Samar Dhwoj Acharya (techgaun), Kapil Karki (kapil-31), and the Build For Nepal team for their encouragement.

Author

Khumnath CG ([email protected])

Contributors

Special thanks to all contributors.