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

chuan-gong-calc

v1.0.0

Published

串宫推月 - 盲派八字推运算法库

Readme

串宫推月 (chuan-gong-calc)

盲派八字推运算法 NPM 库,用于推演流年、流月运势吉凶。

功能特性

  • 命宫定位(盲派掐指法)
  • 十二宫排布
  • 串宫十二神排布
  • 天干五合/遁干计算
  • 十二长生状态计算

安装

npm install chuan-gong-calc
# 或
pnpm add chuan-gong-calc

快速开始

import { createChart, parseGanZhi } from 'chuan-gong-calc';

// 创建用户八字
const profile = {
  gender: 'male',
  year: parseGanZhi('甲午'),
  month: parseGanZhi('丁丑'),
  day: parseGanZhi('己巳'),
  hour: parseGanZhi('辛未'),
};

// 生成壬寅流年命盘
const result = createChart(profile, '壬寅');

console.log('命宫:', result.fateBranch);
console.log('命宫详情:', result.palaces[result.fateBranch]);

完整示例

输入

import { createChart, parseGanZhi } from 'chuan-gong-calc';

// 乾造:甲午年 丁丑月 己巳日 辛未时
const profile = {
  gender: 'male',
  year: parseGanZhi('甲午'),   // { stem: '甲', branch: '午' }
  month: parseGanZhi('丁丑'),  // { stem: '丁', branch: '丑' }
  day: parseGanZhi('己巳'),    // { stem: '己', branch: '巳' }
  hour: parseGanZhi('辛未'),   // { stem: '辛', branch: '未' }
};

// 推算壬寅流年
const result = createChart(profile, '壬寅');

输出

{
  "fateBranch": "未",
  "palaces": {
    "未": {
      "earthlyBranch": "未",
      "palaceName": "命宫",
      "spiritName": "小耗",
      "hiddenStem": "丁",
      "phase": "冠带"
    },
    "申": {
      "earthlyBranch": "申",
      "palaceName": "兄弟",
      "spiritName": "大耗",
      "hiddenStem": "戊",
      "phase": "沐浴"
    },
    "酉": {
      "earthlyBranch": "酉",
      "palaceName": "夫妻",
      "spiritName": "朱雀",
      "hiddenStem": "己",
      "phase": "长生"
    },
    "戌": {
      "earthlyBranch": "戌",
      "palaceName": "子女",
      "spiritName": "白虎",
      "hiddenStem": "庚",
      "phase": "养"
    },
    "亥": {
      "earthlyBranch": "亥",
      "palaceName": "财帛",
      "spiritName": "贵人",
      "hiddenStem": "辛",
      "phase": "胎"
    },
    "子": {
      "earthlyBranch": "子",
      "palaceName": "疾厄",
      "spiritName": "吊客",
      "hiddenStem": "壬",
      "phase": "绝"
    },
    "丑": {
      "earthlyBranch": "丑",
      "palaceName": "迁移",
      "spiritName": "病符",
      "hiddenStem": "癸",
      "phase": "墓"
    },
    "寅": {
      "earthlyBranch": "寅",
      "palaceName": "奴仆",
      "spiritName": "太岁",
      "hiddenStem": "壬",
      "phase": "死"
    },
    "卯": {
      "earthlyBranch": "卯",
      "palaceName": "官禄",
      "spiritName": "青龙",
      "hiddenStem": "癸",
      "phase": "病"
    },
    "辰": {
      "earthlyBranch": "辰",
      "palaceName": "田宅",
      "spiritName": "丧门",
      "hiddenStem": "甲",
      "phase": "衰"
    },
    "巳": {
      "earthlyBranch": "巳",
      "palaceName": "福德",
      "spiritName": "六合",
      "hiddenStem": "乙",
      "phase": "帝旺"
    },
    "午": {
      "earthlyBranch": "午",
      "palaceName": "父母",
      "spiritName": "官符",
      "hiddenStem": "丙",
      "phase": "临官"
    }
  }
}

API 文档

createChart(profile, targetYear)

生成完整的串宫推月命盘。

参数:

  • profile: UserProfile - 用户八字信息
  • targetYear: string | GanZhi - 目标流年干支

返回:

  • ChartResult - 完整排盘结果

parseGanZhi(ganZhiStr)

解析干支字符串为 GanZhi 对象。

const ganZhi = parseGanZhi('甲子');
// { stem: '甲', branch: '子' }

calculateFatePalace(profile)

计算命宫所在地支。

const fateBranch = calculateFatePalace(profile);
// '未'

类型定义

UserProfile

interface UserProfile {
  gender: 'male' | 'female';
  year: GanZhi;
  month: GanZhi;
  day: GanZhi;
  hour: GanZhi;
}

GanZhi

interface GanZhi {
  stem: Stem;   // 天干
  branch: Branch; // 地支
}

ChartResult

interface ChartResult {
  fateBranch: Branch;
  palaces: Record<Branch, PalaceData>;
}

PalaceData

interface PalaceData {
  earthlyBranch: Branch;   // 地盘地支
  palaceName: PalaceName;  // 十二宫名
  spiritName: SpiritName;  // 串宫十二神
  hiddenStem: Stem;        // 遁干
  phase: PhaseName;        // 十二长生
}

算法说明

命宫定位

采用盲派掐指法:"年上起月,月上起日,日上起时"

例:午年,丑月,巳日,未时
午上起丑 -> 得未
未上起巳 -> 得子
子上起未 -> 得未
结果:命宫在未

十二宫排布

从命宫开始,男顺女逆排布:

命宫 → 兄弟 → 夫妻 → 子女 → 财帛 → 疾厄 → 迁移 → 奴仆 → 官禄 → 田宅 → 福德 → 父母

十二神排布

以流年年支起太岁,男顺女逆:

太岁 → 青龙 → 丧门 → 六合 → 官符 → 小耗 → 大耗 → 朱雀 → 白虎 → 贵人 → 吊客 → 病符

遁干(五虎遁)

根据流年天干确定正月天干,从寅开始顺排:

| 年干 | 正月天干 | |------|----------| | 甲/己 | 丙 | | 乙/庚 | 戊 | | 丙/辛 | 庚 | | 丁/壬 | 壬 | | 戊/癸 | 甲 |

十二长生

以命宫所临天干起长生,阳干顺行,阴干逆行:

长生 → 沐浴 → 冠带 → 临官 → 帝旺 → 衰 → 病 → 死 → 墓 → 绝 → 胎 → 养

开发

# 安装依赖
pnpm install

# 运行测试
pnpm test

# 构建
pnpm build

# 类型检查
pnpm typecheck

许可证

ISC