星盤
前言
紫微斗數星盤又叫紫微斗數命盤,是由 十二個宮位 和一個 中宮 構成,宮位的 地支 是固定的,並且是由 寅 開始,而不是由 子 開始。這是因為農曆的正月是寅月,這就是所謂的 正月建寅。在 iztro 裏面,寅宮 的索引是 0,卯宮 的索引是 1,如此按照順時針的方向排列。如下面表格所示:
巳 3 | 午 4 | 未 5 | 申 6 |
辰 2 | 中宮 | 酉 7 | |
卯 1 | 戌 8 | ||
寅 0 | 丑 11 | 子 10 | 亥 9 |
中宮 通常可以用來展示任何你想展示的信息,一般不會對整個星盤產生影響。周圍的 十二宮 用於存放星曜,四化,運限,宮位名稱等信息。關於 宮位 的詳細信息,可以進入 紫微斗數宮位 查看詳細介紹,本頁面主要關注星盤的信息。紫微斗數星盤是由宮位和星曜組成的,如果你還沒有建立起它們的概念,我們強烈推薦你進入 紫微斗數基礎 開始學習有趣的紫微斗數知識。
在安裝好 iztro 依賴以後你可以用如下代碼將 星盤(astro) 對象引入你的代碼。如果你還不知道如何安裝 iztro,請點擊 傳送門 跳轉到相關說明文檔。
astro 的靜態方法
要使用該對象的靜態方法,請先將該對象 import 到你的代碼裏
import { astro } from "iztro";排盤配置與輸入校驗 ^2.6.2
bySolar、byLunar 和 withOptions 回傳的星盤保存產生時的配置與語言。後續修改全局預設配置或建立其他語言的星盤,不會改變既有星盤的運限和四化分析結果。
withOptions 的 type 可省略,預設為陽曆;config 僅覆蓋當前星盤。排盤及日期輔助方法省略 language 時預設為 zh-CN,指定語言不會修改其他呼叫的語言。支援 zh-CN、zh-TW、en-US、ja-JP、ko-KR、vi-VN。
日期年份範圍為 1~9999,必須是實際存在的陽曆或農曆日期。字串支援連字號、斜線或點號分隔,可附加 HH:mm 或 HH:mm:ss;歷史陽曆日期沿用底層曆法的儒略曆/格里曆切換規則。時辰必須為 0~12 的整數;未知性別、語言、日期類型或星盤類型,以及非布林的閏月選項會拋出錯誤。農曆日期按實際月份天數校驗,非閏月時仍忽略 isLeapMonth: true。
配置作用範圍、getConfig() 的獨立副本及 resetConfig() 詳見配置和插件。
astrolabeBySolarDate deprecated
本方法自 v2.0.5 起已棄用,請改用 bySolar,參數與返回值均不變。
bySolar ^2.0.5
用途
通過陽曆獲取星盤信息
定義
tsexport type bySolar = ( solarDateStr: string, timeIndex: number, gender: GenderName, fixLeap: boolean = true, language: Language = "zh-CN" ) => FunctionalAstrolabe;參數
參數 類型 是否必填 默認值 說明 solarDateStr stringtrue- 陽曆日期【YYYY-M-D】 timeIndex numbertrue- 出生時辰序號【0~12】,對應從早子時(0)一直到晚子時(12)的序號 gender GenderNametrue- 性別【男/女】 fixLeap booleanfalsetrue是否調整閏月,為 true閏月的前半個月算上個月,後半個月算下個月language Languagefalsezh-CN返回資料使用指定語言。目前支援 zh-CN、zh-TW、en-US、ko-KR、ja-JP和vi-VN。返回值
示例
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN");
astrolabeByLunarDate deprecated
本方法自 v2.0.5 起已棄用,請改用 byLunar,參數與返回值均不變。
byLunar ^2.0.5
用途
通過農曆日期獲取星盤信息。我們強烈建議你優先使用
bySolar方法,因為該方法也是將農曆日期轉化為陽曆以後調用bySolar獲得結果的。定義
tsexport type byLunar = ( lunarDateStr: string, timeIndex: number, gender: GenderName, isLeapMonth: boolean = false, fixLeap: boolean = true, language?: Language ) => FunctionalAstrolabe;參數
參數 類型 是否必填 默認值 說明 lunarDateStr stringtrue- 農曆日期【YYYY-M-D】,例如 2000年七月十七則傳入2000-7-17timeIndex numbertrue- 出生時辰序號【0~12】,對應從早子時(0)一直到晚子時(12)的序號 gender GenderNametrue- 性別【男/女】 isLeapMonth booleanfalsefalse是否閏月,當實際月份沒有閏月時該參數不生效 fixLeap booleanfalsetrue是否調整閏月,為 true閏月的前半個月算上個月,後半個月算下個月language Languagefalsezh-CN返回資料使用指定語言。目前支援 zh-CN、zh-TW、en-US、ko-KR、ja-JP和vi-VN。返回值
示例
tsimport { astro } from "iztro"; const astrolabe = astro.byLunar("2000-8-16", 2, "女", false, true, "zh-CN");
withOptions ^2.4.1
用途
獲取星盤資訊。其實它內部實作是呼叫了
bySolar和byLunar方法,只是為了方便大家呼叫加了一個殼。定義
tstype Option = { type?: 'solar' | 'lunar'; dateStr: string; timeIndex: number; gender: GenderName; isLeapMonth?: boolean; fixLeap?: boolean; language?: Language; config?: Config; astroType?: AstroType; }; export type withOptions = ( option: Option ) => FunctionalAstrolabe;參數
參數 類型 是否必填 預設值 說明 type solar|lunarfalsesolar日期類型 dateStr stringtrue- 出生日期,格式為 YYYY-M-D timeIndex numbertrue- 出生時辰序號【0~12】,對應從早子時(0)一直到晚子時(12)的序號 gender GenderNametrue- 性別【男/女】 isLeapMonth booleanfalsefalse是否閏月,當實際月份沒有閏月時該參數不生效 fixLeap booleanfalsetrue是否調整閏月,為 true閏月的前半個月算上個月,後半個月算下個月language Languagefalsezh-CN返回資料使用指定語言。目前支援 zh-CN、zh-TW、en-US、ko-KR、ja-JP和vi-VN。config Configfalse- 僅覆蓋當前星盤的亮度、四化及時間分界配置(^2.6.2) astroType ^2.5.0 AstroTypefalseheaven星盤類型;僅在 config.algorithm為zhongzhou時用於選擇天盤、地盤或人盤傳回值
示例
tsimport { astro } from "iztro"; const astrolabe = astro.withOptions({ type: 'solar', dateStr: '1999-12-29', timeIndex: 2, gender: 'female', isLeapMonth: false, fixLeap: true, language: 'zh-CN', config: { algorithm: 'zhongzhou' }, astroType: 'earth' })提示
astroType可取heaven、earth或human。預設的heaven為天盤;earth以身宮為命宮,human以福德宮為命宮。詳見AstroType。
getMajorStarBySolarDate ^1.2.1
用途
通過陽曆獲取命宮主星
定義
tstype getMajorStarBySolarDate = ( solarDateStr: string, timeIndex: number, fixLeap: boolean = true, language?: Language, ) => string;參數
參數 類型 是否必填 默認值 說明 solarDateStr stringtrue- 陽曆日期【YYYY-M-D】 timeIndex numbertrue- 出生時辰序號【0~12】,對應從早子時(0)一直到晚子時(12)的序號 fixLeap booleanfalsetrue是否調整閏月,為 true閏月的前半個月算上個月,後半個月算下個月language Languagefalsezh-CN返回資料使用指定語言。目前支援 zh-CN、zh-TW、en-US、ko-KR、ja-JP和vi-VN。示例
tsimport { astro } from 'isztro'; const result = getMajorStarBySolarDate('2023-4-7', 0);
getMajorStarByLunarDate ^1.2.1
用途
通過農曆獲取命宮主星
定義
tstype getMajorStarByLunarDate = ( lunarDateStr: string, timeIndex: number, isLeapMonth: boolean = false, fixLeap: boolean = true, language?: Language, ) =>參數
參數 類型 是否必填 默認值 說明 lunarDateStr stringtrue- 農曆日期【YYYY-M-D】,例如 2000年七月十七則傳入2000-7-17timeIndex numbertrue- 出生時辰序號【0~12】,對應從早子時(0)一直到晚子時(12)的序號 isLeapMonth booleanfalsefalse是否閏月,當實際月份沒有閏月時該參數不生效 fixLeap booleanfalsetrue是否調整閏月,為 true閏月的前半個月算上個月,後半個月算下個月language Languagefalsezh-CN返回資料使用指定語言。目前支援 zh-CN、zh-TW、en-US、ko-KR、ja-JP和vi-VN。示例
tsimport { astro } from 'isztro'; const result = getMajorStarByLunarDate('2023-2-17', 0, true, false);
getSignBySolarDate ^1.2.1
用途
通過陽曆獲取星座
定義
tstype getSignBySolarDate = ( solarDateStr: string, language?: Language ) => string;參數
參數 類型 是否必填 默認值 說明 solarDateStr stringtrue- 陽曆日期【YYYY-M-D】 language Languagefalsezh-CN返回資料使用指定語言。目前支援 zh-CN、zh-TW、en-US、ko-KR、ja-JP和vi-VN。示例
tsimport { astro } from 'isztro'; const result = getSignBySolarDate('2023-9-5');
getSignByLunarDate ^1.2.1
用途
通過農曆獲取星座
定義
tstype getSignByLunarDate = ( lunarDateStr: string, isLeapMonth?: boolean, language?: Language ) => string;參數
參數 類型 是否必填 默認值 說明 lunarDateStr stringtrue- 農曆日期【YYYY-M-D】,例如 2000年七月十七則傳入2000-7-17isLeapMonth booleanfalsefalse是否閏月,當實際月份沒有閏月時該參數不生效 language Languagefalsezh-CN返回資料使用指定語言。目前支援 zh-CN、zh-TW、en-US、ko-KR、ja-JP和vi-VN。示例
tsimport { astro } from 'isztro'; const result = getSignByLunarDate('2023-7-21');
getZodiacBySolarDate ^1.2.1
用途
通過公歷獲取十二生肖
定義
tstype getZodiacBySolarDate = (solarDateStr: string, language?: Language) => string;參數
參數 類型 是否必填 默認值 說明 solarDateStr stringtrue- 陽曆日期【YYYY-M-D】 language Languagefalsezh-CN返回資料使用指定語言。目前支援 zh-CN、zh-TW、en-US、ko-KR、ja-JP和vi-VN。示例
tsimport { astro } from 'isztro'; const result = getZodiacBySolarDate('2023-2-20');
getZodiacByLunarYear ^1.2.1
用途
通過農曆年份獲取十二生肖
定義
tstype getZodiacByLunarYear = (year: number, language?: Language) => string;參數
參數 類型 是否必填 默認值 說明 year numbertrue- 農曆年份 language Languagefalsezh-CN返回資料使用指定語言。目前支援 zh-CN、zh-TW、en-US、ko-KR、ja-JP和vi-VN。示例
tsimport { astro } from 'isztro'; const result = getZodiacByLunarYear(2023);
功能類定義
開發建議
我們推薦你直接調用 astro 的靜態方法 來獲取數據,而不是手動去創建一個 FunctionalAstrolabe 類的實例。
FunctionalAstrolabe
implements
IFunctionalAstrolabe extends Astrolabe該類所有屬性都是繼承自 Astrolabe,然後在接口內定義了一些方法用於對星盤的分析。bySolar() 和 byLunar() 方法會返回一個該類的實例。
接口定義
tsinterface IFunctionalAstrolabe extends Astrolabe { toJSON: () => Astrolabe; use(plugin: Plugin): void; horoscope: (date?: string | Date, timeIndex?: number) => FunctionalHoroscope; decadalList: () => DecadalHoroscope[]; yearlyList: (indexOrName: number | PalaceName) => YearlyHoroscope[]; monthlyList: (year: number, fixLeap?: boolean) => MonthlyHoroscope[]; palace: (indexOrName: number | PalaceName) => IFunctionalPalace | undefined; surroundedPalaces: (indexOrName: number | PalaceName) => SurroundedPalaces; isSurrounded: ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean; isSurroundedOneOf: ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean; notSurrounded: ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean; hasMutagenInSurroundedPalace: ( indexOrName: number | PalaceName, mutagen: Mutagen ) => boolean; hasMutagenInOppositePalace: ( indexOrName: number | PalaceName, mutagen: Mutagen ) => boolean; }屬性
參考 Astrolabe
方法
toJSON() ^2.6.0
用途
將功能星盤轉換為普通 JSON 對象。返回結果不包含分析方法、插件函數和運行時引用;循環引用會被安全忽略。
定義
tstype toJSON = () => Astrolabe;參數
無
返回值
示例
tsimport { astro } from "iztro"; const astrolabe = astro.bySolar("2000-8-16", 2, "女"); const data = astrolabe.toJSON();
use() ^2.3.0
用途
為目前星盤實例套用一個插件。與
astro.loadPlugin()不同,use()只影響目前實例。定義
tstype use = (plugin: Plugin) => void;參數
參數 類型 是否必填 預設值 說明 plugin Plugintrue- 要套用到目前星盤的插件函數 傳回值
void示例
tsimport { astro, FunctionalAstrolabe } from "iztro"; interface IAstrolabe extends FunctionalAstrolabe { soulPalaceName: () => string; } function soulPalacePlugin(this: IAstrolabe) { this.soulPalaceName = () => this.palace("命宮")?.name ?? ""; } const astrolabe = astro.bySolar<IAstrolabe>("2000-8-16", 2, "女"); astrolabe.use(soulPalacePlugin); const name = astrolabe.soulPalaceName();
horoscope() ^0.2.0
用途
獲取運限數據。如果只是想獲取調用時的運限數據,可以不傳任何參數,該方法會獲取系統當前時間進行計算。
注意
- 當
date為YYYY-M-D格式的字符串而沒有傳timeIndex參數時,會取date當日早子時的時間點作為流時的時間 - 當
date為YYYY-M-D HH格式時間或是一個Date實例而沒有傳timeIndex參數時,會將date裏的小時轉化為時辰作為流時的時間 - 當傳入
timeIndex參數時,會優先使用該參數
- 當
定義
tstype horoscope = (date?: string | Date, timeIndex?: number) => FunctionalHoroscope;參數
參數 類型 是否必填 默認值 說明 date string|Datefalsenew Date()陽曆日期【YYYY-M-D】 timeIndex numberfalse0時辰索引【0~12】 返回值
返回值自
v1.3.4起由Horoscope改為FunctionalHoroscope,使用方式保持向後相容。示例
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); const horoscope = astrolabe.horoscope();
decadalList() ^2.6.0
用途
獲取按起運先後排列的大限列表。數組索引
0表示第一個大限。每一項包含大限所在宮位、起止虛歲、起止年份、干支、四化、流曜和大限十二宮。定義
tstype decadalList = () => DecadalHoroscope[];返回值
示例
tsconst decadals = astrolabe.decadalList(); const firstDecadal = decadals[0];
yearlyList() ^2.6.0
用途
根據大限序號或本命宮位名稱,獲取該大限內的流年列表。每一項包含虛歲、年份、流年干支、四化、流曜和流年十二宮。
定義
tstype yearlyList = ( indexOrName: number | PalaceName ) => YearlyHoroscope[];參數
參數 類型 是否必填 預設值 說明 indexOrName number|PalaceNametrue- 大限序號( 0為第一個大限)或本命宮位名稱返回值
示例
tsconst firstDecadalYearlies = astrolabe.yearlyList(0); const soulPalaceYearlies = astrolabe.yearlyList("命宮");
monthlyList() ^2.6.0
用途
獲取指定年份的流月列表。每一項包含虛歲、年份、月份、流月干支、四化、流曜和流月十二宮。
閏月規則:無閏月時返回 12 項;有閏月且
fixLeap=false時返回 13 項;有閏月且fixLeap=true時將閏月按初一至十五、十六至月底拆分,返回 14 項。定義
tstype monthlyList = ( year: number, fixLeap?: boolean ) => MonthlyHoroscope[];參數
參數 類型 是否必填 預設值 說明 year numbertrue- 流年年份,可直接使用 yearlyList()返回項的yearfixLeap booleanfalsetrue是否將閏月前後半月分開計算 返回值
示例
tsconst year = astrolabe.yearlyList(0)[0].year; const adjusted = astrolabe.monthlyList(year); const unadjusted = astrolabe.monthlyList(year, false);
star() ^1.2.0
用途
通過星曜名稱獲取到當前星曜的對象實例
定義
tstype star = (starName: StarName) => IFunctionalStar;參數
參數 類型 是否必填 默認值 說明 starName StarNametrue- 星曜名稱 返回值
示例
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 獲取 `紫微星` 所在宮位 const star = astrolabe.star("紫微");
palace() ^1.0.0
用途
獲取星盤的指定
宮位定義
tstype palace = ( indexOrName: number | PalaceName ) => IFunctionalPalace | undefined;參數
參數 類型 是否必填 默認值 說明 indexOrName number|PalaceNametrue- 宮位索引或者宮位名稱 返回值
示例
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 獲取 `寅宮` const palace = astrolabe.palace(0); // 獲取 `命宮` const soulPalace = astrolabe.palace("命宮");
surroundedPalaces() ^1.1.0
用途
獲取
三方四正宮位,所謂三方四正就是傳入的目標宮,以及其對宮,財帛位和官祿位,總共四個宮位。宮和位是兩個概念,如果你對宮位和三方四正的概念不清楚,可以點擊 宮位 查看詳細信息。定義
tstype surroundedPalaces = ( indexOrName: number | PalaceName ) => IFunctionalSurpalaces;參數
參數 類型 是否必填 默認值 說明 indexOrName number|PalaceNametrue- 宮位索引或者宮位名稱 返回值
示例
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 獲取 `寅宮` 三方四正 const surroundedPalaces = astrolabe.surroundedPalaces(0); // 獲取 `命宮` 三方四正 const surroundedPalacesOfSoul = astrolabe.surroundedPalaces("命宮");
isSurrounded() ^1.0.0 deprecated
注意
該方法已經在
v1.2.0廢棄,請使用 FunctionalSurpalaces 的 have() 方法代替用途
判斷某一個宮位
三方四正是否包含目標星曜,必須要全部包含才會返回true定義
tstype isSurrounded = ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean;參數
參數 類型 是否必填 默認值 說明 indexOrName number|PalaceNametrue- 宮位索引或者宮位名稱 stars StarName[]true- 星曜名稱數組 返回值
boolean示例
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 判斷 `寅宮` 三方四正是否含有 `天府` 星、`紅鸞` 星和 `祿存` 星 const palace = astrolabe.isSurrounded(0, ["天府", "紅鸞", "祿存"]); // 判斷 `命宮` 三方四正是否含有 `天府` 星、`紅鸞` 星和 `祿存` 星 const soulPalace = astrolabe.isSurrounded("命宮", ["天府", "紅鸞", "祿存"]);
isSurroundedOneOf() ^1.1.0 deprecated
注意
該方法已經在
v1.2.0廢棄,請使用 FunctionalSurpalaces 的 haveOneOf() 方法代替用途
判斷指定宮位
三方四正內是否有傳入星曜的其中一個,只要命中一個就會返回true定義
tstype isSurroundedOneOf = ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean;參數
參數 類型 是否必填 默認值 說明 indexOrName number|PalaceNametrue- 宮位索引或者宮位名稱 stars StarName[]true- 星曜名稱數組 返回值
boolean示例
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 判斷 `寅宮` 三方四正是否含有 `天府` 星、`紅鸞` 星和 `祿存` 星中的壹顆 const palace = astrolabe.isSurroundedOneOf(0, ["天府", "紅鸞", "祿存"]); // 判斷 `命宮` 三方四正是否含有 `天府` 星、`紅鸞` 星和 `祿存` 星中的壹顆 const soulPalace = astrolabe.isSurroundedOneOf("命宮", ["天府", "紅鸞", "祿存"]);
notSurrounded() ^1.1.0 deprecated
注意
該方法已經在
v1.2.0廢棄,請使用 FunctionalSurpalaces 的 notHave() 方法代替用途
判斷指定宮位
三方四正是否不含目標星曜,必須要全部都不在三方四正內才會返回true定義
tstype notSurrounded = ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean;參數
參數 類型 是否必填 默認值 說明 indexOrName number|PalaceNametrue- 宮位索引或者宮位名稱 stars StarName[]true- 星曜名稱數組 返回值
boolean示例
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 判斷 `寅宮` 三方四正是否不含有 `天府` 星、`紅鸞` 星和 `祿存` 星 const palace = astrolabe.notSurrounded(0, ["天府", "紅鸞", "祿存"]); // 判斷 `命宮` 三方四正是否不含有 `天府` 星、`紅鸞` 星和 `祿存` 星 const soulPalace = astrolabe.notSurrounded("命宮", ["天府", "紅鸞", "祿存"]);