Skip to content

Commit

Permalink
🪄 flyinstar judgement feature #143
Browse files Browse the repository at this point in the history
  • Loading branch information
SylarLong committed Dec 17, 2023
1 parent f68f374 commit 001db84
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 54 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
- 🛠️ 修复(fix)
- 🧹 琐事(Chore)

## v2.1.0

- 🪄 功能(feature)

🇨🇳

- 宫位飞星判断 #143

🇺🇸

- flyinstar judgement feature #143

## v2.0.8

- 🛠️ 修复(fix)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iztro",
"version": "2.0.8",
"version": "2.1.0",
"description": "轻量级紫微斗数星盘生成库。可以通过出生年月日获取到紫微斗数星盘信息、生肖、星座等信息。A lightweight kit to astrolabe generator of The Purple Star Astrology (Zi Wei Dou Shu). The Purple Star Astrology(Zi Wei Dou Shu) is a Chinese ancient astrology. You're able to get your horoscope and personality from the astrolabe",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
48 changes: 24 additions & 24 deletions src/__tests__/astro/astro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,33 +174,33 @@ describe('Astrolabe', () => {

const decadalSurpalaces = horoscope.surroundPalaces('命宫', 'decadal');

expect(decadalSurpalaces.target).toHaveProperty('name', '夫妻');
expect(decadalSurpalaces.target).toHaveProperty('heavenlyStem', '庚');
expect(decadalSurpalaces.target).toHaveProperty('earthlyBranch', '辰');
expect(decadalSurpalaces.opposite).toHaveProperty('name', '官禄');
expect(decadalSurpalaces.opposite).toHaveProperty('heavenlyStem', '丙');
expect(decadalSurpalaces.opposite).toHaveProperty('earthlyBranch', '戌');
expect(decadalSurpalaces.career).toHaveProperty('name', '福德');
expect(decadalSurpalaces.career).toHaveProperty('heavenlyStem', '甲');
expect(decadalSurpalaces.career).toHaveProperty('earthlyBranch', '申');
expect(decadalSurpalaces.wealth).toHaveProperty('name', '迁移');
expect(decadalSurpalaces.wealth).toHaveProperty('heavenlyStem', '戊');
expect(decadalSurpalaces.wealth).toHaveProperty('earthlyBranch', '子');
expect(decadalSurpalaces?.target).toHaveProperty('name', '夫妻');
expect(decadalSurpalaces?.target).toHaveProperty('heavenlyStem', '庚');
expect(decadalSurpalaces?.target).toHaveProperty('earthlyBranch', '辰');
expect(decadalSurpalaces?.opposite).toHaveProperty('name', '官禄');
expect(decadalSurpalaces?.opposite).toHaveProperty('heavenlyStem', '丙');
expect(decadalSurpalaces?.opposite).toHaveProperty('earthlyBranch', '戌');
expect(decadalSurpalaces?.career).toHaveProperty('name', '福德');
expect(decadalSurpalaces?.career).toHaveProperty('heavenlyStem', '甲');
expect(decadalSurpalaces?.career).toHaveProperty('earthlyBranch', '申');
expect(decadalSurpalaces?.wealth).toHaveProperty('name', '迁移');
expect(decadalSurpalaces?.wealth).toHaveProperty('heavenlyStem', '戊');
expect(decadalSurpalaces?.wealth).toHaveProperty('earthlyBranch', '子');

const originalSurpalaces = horoscope.surroundPalaces('夫妻', 'origin');

expect(originalSurpalaces.target).toHaveProperty('name', '夫妻');
expect(originalSurpalaces.target).toHaveProperty('heavenlyStem', '庚');
expect(originalSurpalaces.target).toHaveProperty('earthlyBranch', '辰');
expect(originalSurpalaces.opposite).toHaveProperty('name', '官禄');
expect(originalSurpalaces.opposite).toHaveProperty('heavenlyStem', '丙');
expect(originalSurpalaces.opposite).toHaveProperty('earthlyBranch', '戌');
expect(originalSurpalaces.career).toHaveProperty('name', '福德');
expect(originalSurpalaces.career).toHaveProperty('heavenlyStem', '甲');
expect(originalSurpalaces.career).toHaveProperty('earthlyBranch', '申');
expect(originalSurpalaces.wealth).toHaveProperty('name', '迁移');
expect(originalSurpalaces.wealth).toHaveProperty('heavenlyStem', '戊');
expect(originalSurpalaces.wealth).toHaveProperty('earthlyBranch', '子');
expect(originalSurpalaces?.target).toHaveProperty('name', '夫妻');
expect(originalSurpalaces?.target).toHaveProperty('heavenlyStem', '庚');
expect(originalSurpalaces?.target).toHaveProperty('earthlyBranch', '辰');
expect(originalSurpalaces?.opposite).toHaveProperty('name', '官禄');
expect(originalSurpalaces?.opposite).toHaveProperty('heavenlyStem', '丙');
expect(originalSurpalaces?.opposite).toHaveProperty('earthlyBranch', '戌');
expect(originalSurpalaces?.career).toHaveProperty('name', '福德');
expect(originalSurpalaces?.career).toHaveProperty('heavenlyStem', '甲');
expect(originalSurpalaces?.career).toHaveProperty('earthlyBranch', '申');
expect(originalSurpalaces?.wealth).toHaveProperty('name', '迁移');
expect(originalSurpalaces?.wealth).toHaveProperty('heavenlyStem', '戊');
expect(originalSurpalaces?.wealth).toHaveProperty('earthlyBranch', '子');

const yearlyPalace = horoscope.palace('命宫', 'yearly');

Expand Down
30 changes: 30 additions & 0 deletions src/__tests__/astro/palace.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { astro } from '../..';
import { getFiveElementsClass, getSoulAndBody, getPalaceNames, getHoroscope } from '../../astro';
import { FiveElementsClass } from '../../data';
import { t } from '../../i18n';
Expand Down Expand Up @@ -101,4 +102,33 @@ describe('astro/palace', () => {
[1, 13, 25, 37, 49, 61, 73],
]);
});

