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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@baostudio/viet-lunar

v0.1.1

Published

Vietnamese Lunar Calendar library for TypeScript - Convert between Solar ↔ Lunar calendar, compute Can-Chi, Solar Terms, and Vietnamese auspicious/inauspicious rules

Readme

🌙 Vietnamese Lunar Calendar (viet-lunar)

License: MIT TypeScript Bun

A comprehensive, deterministic TypeScript library for the Vietnamese Lunar Calendar (Âm Lịch Việt Nam). Convert between Solar ↔ Lunar dates, compute Can-Chi (Sexagenary cycles), Solar Terms (24 Tiết Khí), Hoàng Đạo hours, and Vietnamese auspicious/inauspicious day rules.


✨ Features

  • Accurate Solar ↔ Lunar Conversion with Vietnamese timezone (UTC+7)
  • Can-Chi (干支) Calculations for year, month, day, and hour
  • 24 Solar Terms (Tiết Khí) computation
  • Hoàng Đạo Hours (Auspicious hours for daily activities)
  • Vietnamese Day Analysis (Nên/Kiêng - Should Do/Avoid)
  • 12 Trực (建除十二客) and 28 Lunar Mansions (Nhị Thập Bát Tú)
  • Vietnamese Holidays detection (Tết, Giỗ Tổ, Trung Thu, etc.)
  • Leap Month handling
  • Dual Localization (Vietnamese & English)
  • Pure Functions - deterministic and testable
  • ESM + CJS exports

📦 Installation

# Using npm
npm install @baostudio/viet-lunar

# Using bun
bun add @baostudio/viet-lunar

# Using yarn
yarn add @baostudio/viet-lunar

🚀 Quick Start

import { solarToLunar, analyzeDay } from '@baostudio/viet-lunar';

// Convert solar to lunar date
const lunar = solarToLunar({ year: 2024, month: 2, day: 10 });
console.log(lunar); 
// { year: 2024, month: 1, day: 1, leapMonth: false } - Tết 2024!

// Analyze a day
const analysis = analyzeDay({ year: 2025, month: 11, day: 4 });
console.log(analysis.lunar);      // Lunar date
console.log(analysis.canChi);     // Can-Chi for year, month, day
console.log(analysis.nen);        // Activities recommended
console.log(analysis.kieng);      // Activities to avoid
console.log(analysis.quality);    // Day quality: excellent/good/neutral/poor/bad

📖 API Documentation

Core Conversions

solarToLunar(solar: SolarDate): LunarDate

Convert a Gregorian (solar) date to Vietnamese lunar date.

import { solarToLunar } from '@baostudio/viet-lunar';

const lunar = solarToLunar({ year: 2024, month: 2, day: 10 });
// Returns: { year: 2024, month: 1, day: 1, leapMonth: false }

lunarToSolar(lunar: LunarDate): SolarDate

Convert a Vietnamese lunar date to Gregorian date.

import { lunarToSolar } from '@baostudio/viet-lunar';

const solar = lunarToSolar({ year: 2025, month: 1, day: 1, leapMonth: false });
// Returns: { year: 2025, month: 1, day: 29 } - Tết 2025

Can-Chi (Sexagenary) Calculations

getCanChiYear(year: number): Sexagenary

Get the Can-Chi for a year.

import { getCanChiYear } from '@baostudio/viet-lunar';

const yearCanChi = getCanChiYear(2024);
// Returns: { stem: "Giáp", branch: "Thìn", code: 40 }

getCanChiDay(solar: SolarDate): Sexagenary

Get the Can-Chi for a specific day.

import { getCanChiDay } from '@baostudio/viet-lunar';

const dayCanChi = getCanChiDay({ year: 2025, month: 11, day: 4 });
// Returns: { stem: "Bính", branch: "Tý", code: 12 }

getAllCanChi(solar: SolarDate, hour?: number): CanChiInfo

Get all Can-Chi (year, month, day, hour) for a date.

import { getAllCanChi } from '@baostudio/viet-lunar';

