Skip to content

Latest commit

 

History

History
361 lines (302 loc) · 10.7 KB

README.md

File metadata and controls

361 lines (302 loc) · 10.7 KB

ASTRO

一套轻量级紫微斗数排盘工具库。

GitHub Workflow Status (with event) npm GitHub top language Codecov npm Maintenance GitHub GitHub code size in bytes npm bundle size GitHub issues GitHub package.json dynamic


简体中文 🔸 English

📢 介绍

用于紫微斗数排盘的工具库,目前支持简体中文、繁体中文、英文、韩文、日文,大家有任何问题欢迎到这里提问交流,如果发现程序有不对的地方,欢迎到这里提交Bug。扣码不易,希望得到各位大佬的星星。🍻

🌰 举个栗子

🎲 用法

🚀 让我们开始把

npm i @sylarlong/astro -S

❓ 调用方法

  • ES6 Module

    import { astro } from '@sylarlong/astro';
    
    // 通过阳历获取星盘信息
    const astrolabe = astro.astrolabeBySolarDate('2000-8-16', 2, '女', true, 'zh-CN');
    
    // 通过农历获取星盘信息
    const astrolabe = astro.astrolabeByLunarDate('2000-7-17', 2, '女', false, true, 'zh-CN');
  • CommonJS

    var astroObj = require('@sylarlong/astro');
    
    // 通过阳历获取星盘信息
    var astrolabe = astroObj.astro.astrolabeBySolarDate('2000-8-16', 2, '女', true, 'zh-CN');
    
    // 通过农历获取星盘信息
    var astrolabe = astroObj.astro.astrolabeByLunarDate('2000-7-17', 2, '女', false, true, 'zh-CN');
✍️ 方法定义
  • astrolabeBySolarDate

    /**
     * 通过阳历获取星盘信息
     *
     * @param solarDateStr 阳历日期【YYYY-M-D】
     * @param timeIndex 出生时辰序号【0~12】,对应从早子时(0)一直到晚子时(12)的序号
     * @param gender 性别【男|女】
     * @param fixLeap 是否调整闰月情况【默认 true】,假入调整闰月,则闰月的前半个月算上个月,后半个月算下个月
     * @param language 指定返回数据语言【默认 zh-CN】,目前支持zh-CN、zh-TW、en-US、ko-KR、ja-JP
     * @returns 星盘信息
     */
    type astrolabeBySolarDate = (
      solarDateStr: string,
      timeIndex: number,
      gender: Gender,
      fixLeap: boolean = true,
      language: Language = 'zh-CN'
    ) => Astrolabe;
  • astrolabeByLunarDate

    /**
     * 通过农历获取星盘信息
     *
     * @param lunarDateStr 农历日期【YYYY-M-D】,例如2000年七月十七则传入 2000-7-17
     * @param timeIndex 出生时辰序号【0~12】
     * @param gender 性别【男|女】
     * @param isLeapMonth 是否闰月【默认 false】,当实际月份没有闰月时该参数不生效
     * @param fixLeap 是否调整闰月情况【默认 true】,假入调整闰月,则闰月的前半个月算上个月,后半个月算下个月
     * @param language 指定返回数据语言【默认 zh-CN】,目前支持zh-CN、zh-TW、en-US、ko-KR、ja-JP
     * @returns 星盘信息
     */
    type astrolabeByLunarDate = (
      lunarDateStr: string,
      timeIndex: number,
      gender: Gender,
      isLeapMonth: boolean = false,
      fixLeap: boolean = true,
      language: Language = 'zh-CN'
    ) => Astrolabe;
📑 返回数据
    {
      // 阳历日期
      solarDate: '2000-8-16',
       // 农历日期
      lunarDate: '二〇〇〇年七月十七',
      // 四柱
      chineseDate: '庚辰 甲申 丙午 庚寅',
      // 时辰
      time: '寅时',
      // 时辰对应的时间段
      timeRange: '03:00~05:00',
      // 星座
      sign: '狮子座',
      // 生肖
      zodiac: '龙',
      // 命宫地支
      earthlyBranchOfSoulPalace: '午',
      // 身宫地支
      earthlyBranchOfBodyPalace: '戌',
      // 命主
      soul: '破军',
      // 身主
      body: '文昌',
      // 五行局
      fiveElementsClass: '木三局',
      // 十二宫数据,从寅宫开始
      palaces: [
        {
          // 宫名
          name: '财帛',
          // 是否身宫
          isBodyPalace: false,
          // 是否来因宫
          isOriginalPalace: false,
          // 宫位天干
          heavenlyStem: '戊',
          // 宫位地支
          earthlyBranch: '寅',
          // 主星(含天马禄存)
          majorStars: [
            { name: '武曲', type: 'major', scope: 'origin', brightness: '得' },
            { name: '天相', type: 'major', scope: 'origin', brightness: '庙' },
            { name: '天马', type: 'tianma', scope: 'origin', brightness: '' },
          ],
          // 辅星(含六吉六煞)
          minorStars: [],
          // 杂耀
          adjectiveStars: [
            { name: '月解', type: 'helper', scope: 'origin' },
            { name: '三台', type: 'adjective', scope: 'origin' },
            { name: '天寿', type: 'adjective', scope: 'origin' },
            { name: '天巫', type: 'adjective', scope: 'origin' },
            { name: '天厨', type: 'adjective', scope: 'origin' },
            { name: '阴煞', type: 'adjective', scope: 'origin' },
            { name: '天哭', type: 'adjective', scope: 'origin' },
          ],
          // 长生12神
          changsheng12: '绝',
          // 博士12神
          boshi12: '蜚廉',
          // 流年将前12神
          jiangqian12: '岁驿',
          // 流年岁前12神
          suiqian12: '吊客',
          // 大限
          decadal: { range: [44, 53], heavenlyStem: '戊' },
          // 小限
          ages: [9, 21, 33, 45, 57, 69, 81],
        },
        // 其余11条数据因为篇幅关系予以隐藏
      ],
    }