test('fliesTo() & notFlyTo() & fliesOneOfTo()', () => {
const astrolabe = astro.bySolar('2017-12-4', 12, 'male');

expect(astrolabe.palace('命宫')?.fliesTo('兄弟', '忌')).toBeTruthy();
expect(astrolabe.palace('命宫')?.notFlyTo('兄弟', '科')).toBeTruthy();
expect(astrolabe.palace('田宅')?.fliesTo('福德', ['禄', '科'])).toBeTruthy();
expect(astrolabe.palace('田宅')?.notFlyTo('福德', ['禄', '科'])).toBeFalsy();
expect(astrolabe.palace('兄弟')?.fliesTo('夫妻', ['权', '科'])).toBeFalsy();
expect(astrolabe.palace('兄弟')?.fliesOneOfTo('夫妻', ['权', '科'])).toBeTruthy();
expect(astrolabe.palace('兄弟')?.fliesOneOfTo('夫妻', ['权', '禄'])).toBeFalsy();
expect(astrolabe.palace('兄弟')?.notFlyTo('夫妻', ['权', '科'])).toBeFalsy();
expect(astrolabe.palace('仆役')?.selfMutaged('科')).toBeTruthy();
expect(astrolabe.palace('仆役')?.selfMutaged(['科', '权'])).toBeFalsy();
expect(astrolabe.palace('仆役')?.selfMutagedOneOf(['科', '权'])).toBeTruthy();
expect(astrolabe.palace('仆役')?.selfMutagedOneOf()).toBeTruthy();
expect(astrolabe.palace('仆役')?.selfMutaged('权')).toBeFalsy();
expect(astrolabe.palace('仆役')?.notSelfMutaged()).toBeFalsy();
expect(astrolabe.palace('仆役')?.notSelfMutaged('权')).toBeTruthy();
expect(astrolabe.palace('仆役')?.notSelfMutaged(['权', '科'])).toBeFalsy();

const palaces = astrolabe.palace('命宫')?.mutagedPlaces() ?? [];

expect(palaces).toHaveLength(4);
expect(palaces[0]).toHaveProperty('name', '命宫');
expect(palaces[1]).toHaveProperty('name', '迁移');
expect(palaces[2]).toHaveProperty('name', '仆役');
expect(palaces[3]).toHaveProperty('name', '兄弟');
});
});
6 changes: 3 additions & 3 deletions src/astro/FunctionalAstrolabe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getPalace, getSurroundedPalaces } from './analyzer';
import { IFunctionalPalace } from './FunctionalPalace';
import { IFunctionalSurpalaces } from './FunctionalSurpalaces';
import { getPalaceNames } from './palace';
import FunctionalHoroscope from './FunctionalHoroscope';
import FunctionalHoroscope, { IFunctionalHoroscope } from './FunctionalHoroscope';