const canChi = getAllCanChi({ year: 2025, month: 11, day: 4 }, 9);
console.log(canChi.year);   // Year Can-Chi
console.log(canChi.month);  // Month Can-Chi
console.log(canChi.day);    // Day Can-Chi
console.log(canChi.hour);   // Hour Can-Chi

Day Analysis

analyzeDay(solar: SolarDate, options?: AnalysisOptions): DayAnalysis

Comprehensive analysis of a day including:

  • Lunar date
  • Can-Chi for year, month, day, hour
  • Solar term
  • Hoàng Đạo hours
  • Trực (12 Positions)
  • Nên (recommended activities)
  • Kiêng (activities to avoid)
  • Holidays
  • Overall quality
import { analyzeDay } from '@baostudio/viet-lunar';

const analysis = analyzeDay(
  { year: 2025, month: 11, day: 4 },
  { hour: 9, locale: 'vi' }
);

console.log(analysis.lunar);           // { year: 2025, month: 9, day: 15, leapMonth: false }
console.log(analysis.canChi.day);      // Day's Can-Chi
console.log(analysis.hoangDao.hours);  // ["Tý", "Sửu", "Mão", ...]
console.log(analysis.nen);             // ["cưới hỏi", "khai trương", ...]
console.log(analysis.kieng);           // ["động thổ", ...]
console.log(analysis.quality);         // "good"

findGoodDays(startDate, endDate, criteria?): DayAnalysis[]

Find good days within a date range.

import { findGoodDays } from '@baostudio/viet-lunar';

const goodDays = findGoodDays(
  { year: 2025, month: 11, day: 1 },
  { year: 2025, month: 11, day: 30 },
  'excellent'
);

console.log(`Found ${goodDays.length} excellent days`);

Solar Terms

getSolarTerm(solar: SolarDate): SolarTerm | undefined

Get the solar term if the date falls on one.

import { getSolarTerm } from '@baostudio/viet-lunar';

const term = getSolarTerm({ year: 2024, month: 2, day: 4 });
// Returns solar term if date is Lập Xuân, Vũ Thủy, etc.

Formatting

toRichText(analysis: DayAnalysis, locale?: 'vi' | 'en'): string

Format analysis result as rich text.

import { toRichText, analyzeDay } from '@baostudio/viet-lunar';

const analysis = analyzeDay({ year: 2025, month: 11, day: 4 });
const text = toRichText(analysis, 'vi');
console.log(text);

🎯 Use Cases

1. Wedding Date Selection

import { findDaysForActivity } from '@baostudio/viet-lunar';

const weddingDays = findDaysForActivity(
  { year: 2025, month: 12, day: 1 },
  { year: 2026, month: 2, day: 28 },
  'cưới hỏi'
);

console.log(`Found ${weddingDays.length} suitable days for weddings`);

2. Business Opening

import { analyzeDay } from '@baostudio/viet-lunar';

const analysis = analyzeDay({ year: 2025, month: 11, day: 4 });

if (analysis.nen.includes('khai trương')) {
  console.log('Good day to open business!');
  console.log('Auspicious hours:', analysis.hoangDao.hours);
}

3. Calendar Widget

import { analyzeDay, toDisplayObject } from '@baostudio/viet-lunar';

const today = { year: 2025, month: 11, day: 4 };
const analysis = analyzeDay(today);
const display = toDisplayObject(analysis, 'vi');

// Use display object in your UI
// display.date.lunar, display.canChi, display.recommendations, etc.

🧪 Testing

# Run tests
bun test

# Run with watch mode
bun test --watch

🏗️ Building

# Build all formats (ESM + CJS + Types)
bun run build

# Build individual formats
bun run build:esm
bun run build:cjs
bun run build:types

📚 Documentation

For detailed documentation on algorithms and Vietnamese lunar calendar rules, see:


🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


📄 License

MIT License - see LICENSE for details


🙏 Acknowledgments

  • Based on Vietnamese astronomical calculations and traditional calendar rules
  • Algorithms adapted from Jean Meeus' "Astronomical Algorithms"
  • Vietnamese calendar research by Prof. Hoàng Xuân Hãn

📮 Contact

Created by Bao Studio

For issues or questions, please open an issue on GitHub.


Built with ❤️ using Bun and TypeScript