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-engine

v0.1.0

Published

Bazi (Four Pillars) computation engine: true solar time with Meeus equation-of-time, IANA timezone & DST handling, four pillars, ten gods, hidden stems, Na Yin, void branches and luck pillars. Emits a NormalizedChart that <BaziChart /> renders directly. P

Readme

bazi-engine

BaziKit 的计算层 — by AskingMing。传入出生日期、时间、地点和性别,返回可直接用于 <BaziChart /> 的完整八字命盘。

import { computeBazi } from 'bazi-engine';

const result = computeBazi({
  solar: '1990-03-24 09:54',
  gender: 'male',
  location: { city: '广州' },
});

// 直接传给渲染组件——无需适配器
<BaziChart data={result} lang="both" theme="light" />

v1 功能范围

| 功能 | 来源 | |------|------| | 四柱 + 天干、地支、藏干 | lunar-typescript | | 十神(天干级 + 藏干级) | lunar + 自有推导 | | 纳音、旬/空亡 | lunar-typescript | | 胎元 / 胎息 / 命宫 / 身宫 | lunar-typescript | | 十二长生 · 星运(日干对各柱地支) | lunar-typescript | | 自坐(本柱天干对本柱地支) | 自有 10×12 表 | | 大运(含十神、纳音) | lunar + 自有增强 | | 真太阳时(Meeus & approx EOT) | 自有实现 | | 城市 → 经纬度 + IANA 时区(88 城) | 内置数据 | | 历史夏令时 via Intl(中国 1986–91、韩国 1988…) | 自有解析器 |

v1 不含(计划 v2):刑冲合会、神煞、五行分值。

API

computeBazi(input: BaziInput): BaziResult

纯函数。相同输入 → 逐字节相同输出。无 IO、无 Date.now()、无全局状态。

入参

interface BaziInput {
  // 时间——三选一(优先级:parts > solar > date)
  solar?: string;           // '1990-03-24 09:54' 或 '1990/3/4 9:5'
  parts?: { year; month; day; hour; minute; second? };
  date?: Date;              // 按本地时间解读;推荐用 solar/parts

  gender: 'male' | 'female';

  // 地点——四种写法,按顺序检查
  location?:
    | { city: string }                              // 内置城市表
    | { longitude: number; timeZone: string }         // IANA → Intl 解析
    | { longitude: number; timeZoneOffset: number; dstOffset?: number }
    | { longitude: number; standardMeridian: number; dstOffset?: number };

  trueSolarTime?: boolean | 'auto';  // 默认 'auto'
  eotAlgorithm?: 'meeus' | 'approx'; // 默认 'meeus'
  sect?: 1 | 2;                      // 默认 2
  disambiguation?: 'compatible' | 'earlier' | 'later' | 'reject';
  referenceDate?: Date | string;     // 用于标记当前大运 daYun[].isCurrent
  luckPillars?: number;              // 默认 8,限制 1–20
}

输出

BaziResult extends NormalizedChart——可直接赋值给 <BaziChart />。额外字段:

  • solarTime — 完整校正明细(钟表时间、校正后时间、经度补偿、EOT、偏移量、时辰变化标志)
  • options — 回显的设置项,可用于缓存键
  • warnings — 非致命问题(跳过校正、假设无夏令时等)
  • engineVersion — 包版本号字符串

错误处理

| 类 | 触发条件 | |----|---------| | BaziInputError | 输入缺失/无效、未知城市、无效时区 | | BaziRangeError | 日期超出 1900-01-01 … 2099-12-31 |

两者均携带结构化的 field 和 received 属性,方便表单 UI 高亮出错字段。

设计决策

  • lunar-typescript 作为依赖而非 vendor。 历法表约 1.4 MB 且维护良好;精确 pin 到 1.8.6 并用 parity 测试守护比 fork 更安全。
  • 真太阳时默认使用 Meeus EOT。 也提供 approx 模型,用于复现使用近似公式的引擎结果。
  • IANA 优于静态偏移。 历史夏令时规则会变;Intl.DateTimeFormat 能正确处理。例如中国在 1988 年夏季为 UTC+9,静态表无法表达。
  • 无全局状态。 EightChar.setSect() 是实例方法。formatter 缓存是幂等的派生值记忆化。不同参数的并发调用互不干扰。

法律

本包依赖 MIT 许可的项目。详见 NOTICE 和 THIRD-PARTY-MIT.md。

| 上游 | 版本 | 角色 | |------|------|------| | lunar-typescript | 1.8.6 | 运行时依赖(历法核心) |

许可证

MIT © 2026 AskingMing.