✍️ 返回数据定义
export type Star = {
  /** 星耀名字 */
  name: string;
  /** 星耀类型(主星 | 吉星 | 煞星 | 杂耀 | 桃花星 | 解神 | 禄存 | 天马) */
  type: StarType;
  /** 作用范围(本命盘 | 大限盘 | 流年盘) */
  scope: Scope;
  /** 星耀亮度 */
  brightness?: StarBrightness;
  /** 四化 */
  mutagen?: Mutagen;
};

export type Decadal = {
  /** 大限起止年龄 [起始年龄, 截止年龄] */
  range: number[];
  /** 大限天干 */
  heavenlyStem: HeavenlyStem;
  /** 大限地支 */
  earthlyBranch: EarthlyBranch;
};

export type Palace = {
  /** 宫名 */
  name: PalaceName;
  /** 是否身宫 */
  isBodyPalace: boolean;
  /** 是否来因宫 */
  isOriginalPalace: boolean;
  /** 宫位天干 */
  heavenlyStem: HeavenlyStem;
  /** 宫位地支 */
  earthlyBranch: EarthlyBranch;
  /** 主星 */
  majorStars: Star[];
  /** 辅星 */
  minorStars: Star[];
  /** 杂耀 */
  adjectiveStars: Star[];
  /** 长生12神 */
  changsheng12: string;
  /** 博士12神 */
  boshi12: string;
  /** 流年将前12神 */
  jiangqian12: string;
  /** 流年岁前12神 */
  suiqian12: string;
  /** 大限 */
  decadal: Decadal;
  /** 小限 */
  ages: number[];
};

export type Astrolabe = {
  /** 阳历日期 */
  solarDate: string;
  /** 农历日期 */
  lunarDate: string;
  /** 四柱 */
  chineseDate: string;
  /** 时辰 */
  time: BirthTime;
  /** 时辰对应的时间段 */
  timeRange: TimeRange;
  /** 星座 */
  sign: string;
  /** 生肖 */
  zodiac: string;
  /** 命宫地支 */
  earthlyBranchOfSoulPalace: EarthlyBranch;
  /** 身宫地支 */
  earthlyBranchOfBodyPalace: EarthlyBranch;
  /** 命主 */
  soul: string;
  /** 身主 */
  body: string;
  /** 五行局 */
  fiveElementsClass: FiveElementsClassName;
  /** 十二宫数据 */
  palaces: Palace[];
};

✨ 获取流耀

❓ 调用方法
  • ES6 Module

    import { star } from '@sylarlong/astro';
    
    // 通过天干地支获取流耀
    const horoscopeStars = star.getHoroscopeStar('庚', '辰', 'decadal');
  • CommonJS

    var astroObj = require('@sylarlong/astro');
    
    // 通过天干地支获取流耀
    var horoscopeStars = astroObj.star.getHoroscopeStar('庚', '辰', 'decadal');
✍️ 方法定义
  • getHoroscopeStar

    /**
     * 获取流耀
     *
     * 魁钺昌曲禄羊陀马鸾喜
     *
     * @param heavenlyStem 天干
     * @param earthlyBranch 地支
     * @param scope 限定是大限还是流年的流耀,其中大限流耀会在星耀前面加上`运`,流年流耀会在星耀前面加上`流`
     */
    type getHoroscopeStar = (
      heavenlyStem: HeavenlyStem,
      earthlyBranch: EarthlyBranch,
      scope: 'decadal' | 'yearly',
    ) => Star[][];
📑 返回数据
[
  [{ name: '运马', type: 'tianma', scope: 'decadal' }],
  [{ name: '运曲', type: 'soft', scope: 'decadal' }],
  [],
  [{ name: '运喜', type: 'flower', scope: 'decadal' }],
  [],
  [
    { name: '运钺', type: 'soft', scope: 'decadal' },
    { name: '运陀', type: 'tough', scope: 'decadal' },
  ],
  [{ name: '运禄', type: 'lucun', scope: 'decadal' }],
  [{ name: '运羊', type: 'tough', scope: 'decadal' }],
  [],
  [
    { name: '运昌', type: 'soft', scope: 'decadal' },
    { name: '运鸾', type: 'flower', scope: 'decadal' },
  ],
  [],
  [{ name: '运魁', type: 'soft', scope: 'decadal' }],
];

☕ 总结

如果您觉得本程序对您有用的话,可以给我带杯咖啡吗?👍 Paypal Me

以上数据可以生成如下星盘,其中palaces数据用于填充12宫,其他数据用于填充中宫。

demo

📜 版权(LICENSE)

MIT License

Copyright © 2023 Sylar Long

请合理使用本开源代码,禁止用于非法目的。