/**
* 获取运限数据
Expand All @@ -28,7 +28,7 @@ const _getHoroscopeBySolarDate = (
$: FunctionalAstrolabe,
targetDate: string | Date = new Date(),
timeIndex?: number,
): FunctionalHoroscope => {
): IFunctionalHoroscope => {
const _birthday = solar2lunar($.solarDate);
const _date = solar2lunar(targetDate);
const convertTimeIndex = timeToIndex(dayjs(targetDate).hour());
Expand Down Expand Up @@ -171,7 +171,7 @@ export interface IFunctionalAstrolabe extends Astrolabe {
* @param timeIndex 时辰索引【可选】,默认会自动读取当前时间的时辰
* @returns 运限数据
*/
horoscope: (date?: string | Date, timeIndex?: number) => Horoscope;
horoscope: (date?: string | Date, timeIndex?: number) => IFunctionalHoroscope;

/**
* 通过星耀名称获取到当前星耀的对象实例
Expand Down
19 changes: 10 additions & 9 deletions src/astro/FunctionalHoroscope.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Horoscope, Scope } from '../data/types';
import { Mutagen, MutagenKey, PalaceName, StarKey, StarName, kot } from '../i18n';
import { IFunctionalAstrolabe } from './FunctionalAstrolabe';
import { FunctionalSurpalaces } from './FunctionalSurpalaces';
import FunctionalPalace from './FunctionalPalace';
import { IFunctionalSurpalaces } from './FunctionalSurpalaces';
import { IFunctionalPalace } from './FunctionalPalace';
import { mergeStars } from '../utils';
import { MUTAGEN } from '../data';

const _getHoroscopePalaceIndex = ($: FunctionalHoroscope, scope: Scope, palaceName: PalaceName) => {
const _getHoroscopePalaceIndex = ($: IFunctionalHoroscope, scope: Scope, palaceName: PalaceName) => {
let palaceIndex = -1;

if (scope === 'origin') {
Expand All @@ -27,14 +27,15 @@ const _getHoroscopePalaceIndex = ($: FunctionalHoroscope, scope: Scope, palaceNa
};

export interface IFunctionalHoroscope extends Horoscope {
astrolabe: IFunctionalAstrolabe;
/**
* 获取小限宫位
*
* @version v1.3.0
*
* @returns {FunctionalPalace | undefined} 小限宫位
* @returns {IFunctionalPalace | undefined} 小限宫位
*/
agePalace: () => FunctionalPalace | undefined;
agePalace: () => IFunctionalPalace | undefined;

/**
* 获取运限宫位
Expand All @@ -43,9 +44,9 @@ export interface IFunctionalHoroscope extends Horoscope {
*
* @param palaceName 宫位名称
* @param scope 指定获取哪个运限的宫位
* @returns {FunctionalPalace | undefined} 指定宫位
* @returns {IFunctionalPalace | undefined} 指定宫位
*/
palace: (palaceName: PalaceName, scope: Scope) => FunctionalPalace | undefined;
palace: (palaceName: PalaceName, scope: Scope) => IFunctionalPalace | undefined;

/**
* 获取运限指定宫位的三方四正宫位
Expand All @@ -54,9 +55,9 @@ export interface IFunctionalHoroscope extends Horoscope {
*
* @param palaceName 宫位名称
* @param scope 指定获取哪个运限的宫位
* @returns {FunctionalSurpalaces | undefined} 指定宫位的三方四正
* @returns {IFunctionalSurpalaces | undefined} 指定宫位的三方四正
*/
surroundPalaces: (palaceName: PalaceName, scope: Scope) => FunctionalSurpalaces | undefined;
surroundPalaces: (palaceName: PalaceName, scope: Scope) => IFunctionalSurpalaces | undefined;

/**
* 判断在指定运限的宫位内是否包含流耀,需要全部包含才返回true
Expand Down
Loading

0 comments on commit 001db84

Please sign in to comment.