@aharris02/bazi-calculator-by-alvamind
Version:
A fork of alvamind's comprehensive Bazi calculator for personal use
317 lines (314 loc) • 11.7 kB
TypeScript
type ElementType = 'WOOD' | 'FIRE' | 'EARTH' | 'METAL' | 'WATER';
type GenderType = 'male' | 'female';
type YinYangType = 'Yang' | 'Yin';
type EarthlyBranchName = 'Rat' | 'Ox' | 'Tiger' | 'Rabbit' | 'Dragon' | 'Snake' | 'Horse' | 'Goat' | 'Monkey' | 'Rooster' | 'Dog' | 'Pig';
interface InternalHeavenlyStem {
name: string;
value: number;
character: string;
spelling: string;
elementType: ElementType;
yinYang: YinYangType;
}
interface InternalHiddenStemInfo extends InternalHeavenlyStem {
tenGod?: TenGodInfo | null;
}
interface InternalEarthlyBranch {
name: EarthlyBranchName;
value: number;
character: string;
spelling: string;
elementType: ElementType;
animal: string;
hiddenStems: InternalHiddenStemInfo[];
yinYang: YinYangType;
}
interface InternalGanZhi {
name: string;
elementName: string;
elementValue: number;
}
interface InternalPillarData {
chinese: string;
heavenlyStem: InternalHeavenlyStem;
earthlyBranch: InternalEarthlyBranch;
ganZhi: InternalGanZhi;
lifeCycle?: string;
heavenlyStemTenGod?: TenGodInfo | null;
dayMasterTenGod?: TenGodInfo | null;
}
interface InternalYearPillarData extends InternalPillarData {
year: number;
}
interface InternalMonthPillarData extends InternalPillarData {
month: number;
}
interface InternalDayPillarData extends InternalPillarData {
day: number;
}
interface InternalTimeOfDay {
hour: number;
minute: number;
}
interface InternalHourPillarData extends InternalPillarData {
hour: InternalTimeOfDay | null;
}
interface InternalFourPillarsData {
year: InternalYearPillarData;
month: InternalMonthPillarData;
day: InternalDayPillarData;
hour: InternalHourPillarData | null;
}
interface Pillar {
chinese: string;
element: string;
animal: string;
branch: {
element: string;
};
}
interface Pillars {
year: Pillar;
month: Pillar;
day: Pillar;
time: Pillar | null;
}
interface LuckPillarData {
number: number;
heavenlyStem: InternalHeavenlyStem;
earthlyBranch: InternalEarthlyBranch;
ganZhi: InternalGanZhi;
yearStart: number | null;
yearEnd: number | null;
startTime: Date | null;
ageStart: number | null;
heavenlyStemTenGod?: TenGodInfo | null;
}
interface LuckPillarsResult {
pillars: LuckPillarData[];
incrementRule: 1 | -1;
isTimingKnown: boolean;
startAgeYears: number | null;
startAgeMonths: number | null;
startAgeDays: number | null;
}
interface DayMasterAnalysis {
stem: string;
nature: YinYangType;
element: ElementType;
}
interface FiveFactors {
WOOD: number;
FIRE: number;
EARTH: number;
METAL: number;
WATER: number;
}
interface EightMansions {
group: 'West' | 'East';
lucky: {
wealth: string;
health: string;
romance: string;
career: string;
};
unlucky: {
obstacles: string;
quarrels: string;
setbacks: string;
totalLoss: string;
};
}
type DayMasterStrength = "Strong" | "Weak" | "Balanced";
interface DayMasterStrengthResult {
strength: DayMasterStrength;
score: number;
notes?: string[];
}
interface FavorableElementsResult {
primary: ElementType[];
secondary?: ElementType[];
unfavorable?: ElementType[];
notes?: string[];
}
interface BasicAnalysis {
lifeGua: number;
dayMaster: DayMasterAnalysis;
nobleman: string[];
intelligence: string;
skyHorse: string;
peachBlossom: string;
fiveFactors: FiveFactors | null;
eightMansions: EightMansions;
dayMasterStrength?: DayMasterStrengthResult | null;
favorableElements?: FavorableElementsResult | null;
}
interface CompleteAnalysis {
mainPillars: Pillars;
basicAnalysis: BasicAnalysis | null;
detailedPillars?: InternalFourPillarsData | null;
luckPillars?: LuckPillarsResult | null;
interactions?: InteractionDetail[];
}
type InteractionType = "StemCombination" | "StemClash" | "Branch6Combo" | "TrinityCombo" | "DirectionalCombo" | "BranchClash" | "BranchHarm" | "BranchPunishment" | "BranchDestruction";
type PillarName = 'Year' | 'Month' | 'Day' | 'Hour';
type InteractionLocation = 'Natal' | 'Natal-Luck' | 'Natal-Annual' | 'Luck-Annual';
type ParticipantSource = 'Natal' | 'Luck' | 'Annual' | 'Monthly' | 'Daily';
interface InteractionParticipant {
pillar: PillarName;
source: ParticipantSource;
elementChar: string;
elementType: 'Stem' | 'Branch';
}
interface InteractionDetail {
type: InteractionType;
participants: InteractionParticipant[];
potentialTransformation?: ElementType | null;
location: InteractionLocation;
description?: string;
involvesFavorableElement?: boolean;
involvesUnfavorableElement?: boolean;
affectedPillarStemsTenGods?: (TenGodInfo | null)[];
consequenceNotes?: string[];
}
type TenGodName = "Bi Jian" | "Jie Cai" | "Shi Shen" | "Shang Guan" | "Pian Cai" | "Zheng Cai" | "Qi Sha" | "Zheng Guan" | "Pian Yin" | "Zheng Yin";
interface TenGodInfo {
name: TenGodName;
chinese: string;
relationship: 'Resource' | 'Companion' | 'Output' | 'Wealth' | 'Control';
}
interface GeneralDailyPillarInfo {
stemChar: string;
branchChar: string;
stemFullName: string;
branchFullName: string;
stemElement: ElementType;
branchElement: ElementType;
stemYinYang: YinYangType;
branchYinYang: YinYangType;
naYin: string;
tenGods?: {
vsMonthStem?: TenGodInfo | null;
vsYearStem?: TenGodInfo | null;
};
}
interface GeneralDailyInteractionSummary {
description: string;
type: InteractionType;
participants: string[];
}
interface GeneralDailyAnalysisOutput {
type: 'general';
date: string;
dayPillar: GeneralDailyPillarInfo;
elementalDynamicDescription: string;
annualPillarContext?: GeneralDailyPillarInfo | null;
monthlyPillarContext?: GeneralDailyPillarInfo | null;
keyInteractions: GeneralDailyInteractionSummary[];
dayBranchAnimal: string;
specialNotes?: string[];
}
interface PersonalizedDailyAnalysisOutput {
type: 'personalized';
date: string;
dayPillar: GeneralDailyPillarInfo;
elementalDynamicDescription: string;
currentLuckPillarSnap?: GeneralDailyPillarInfo & {
tenGodVsNatalDayMaster?: TenGodInfo | null;
} | null;
interactions: InteractionDetail[];
}
interface DateAnalysisOptions {
type: 'general' | 'personalized';
}
declare class BaziCalculator {
private birthDateTime;
private pillarCalculator;
private analysisCalculator;
private internalPillars;
private lifeCycleCalculated;
private tenGodsCalculated;
private luckPillarsResult;
private interactionsResult;
private dayMasterStrengthResult;
private favorableElementsResult;
private originalYear;
private timezone;
private isTimeKnown;
private gender;
constructor(birthDateTime: Date, // Expect timezone-aware Date object
genderInput?: string, // Accept string, default to 'male'
timezoneInput?: string, isTimeKnownInput?: boolean);
private getInternalPillars;
private mapToPublicPillar;
private toGeneralDailyPillarInfo;
calculatePillars(): Pillars | null;
calculateLuckPillars(): LuckPillarsResult | null;
/**
* Calculates basic analysis details including Life Gua, Day Master, Nobleman, etc.,
* Day Master Strength, and Favorable Elements. Caches Strength and Favorable Elements results.
* @returns BasicAnalysis object or null if calculation fails.
*/
calculateBasicAnalysis(): BasicAnalysis | null;
/**
* Calculates interactions within the Natal Chart. Caches the result.
* @returns An array of detected InteractionDetail objects, or null if calculation fails.
*/
calculateInteractions(): InteractionDetail[] | null;
getCompleteAnalysis(): CompleteAnalysis | null;
/**
* Gets the Bazi Pillar (Stem & Branch) for a specific Gregorian year.
* Note: This calculates the pillar based on the lunar year number associated with the start of the Gregorian year.
* @param year The year (e.g., 2024).
* @returns The InternalPillarData for the year or null on error.
*/
getAnnualPillar(year: number): InternalPillarData | null;
/**
* Gets the full Four Pillars for a specific target date and time.
* Useful for analyzing daily or monthly charts.
* @param targetDate The specific date/time as a Date object.
* @param targetTimezone The timezone relevant for the targetDate.
* @returns The full InternalFourPillarsData for the target date or null on error.
*/
getPillarsForDate(targetDate: Date, targetTimezone: string): InternalFourPillarsData | null;
/**
* Finds the Luck Pillar active for a given date.
* @param targetDate The date for which to find the active Luck Pillar.
* @returns The active Luck Pillar data or null if not applicable/calculable.
*/
getCurrentLuckPillar(targetDate: Date): LuckPillarData | null;
/**
* Performs analysis for a specific target date, considering interactions
* between Natal, current Luck Pillar, and the target date's pillars (Year, Month, Day).
* @param targetDate The date/time to analyze.
* @param targetTimezone The timezone for the target date.
* @returns An object containing the target date's pillars and detected interactions, or null.
*/
getTimedAnalysis(targetDate: Date, targetTimezone: string): {
targetPillars: InternalFourPillarsData | null;
currentLuckPillar: LuckPillarData | null;
interactions: InteractionDetail[] | null;
} | null;
/**
* Provides Bazi analysis for a single target date.
* Can be 'general' (day's chart in its own context) or 'personalized' (natal vs. timed).
*
* @param targetDate The date to analyze.
* @param targetTimezone The timezone for the target date.
* @param options Specifies 'general' or 'personalized' analysis.
* @returns GeneralDailyAnalysisOutput or PersonalizedDailyAnalysisOutput, or null on error.
*/
getAnalysisForDate(targetDate: Date, targetTimezone: string, options: DateAnalysisOptions): GeneralDailyAnalysisOutput | PersonalizedDailyAnalysisOutput | null;
/**
* Provides Bazi analysis for a range of dates.
*
* @param startDate The start date of the range.
* @param endDate The end date of the range.
* @param targetTimezone The timezone for the analysis.
* @param options Specifies 'general' or 'personalized' analysis.
* @returns An array of daily analysis outputs, or null on error.
*/
getAnalysisForDateRange(startDate: Date, endDate: Date, targetTimezone: string, options: DateAnalysisOptions): (GeneralDailyAnalysisOutput | PersonalizedDailyAnalysisOutput)[] | null;
toString(): string;
}
export { type BasicAnalysis, BaziCalculator, type CompleteAnalysis, type DateAnalysisOptions, type DayMasterAnalysis, type DayMasterStrengthResult, type EightMansions, type ElementType, type FavorableElementsResult, type FiveFactors, type GenderType as Gender, type GeneralDailyAnalysisOutput, type GeneralDailyInteractionSummary, type GeneralDailyPillarInfo, type InteractionDetail, type InteractionLocation, type InteractionParticipant, type InteractionType, type InternalEarthlyBranch, type InternalFourPillarsData, type InternalGanZhi, type InternalHeavenlyStem, type InternalHiddenStemInfo, type InternalPillarData, type LuckPillarData, type LuckPillarsResult, type ParticipantSource, type PersonalizedDailyAnalysisOutput, type Pillars, type TenGodInfo, type TenGodName, type YinYangType };