Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A TypeScript/JavaScript library for XiaoChengTu (小成图) divination, implementing the traditional Chinese Yi-Jing based prediction method.

License

Notifications You must be signed in to change notification settings

look-fate/xiaochengtu-ts-lib

Repository files navigation

xiaochengtu

小成图排盘 TypeScript/JavaScript 库

A TypeScript/JavaScript library for XiaoChengTu (小成图) divination, implementing the traditional Chinese Yi-Jing based prediction method.

安装 / Installation

# npm
npm install xiaochengtu

# pnpm
pnpm add xiaochengtu

# yarn
yarn add xiaochengtu

快速开始 / Quick Start

import { XiaoChengTu, Trigram } from 'xiaochengtu'

// 方式1: 使用卦象直接创建
const xct = new XiaoChengTu({
  baseHexagram: { upper: Trigram.Kan, lower: Trigram.Li }, // 水火既济
  changedHexagram: { upper: Trigram.Dui, lower: Trigram.Gen }, // 泽山咸
})

// 执行排盘
const result = xct.divine()
console.log(result)

// 输出格式化结果
console.log(xct.toString())

// 方式2: 使用数字起卦
const xct2 = XiaoChengTu.fromNumbers({
  baseUpper: 6, // 坎
  baseLower: 3, // 离
  changedUpper: 2, // 兑
  changedLower: 7, // 艮
})

// 方式3: 随机起卦
const xct3 = XiaoChengTu.random()

// 方式4: 时间起卦
const xct4 = XiaoChengTu.fromTime() // 使用当前时间
const xct5 = XiaoChengTu.fromTime(new Date('2024-01-15T10:30:00')) // 指定时间

八卦编号 / Trigram Numbers

使用先天数:

数字 八卦 Trigram
1 Qian
2 Dui
3 Li
4 Zhen
5 Xun
6 Kan
7 Gen
8 Kun

API

XiaoChengTu 类

主要的排盘类。

构造函数

new XiaoChengTu(input: XiaoChengTuInput)

静态方法

  • XiaoChengTu.fromNumbers(input: NumberDivinationInput) - 从数字创建
  • XiaoChengTu.random() - 随机起卦
  • XiaoChengTu.fromTime(date?: Date) - 时间起卦

实例方法

  • divine(): XiaoChengTuResult - 执行排盘,返回完整结果
  • getPalaceAnalysis(palace: Palace): PalaceAnalysis | undefined - 获取指定宫位分析
  • toString(): string - 输出格式化的盘面字符串

类型定义

Trigram (八卦)

enum Trigram {
  Qian = 'qian', // 乾
  Dui = 'dui', // 兑
  Li = 'li', // 离
  Zhen = 'zhen', // 震
  Xun = 'xun', // 巽
  Kan = 'kan', // 坎
  Gen = 'gen', // 艮
  Kun = 'kun', // 坤
}

Palace (九宫)

enum Palace {
  Kan = 1, // 坎宫 - 正北
  Kun = 2, // 坤宫 - 西南
  Zhen = 3, // 震宫 - 正东
  Xun = 4, // 巽宫 - 东南
  Center = 5, // 中宫 - 中央
  Qian = 6, // 乾宫 - 西北
  Dui = 7, // 兑宫 - 正西
  Gen = 8, // 艮宫 - 东北
  Li = 9, // 离宫 - 正南
}

FourImages (四象)

enum FourImages {
  He = 'he', // 阖 - 向心/凝聚
  Pi = 'pi', // 辟 - 离心/发散
  Wang = 'wang', // 往 - 外引
  Lai = 'lai', // 来 - 内引
}

工具函数

// 数字转八卦
numberToTrigram(num: number): Trigram

// 生成互卦
generateMutualHexagram(hexagram: Hexagram): Hexagram

// 判断是否为八纯卦
isPureHexagram(hexagram: Hexagram): boolean

// 判断是否为同位异性卦
isOppositeHexagram(hexagram: Hexagram): boolean

// 计算中宫
calculateCenterPalace(baseHexagram: Hexagram, changedHexagram: Hexagram): Trigram

// 计算四象
calculateFourImages(skyTrigram: Trigram, earthTrigram: Trigram): FourImages

// 计算配对结果
calculateMatchResult(skyTrigram: Trigram, earthTrigram: Trigram): MatchResult

// 获取八卦中文名
getTrigramChineseName(trigram: Trigram): string

// 获取宫位中文名
getPalaceChineseName(palace: Palace): string

示例输出

========================================
小成图排盘结果
========================================
本卦: 坎离
变卦: 兑艮
本互卦: 离坎
变互卦: 乾巽

九宫布局:
----------------------------------------
| 兑    | 坎    | 坎    |
| 巽    | 离    | 坤    |
----------------------------------------
| 艮    | 乾    | 巽    |
| 震    | 中    | 兑    |
----------------------------------------
| 离    | 离    | 乾    |
| 艮    | 坎    | 乾    |
----------------------------------------

各宫分析:
坎宫(正北): 天盘离 地盘坎 → 吉 - 内引得配,宜守成
坤宫(西南): 天盘坎 地盘坤 → 凶 - 外引失配,奔波徒劳
...

许可证 / License

MIT

About

A TypeScript/JavaScript library for XiaoChengTu (小成图) divination, implementing the traditional Chinese Yi-Jing based prediction method.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •