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

xiaochengtu

v1.0.1

Published

小成图排盘库 - XiaoChengTu divination library for TypeScript/JavaScript

Readme

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