Skip to content

Latest commit

 

History

History
226 lines (179 loc) · 6.08 KB

File metadata and controls

226 lines (179 loc) · 6.08 KB

API 文档

MingPan 导出六个计算函数和六个 Service 类。所有函数自动处理农历到公历的转换。

统一入口函数

calculateBazi(params) — 八字排盘

async function calculateBazi(params: {
  year: number;       // 出生年
  month: number;      // 出生月 (1-12)
  day: number;        // 出生日 (1-31)
  hour: number;       // 出生时 (0-23)
  minute?: number;    // 出生分 (0-59), 默认 0
  gender?: string;    // 'male' | 'female', 默认 'male'
  isLunar?: boolean;  // 是否为农历, 默认 false
}): Promise<{ data: BaziResult; text: string }>

返回值:

  • data — 结构化八字数据(四柱、十神、神煞、格局、大运等)
  • text — Markdown 格式的排盘文本

示例:

const result = await calculateBazi({
  year: 1990, month: 5, day: 15, hour: 10,
  gender: 'male',
});

calculateZiwei(params) — 紫微斗数排盘

async function calculateZiwei(params: {
  year: number;       // 出生年
  month: number;      // 出生月 (1-12)
  day: number;        // 出生日 (1-31)
  hour: number;       // 出生时 (0-23)
  minute?: number;    // 出生分 (0-59)
  gender: string;     // 'male' | 'female' (必填)
  isLunar?: boolean;  // 是否为农历, 默认 false
}): Promise<{ data: ZiweiResult; text: string }>

返回值:

  • data — 紫微命盘数据(十二宫位、星曜、四化、大限流年等)
  • text — Markdown 格式的命盘文本

calculateLiuyao(params) — 六爻排盘

function calculateLiuyao(params: {
  yaoValues: number[];  // 6 个爻值,每个为 6/7/8/9
                        // 6=老阴(变阳), 7=少阳(不变)
                        // 8=少阴(不变), 9=老阳(变阴)
  year: number;         // 占卜年
  month: number;        // 占卜月
  day: number;          // 占卜日
  hour: number;         // 占卜时
  minute?: number;      // 占卜分
  isLunar?: boolean;    // 是否为农历
}): { data: LiuyaoResult; text: string }

注意: 六爻为同步函数。


calculateMeihua(params) — 梅花易数排盘

function calculateMeihua(params: {
  method: 'time' | 'number';  // 起卦方式
  // --- 时间起卦参数 ---
  year?: number;
  month?: number;
  day?: number;
  hour?: number;
  minute?: number;
  isLunar?: boolean;
  // --- 数字起卦参数 ---
  upperNumber?: number;   // 上卦数
  lowerNumber?: number;   // 下卦数
  yaoNumber?: number;     // 动爻数 (可选)
}): { data: MeihuaResult; text: string }

两种起卦方式:

// 时间起卦
calculateMeihua({ method: 'time', year: 2024, month: 5, day: 14, hour: 10 });

// 数字起卦
calculateMeihua({ method: 'number', upperNumber: 3, lowerNumber: 7, yaoNumber: 5 });

calculateDaliuren(params) — 大六壬排盘

function calculateDaliuren(params: {
  jieqi: string;        // 节气名称, 如 '立夏'
  lunarMonth: number;   // 农历月 (1-12)
  dayGanZhi: string;    // 日干支, 如 '甲辰'
  hourGanZhi: string;   // 时干支, 如 '庚午'
  guirenMethod?: number; // 贵人起法 (0 或 1)
}): { data: DaliurenResult; text: string }

注意: 大六壬需要直接提供干支信息,不接受公历日期。


calculateQimen(params) — 奇门遁甲排盘

function calculateQimen(params: {
  year: number;           // 年
  month: number;          // 月
  day: number;            // 日
  hour: number;           // 时
  minute?: number;        // 分
  isLunar?: boolean;      // 是否为农历
  panType?: string;       // 盘类型: '时盘' | '日盘' | '月盘' | '年盘'
  panStyle?: string;      // 盘式: '转盘' | '飞盘'
  zhiRunMethod?: string;  // 置闰法: 'chaibu' | 'maoshan'
}): { data: QimenResult; text: string }

Service 类(进阶用法)

每个 Service 类可直接实例化,返回更详细的结构化数据(不经 text 渲染):

import {
  BaziService,      // 八字
  ZiweiService,     // 紫微斗数
  LiuyaoService,    // 六爻
  MeihuaService,    // 梅花易数
  DaliurenService,  // 大六壬
  QimenService,     // 奇门遁甲
} from 'mingpan';

const service = new BaziService();
const result = await service.calculate({
  year: 1990, month: 5, day: 15, hour: 10,
  gender: 'male',
  useLunar: false,
});

渲染器

如果只需要文本输出,可以直接使用渲染器:

import { BaziService, renderBaziText } from 'mingpan';

const service = new BaziService();
const data = await service.calculate({ ... });
const text = renderBaziText(
  { bazi: data, gender: 'male', birthDate: new Date(...) },
  { detail: 'standard', includePersonal: false, includeLocation: false }
);

返回数据结构

BaziResult

  • chart — 四柱天干地支
  • birthInfo — 出生信息
  • basic — 基础分析(十神、五行)
  • traditional — 传统分析(神煞、格局)
  • enhanced — 增强分析(旺衰、用神)
  • timeBased — 时间维度(大运、流年、流月、流日)

ZiweiResult

  • basicInfo — 命主基本信息
  • solarDate / lunarDate — 公历/农历日期
  • palaces — 十二宫位及星曜
  • decades — 大限信息
  • currentDecade — 当前大限
  • yearlyInfo — 流年信息
  • mutagenInfo — 四化信息

LiuyaoResult

  • timeInfo — 时间干支信息
  • benGua / bianGua — 本卦/变卦
  • yaoList — 六爻详细信息
  • movingYaoPositions — 动爻位置
  • fuShenList — 伏神信息

MeihuaResult

  • method — 起卦方式
  • qiGuaData — 起卦原始数据
  • benGua / bianGua / huGua — 本卦/变卦/互卦
  • movingYao — 动爻
  • tiYong — 体用分析

DaliurenResult

  • basicInfo — 基础信息(干支、节气)
  • tianDiPan — 天地盘
  • siKe — 四课
  • sanChuan — 三传
  • shenSha — 神煞

QimenResult

  • timeInfo — 时间信息
  • panType / panStyle — 盘类型/盘式
  • yinYangDun — 阴阳遁
  • juShu / yuan — 局数/元
  • gongs — 九宫详细信息
  • geJu — 格局分析