### Browser Environment Usage
Source: https://context7.com/mystilight/mystilight-8char/llms.txt
In a browser, include the minified JS file and access the API via the global `mystilight8char` variable. This example demonstrates generating a Bazi chart and performing a reverse lookup.
```html
八字排盘演示
```
--------------------------------
### Detailed Bazi Data Structure
Source: https://context7.com/mystilight/mystilight-8char/llms.txt
This example shows how to import and use the library in a Node.js environment and details the extensive data structure returned by `getCurrentEightCharJSON`, covering basic info, pillars, luck cycles, and analysis results.
```javascript
import paipan from 'mystilight-8char';
const result = paipan.getCurrentEightCharJSON({
year: 1999, month: 12, day: 10, hour: 15, gender: 0, sect: 2
});
// === 基本信息 ===
console.log('输入信息:', result.input);
// { year: 1999, month: 12, day: 10, hour: 15, minute: 0, second: 0 }
console.log('当前日期:', result.current);
// { year: 2025, month: 1, day: 1 }
console.log('性别:', result.gender); // "女"
console.log('流派:', result.sect); // 2
// === 四柱详情 ===
const dayPillar = result.pillars.day;
console.log('日主天干:', result.pillars.dayMasterGan); // 日主
console.log('日柱干支:', dayPillar.value); // 如 "己丑"
console.log('天干:', dayPillar.gan); // 如 "己"
console.log('地支:', dayPillar.zhi); // 如 "丑"
console.log('藏干:', dayPillar.hideGan); // 如 "癸辛己"
console.log('纳音:', dayPillar.naYin); // 如 "霹雳火"
console.log('天干十神:', dayPillar.shiShenGan); // 如 "日主"
console.log('地支十神:', dayPillar.shiShenZhi); // 地支藏干十神
console.log('地势:', dayPillar.diShi); // 十二长生阶段
console.log('旬:', dayPillar.xun); // 所属旬
console.log('旬空:', dayPillar.xunKong); // 旬空地支
// 藏干详细属性
dayPillar.hideGanAttr.forEach(h => {
console.log(`${h.gan}: ${h.qiLevel}(${h.wuXing}) - ${h.shiShen}`);
// 输出: 癸: 中气(水) - 偏财
});
// === 命宫身宫胎元 ===
console.log('胎元:', result.taiYuan, result.taiYuanNaYin);
console.log('胎息:', result.taiXi, result.taiXiNaYin);
console.log('命宫:', result.mingGong, result.mingGongNaYin);
console.log('身宫:', result.shenGong, result.shenGongNaYin);
// === 运势信息 ===
console.log('起运信息:', result.yun);
// { gender: "女", forward: true, startYear: 2005, startMonth: 3, startDay: 15, startSolar: "2005-03-15 ..." }
// 当前运势
const { daYun, liuNian, xiaoYun, liuYue, liuRi } = result.currentYun;
if (daYun) {
console.log('当前大运:', daYun.ganZhi.join(''), '十神:', daYun.shiShen);
console.log('大运区间:', `${daYun.startYear}-${daYun.endYear}岁`);
}
if (liuNian) {
console.log('当前流年:', liuNian.year, liuNian.ganZhi.join(''), '十神:', liuNian.shiShen);
}
// 大运数组(含十神简称,便于展示)
result.dayunArr.forEach(dy => {
console.log(`大运 ${dy.startYear}: ${dy.ganZhi} [干:${dy.ganshen} 支:${dy.zhishen}]`);
dy.liunianArr.slice(0, 3).forEach(ln => {
console.log(` 流年 ${ln.year}: ${ln.ganZhi} [干:${ln.ganshen} 支:${ln.zhishen}]`);
});
});
// === 分析结果 ===
console.log('日时断语:', result.analysis.rishi);
console.log('三命通会:', result.analysis.SanMingTongHui);
console.log('喜用神:', result.analysis.XiYongShen);
// 渊海子平分析
console.log('月令分析:', result.yuanHaiZiping.yueLing);
console.log('太岁分析:', result.yuanHaiZiping.taiSui);
console.log('身强指数:', result.yuanHaiZiping.shenQiang); // 0-100
console.log('湿度指数:', result.yuanHaiZiping.shidu); // 0-100
// === 其他分析 ===
console.log('配偶外貌:', result.spouseAppearance);
console.log('家庭背景:', result.familyBackground);
console.log('自身外貌:', result.selfAppearance);
console.log('学业才华:', result.educationAndTalent);
// === 性能信息 ===
console.log('计算耗时:', result.meta.durationMs, 'ms');
```
--------------------------------
### getCurrentEightCharJSON - Get Full Bazi Analysis
Source: https://context7.com/mystilight/mystilight-8char/llms.txt
Calculates and returns a comprehensive JSON object containing the full Bazi analysis based on birth date and time. This is the core API for generating Bazi charts and related astrological data.
```APIDOC
## POST /api/getCurrentEightCharJSON
### Description
Retrieves a complete Bazi analysis JSON object based on the provided birth year, month, day, and hour. This includes pillars, luck cycles, elemental strengths, divine stars, and more.
### Method
POST
### Endpoint
/api/getCurrentEightCharJSON
### Parameters
#### Request Body
- **year** (integer) - Required - The birth year.
- **month** (integer) - Required - The birth month.
- **day** (integer) - Required - The birth day.
- **hour** (integer) - Optional - The birth hour (defaults to 0).
- **minute** (integer) - Optional - The birth minute (defaults to 0).
- **second** (integer) - Optional - The birth second (defaults to 0).
- **sect** (integer) - Optional - The Bazi school/sect (1 or 2, defaults to 2).
- **gender** (integer) - Optional - The gender (1 for male, 0 for female, defaults to 1).
- **yunSect** (integer) - Optional - The luck cycle school/sect (defaults to 2).
- **currentYear** (integer) - Optional - The current year to use for fortune analysis.
- **currentMonth** (integer) - Optional - The current month to use for fortune analysis.
- **currentDay** (integer) - Optional - The current day to use for fortune analysis.
### Request Example
```json
{
"year": 1990,
"month": 5,
"day": 15,
"hour": 14,
"minute": 30,
"gender": 1
}
```
### Response
#### Success Response (200)
- **pillars** (object) - Contains the four pillars (Year, Month, Day, Time) with detailed information.
- **wuXingPower** (object) - Represents the strength of the five elements (Wood, Fire, Earth, Metal, Water).
- **currentYun** (object) - Details the current luck cycle, including great luck (DaYun), yearly luck (LiuNian), and small luck (XiaoYun).
- **taiYuan** (string) - The Heavenly Stem and Earthly Branch of the Fetal Origin.
- **taiYuanNaYin** (string) - The Na Yin (sound-based) name of the Fetal Origin.
- **mingGong** (string) - The Heavenly Stem and Earthly Branch of the Palace of Destiny.
- **mingGongNaYin** (string) - The Na Yin name of the Palace of Destiny.
- **shenGong** (string) - The Heavenly Stem and Earthly Branch of the Palace of Body.
- **shenGongNaYin** (string) - The Na Yin name of the Palace of Body.
- **dayunArr** (array) - An array of objects representing the great luck cycles.
- **analysis** (object) - Textual analysis of the Bazi chart.
- **yuanHaiZiping** (object) - Analysis based on the Yuan Hai Zi Ping tradition.
#### Response Example
```json
{
"pillars": {
"year": {"value": "庚午", "gan": "庚", "zhi": "午", "hideGan": "丁己", "wuXing": "金火", "naYin": "路旁土", "shiShenGan": "正财"},
"month": {"value": "辛巳", "gan": "辛", "zhi": "巳", ...},
"day": {"value": "己丑", "gan": "己", "zhi": "丑", ...},
"time": {"value": "辛未", "gan": "辛", "zhi": "未", ...}
},
"wuXingPower": {"木": 14.95, "火": 30.84, "土": 42.99, "金": 8.41, "水": 2.8},
"currentYun": {
"daYun": {"ganZhi": ["丙", "寅"], "shiShen": "劫财", "startYear": 2020, "endYear": 2029, ...},
"liuNian": {"year": 2025, "ganZhi": ["乙", "巳"], "shiShen": "偏印", ...},
"xiaoYun": {"year": 2025, "age": 36, "ganZhi": ["癸", "亥"], ...},
"liuYue": {"monthCn": "正月", "ganZhi": ["戊", "寅"], ...},
"liuRi": {"ganZhi": ["甲", "子"], ...}
},
"taiYuan": "甲申",
"taiYuanNaYin": "申箔金",
"mingGong": "丙辰",
"mingGongNaYin": "辰沙中土",
"shenGong": "己未",
"shenGongNaYin": "未路旁土",
"dayunArr": [
{"startYear": 2005, "ganZhi": "庚申", "ganshen": "财", "zhishen": "财", "liunianArr": [...]},
...
],
"analysis": {"rishi": [...], "SanMingTongHui": [...], "XiYongShen": [...]},
"yuanHaiZiping": {"yueLing": {...}, "taiSui": {...}, "shenQiang": 75, "shidu": 60, "yinyang": {...}}
}
```
```
--------------------------------
### Get Full Bazi Analysis JSON
Source: https://context7.com/mystilight/mystilight-8char/llms.txt
Use this core API to obtain comprehensive Bazi chart data based on birth time. It includes pillar information, luck cycles, elemental strengths, divine symbols, and Yuan Hai Zi Ping analysis. Specify current date parameters for accurate current fortune analysis.
```javascript
import paipan from 'mystilight-8char';
const { getCurrentEightCharJSON } = paipan;
// 基本用法:计算1990年5月15日14:30出生男性的八字
const result = getCurrentEightCharJSON({
year: 1990, // 出生年(必填)
month: 5, // 出生月(必填)
day: 15, // 出生日(必填)
hour: 14, // 出生时,默认0
minute: 30, // 出生分,默认0
second: 0, // 出生秒,默认0
sect: 2, // 八字流派(1或2),默认2
gender: 1, // 性别(1男,0女),默认1
yunSect: 2 // 起运流派,默认2
});
console.log('四柱:', result.pillars);
// 输出示例:
// {
// year: { value: "庚午", gan: "庚", zhi: "午", hideGan: "丁己", wuXing: "金火", naYin: "路旁土", shiShenGan: "正财", ... },
// month: { value: "辛巳", gan: "辛", zhi: "巳", ... },
// day: { value: "己丑", gan: "己", zhi: "丑", ... },
// time: { value: "辛未", gan: "辛", zhi: "未", ... }
// }
console.log('五行力量:', result.wuXingPower);
// 输出示例: { 木: 14.95, 火: 30.84, 土: 42.99, 金: 8.41, 水: 2.8 }
console.log('当前运势:', result.currentYun);
// 输出示例:
// {
// daYun: { ganZhi: ["丙", "寅"], shiShen: "劫财", startYear: 2020, endYear: 2029, ... },
// liuNian: { year: 2025, ganZhi: ["乙", "巳"], shiShen: "偏印", ... },
// xiaoYun: { year: 2025, age: 36, ganZhi: ["癸", "亥"], ... },
// liuYue: { monthCn: "正月", ganZhi: ["戊", "寅"], ... },
// liuRi: { ganZhi: ["甲", "子"], ... }
// }
// 指定当前日期进行运势分析
const resultWithDate = getCurrentEightCharJSON({
year: 1999,
month: 5,
day: 25,
hour: 14,
minute: 30,
sect: 2,
gender: 1,
currentYear: 2025, // 指定当前年
currentMonth: 1, // 指定当前月
currentDay: 1 // 指定当前日
});
console.log('胎元:', resultWithDate.taiYuan, '纳音:', resultWithDate.taiYuanNaYin);
console.log('命宫:', resultWithDate.mingGong, '纳音:', resultWithDate.mingGongNaYin);
console.log('身宫:', resultWithDate.shenGong, '纳音:', resultWithDate.shenGongNaYin);
console.log('大运数组:', resultWithDate.dayunArr);
// dayunArr 包含十神简称,便于展示
// [{ startYear: 2005, ganZhi: "庚申", ganshen: "财", zhishen: "财", liunianArr: [...] }, ...]
console.log('分析文本:', resultWithDate.analysis);
// { rishi: [...], SanMingTongHui: [...], XiYongShen: [...] }
console.log('渊海子平分析:', resultWithDate.yuanHaiZiping);
// { yueLing: {...}, taiSui: {...}, shenQiang: 75, shidu: 60, yinyang: {...} }
```
--------------------------------
### fromBaZi - Infer Birth Date from Bazi Chart
Source: https://context7.com/mystilight/mystilight-8char/llms.txt
Derives possible Gregorian birth dates from a given set of Bazi pillars (Year, Month, Day, Time). This is useful for verifying Bazi calculations or estimating birth times when only the Bazi chart is known.
```APIDOC
## POST /api/fromBaZi
### Description
Infers potential Gregorian birth dates by providing the four Bazi pillars (Year, Month, Day, Time). It returns an array of candidate birth dates that match the provided Bazi.
### Method
POST
### Endpoint
/api/fromBaZi
### Parameters
#### Request Body
- **yearPillar** (string) - Required - The Heavenly Stem and Earthly Branch of the Year Pillar (e.g., '己卯').
- **monthPillar** (string) - Required - The Heavenly Stem and Earthly Branch of the Month Pillar (e.g., '丁丑').
- **dayPillar** (string) - Required - The Heavenly Stem and Earthly Branch of the Day Pillar (e.g., '己亥').
- **timePillar** (string) - Required - The Heavenly Stem and Earthly Branch of the Time Pillar (e.g., '甲子').
- **sect** (integer) - Optional - The Bazi school/sect (1 or 2, defaults to 2).
- **baseYear** (integer) - Optional - The base year to start searching from (defaults to the current year).
### Request Example
```json
{
"yearPillar": "己卯",
"monthPillar": "丁丑",
"dayPillar": "己亥",
"timePillar": "甲子",
"baseYear": 1990
}
```
### Response
#### Success Response (200)
- **candidates** (array) - An array of objects, where each object represents a possible birth date and time.
- **year** (integer) - The inferred birth year.
- **month** (integer) - The inferred birth month.
- **day** (integer) - The inferred birth day.
- **hour** (integer) - The inferred birth hour.
- **minute** (integer) - The inferred birth minute.
- **second** (integer) - The inferred birth second.
- **ymd** (string) - The date in YYYY-MM-DD format.
- **ymdHms** (string) - The date and time in YYYY-MM-DD HH:MM:SS format.
#### Response Example
```json
[
{
"year": 1999,
"month": 1,
"day": 18,
"hour": 0,
"minute": 0,
"second": 0,
"ymd": "1999-01-18",
"ymdHms": "1999-01-18 00:00:00"
},
{
"year": 1999,
"month": 1,
"day": 18,
"hour": 23,
"minute": 0,
"second": 0,
"ymd": "1999-01-18",
"ymdHms": "1999-01-18 23:00:00"
}
]
```
```
--------------------------------
### Derive Birth Date from Bazi
Source: https://context7.com/mystilight/mystilight-8char/llms.txt
Reverse-calculate possible Gregorian birth dates from known Bazi pillars (year, month, day, hour). This function returns an array of matching birth dates, useful for Bazi verification or inferring birth times when only Bazi is known. Specify a base year to limit the search range.
```javascript
import paipan from 'mystilight-8char';
const { fromBaZi } = paipan;
// 从四柱八字反推出生日期
// 参数: 年柱干支, 月柱干支, 日柱干支, 时柱干支, 流派(可选), 基准年(可选)
const candidates = fromBaZi(
'己卯', // 年柱
'丁丑', // 月柱
'己亥', // 日柱
'甲子', // 时柱
2, // 八字流派,默认2
1990 // 基准年,从此年开始搜索
);
console.log('可能的出生日期:');
candidates.forEach(candidate => {
console.log(`${candidate.ymd} ${candidate.hour}:${candidate.minute}:${candidate.second}`);
// 输出示例:
// 1999-01-18 0:0:0
// 1999-01-18 23:0:0
});
// 返回结构示例:
// [
// {
// year: 1999,
// month: 1,
// day: 18,
// hour: 0,
// minute: 0,
// second: 0,
// ymd: "1999-01-18",
// ymdHms: "1999-01-18 00:00:00"
// },
// ...
// ]
// 验证八字计算的一致性
const result = getCurrentEightCharJSON({
year: 1999, month: 5, day: 25, hour: 14, minute: 30, sect: 2, gender: 1
});
const yearGZ = result.pillars.year.value; // 获取年柱干支
const monthGZ = result.pillars.month.value; // 获取月柱干支
const dayGZ = result.pillars.day.value; // 获取日柱干支
const timeGZ = result.pillars.time.value; // 获取时柱干支
const list = fromBaZi(yearGZ, monthGZ, dayGZ, timeGZ, result.sect, 1990);
const found = list.some(s =>
s.year === 1999 && s.month === 5 && s.day === 25 && s.hour === 14
);
console.log('验证结果:', found ? '八字计算正确' : '未找到匹配日期');
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.