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

@zhihao93.li/bazi-sdk

v0.2.0

Published

八字命理计算 SDK - 专业、准确、易用

Downloads

20

Readme

@zhihao93.li/bazi-sdk

八字命理计算 SDK - 专业、准确、易用

✨ 特性

  • 🎯 完整功能: 四柱排盘、日主强弱、格局检测、五行分析、大运流年
  • 🏗️ 教科书级架构: 基于五层格局检测系统(结构分析、纯度检测、评分重算、冲突引擎、格局调度)
  • 🎨 简单易用: 一行代码完成计算,也支持分步调用
  • 📦 轻量级: 约 200KB(包含所有功能)
  • 🌍 真太阳时: 支持 3000+ 城市的经纬度和真太阳时校正
  • 🔧 TypeScript: 完整的类型定义

📦 安装

npm install @zhihao93.li/bazi-sdk

🚀 快速开始

最简单的用法

import { BaziSDK } from '@zhihao93.li/bazi-sdk';

const bazi = new BaziSDK();

const result = bazi.calculate({
  gender: 'male',
  calendarType: 'solar',
  year: 1990,
  month: 10,
  day: 15,
  hour: 14,
  minute: 30,
  location: '北京'  // 自动查询经纬度和真太阳时
});

console.log(result);

输出结果

{
  "fourPillars": {
    "year": { "heavenlyStem": {...}, "earthlyBranch": {...}, "naYin": "路旁土" },
    "month": { "heavenlyStem": {...}, "earthlyBranch": {...}, "naYin": "屋上土" },
    "day": { "heavenlyStem": {...}, "earthlyBranch": {...}, "naYin": "大海水" },
    "hour": { "heavenlyStem": {...}, "earthlyBranch": {...}, "naYin": "剑锋金" }
  },
  "dayMaster": {
    "strength": "strong",
    "analysis": {
      "totalScore": 85,
      "deLing": 30,
      "deDi": 45,
      "tianGanHelp": 10
    }
  },
  "pattern": {
    "name": "曲直格",
    "category": "special",
    "description": "木气专旺成格"
  },
  "fiveElements": {
    "favorable": ["water", "wood"],
    "unfavorable": ["fire", "earth"]
  }
}

📖 使用方式

1. 一键计算(推荐)

const result = bazi.calculate({
  gender: 'male',
  calendarType: 'solar',
  year: 1990,
  month: 10,
  day: 15,
  hour: 14,
  minute: 30,
  location: '北京'
});

2. 分步调用(灵活控制)

// 第 1 步:排盘
const fourPillars = bazi.getFourPillars({
  gender: 'male',
  calendarType: 'solar',
  year: 1990,
  month: 10,
  day: 15,
  hour: 14,
  minute: 30,
  location: '北京'
});

// 第 2 步:分析日主
const dayMaster = bazi.analyzeDayMaster(fourPillars);

// 第 3 步:检测格局
const pattern = bazi.detectPattern(fourPillars, dayMaster);

// 第 4 步:五行分析
const fiveElements = bazi.analyzeFiveElements(fourPillars, dayMaster);

3. 函数式调用(高级用户)

import { calculateBazi, calculateDayMasterOptimized } from '@zhihao93.li/bazi-sdk';

const result = calculateBazi({
  gender: 'male',
  calendarType: 'solar',
  year: 1990,
  month: 10,
  day: 15,
  hour: 14,
  minute: 30,
  longitude: 116.4074,
  latitude: 39.9042
});

🎯 核心功能

| 功能 | 接口 | 说明 | |-----|------|------| | 一键计算 | calculate() | 返回完整结果 | | 四柱排盘 | getFourPillars() | 天干地支、藏干、纳音 | | 日主强弱 | analyzeDayMaster() | 得令、得地、天干帮扶 | | 格局检测 | detectPattern() | 专旺格、从格、化气格、普通格 | | 五行分析 | analyzeFiveElements() | 喜忌用神、五行分布 | | 大运流年 | calculateDayun() | 一生运势预测 | | 真太阳时 | calculateTrueSolarTime() | 时辰校正 |

📚 详细文档

🏗️ 架构特点

五层格局检测系统

第一层: 结构分析器 (StructuralAnalyzer)
  ↓ 透干、通根、会合
第二层: 纯度检测器 (PurityChecker)
  ↓ 检测杂质、闲神
第三层: 评分重算器 (ScoreRecalculator)
  ↓ 基于格局重新评估强弱
第四层: 冲突引擎 (ConflictEngine)
  ↓ 检测破格因素
第五层: 格局调度器 (PatternDispatcher)
  ↓ 综合判定最终格局

🔧 开发

# 安装依赖
npm install

# 开发模式
npm run dev

# 构建
npm run build

# 测试
npm test

# 代码检查
npm run lint

📄 许可证

MIT

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📮 联系