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

bazi-ts-lib

v1.0.1

Published

八字排盘 TypeScript 库 - 支持早晚子时、大运流年、纳音、神煞、格局分析、用神判定

Readme

bazi-ts-lib

八字排盘 TypeScript 库,基于 tyme4ts 构建。

功能特性

  • 基础排盘:四柱、纳音、藏干、十神、十二长生
  • 早晚子时:支持两种流派切换
  • 大运流年:支持 4 种起运算法
  • 神煞系统:151 个神煞(基于 tyme4ts)+ 年柱神煞
  • 格局分析:月令取格法判定八正格
  • 用神分析:五行力量评分 + 扶抑法判定

安装

npm install bazi-ts-lib
# 或
pnpm add bazi-ts-lib

快速开始

import { getBaZi, getFortune, getShenSha, getPattern, getYongShen, getFullBaZi } from "bazi-ts-lib";

// 基础排盘
const bazi = getBaZi(new Date("1990-05-15 10:30"), "男");
console.log(bazi.baziString);                  // "庚午 辛巳 庚辰 辛巳"
console.log(bazi.pillars.day.sixtyCycle);      // "庚辰"
console.log(bazi.pillars.day.sound);           // "白蜡金"
console.log(bazi.specialSigns.ownSign);        // 命宫
console.log(bazi.specialSigns.kongWang);       // ["申", "酉"]

// 大运流年
const fortune = getFortune(bazi, new Date("1990-05-15 10:30"));
console.log(fortune.childLimit.startAge);      // 起运虚岁
console.log(fortune.decades[0].sixtyCycle);    // 第一步大运

// 神煞
const shensha = getShenSha(bazi);
console.log(shensha.yearShenSha);              // 年柱神煞
console.log(shensha.dayShenSha);               // 日柱神煞

// 格局
const pattern = getPattern(bazi);
console.log(pattern.name);                     // "七杀格"

// 用神
const yongShen = getYongShen(bazi);
console.log(yongShen.yongShen);                // 用神五行
console.log(yongShen.jiShen);                  // 忌神五行

// 一键全量分析
const result = getFullBaZi(new Date("1990-05-15 10:30"), "男");

配置选项

interface BaZiConfig {
  // 子时切换:"early" = 早子时(默认)| "late" = 晚子时
  zishiMode: "early" | "late";

  // 起运算法
  childLimitMode: "default" | "china95" | "lunar_sect1" | "lunar_sect2";

  // 大运步数,默认 10
  decadeCount: number;
}

// 使用配置
const bazi = getBaZi(new Date("1990-01-15 23:30"), "男", {
  zishiMode: "late",           // 晚子时
  childLimitMode: "china95",   // China95 起运算法
  decadeCount: 8,              // 8 步大运
});

API 文档

核心函数

| 函数 | 说明 | |------|------| | getBaZi(date, gender, config?) | 基础排盘 | | getBaZiBySiZhu(year, month, day, hour, gender, config?) | 四柱反推 | | getFortune(bazi, date, config?) | 大运流年 | | getAnnualFortuneByYear(bazi, date, year, config?) | 指定年份流年 | | getShenSha(bazi) | 神煞查询 | | getPattern(bazi) | 格局分析 | | getYongShen(bazi) | 用神分析 | | getFullBaZi(date, gender, config?) | 一键全量 |

类型导出

// 基础类型
export type { WuXingType, YinYangType, Gender, TenStarType, TerrainType };

// 结果类型
export type { BaZiResult, FortuneResult, ShenShaResult, PatternResult, YongShenResult };

// 配置
export type { BaZiConfig };

开发

# 安装依赖
pnpm install

# 开发调试
pnpm ts

# 运行测试
pnpm test

# 构建
pnpm build

许可证

Apache-2.0