diff --git a/CHANGELOG.md b/CHANGELOG.md index b9ed20ea..a006c58f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ - 🛠️ 修复(fix) - 🧹 琐事(Chore) +## v2.0.6 + +- 🪄 功能(feature) + + 🇨🇳 + + - 新增空宫判断 #92 + + 🇺🇸 + + - add empty palace verification #92 + ## v2.0.5 - ✨ 改进(enhancement) diff --git a/README.md b/README.md index 32bd88b6..ce615215 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ - 判断指定运限宫位内是否存在四化 - 判断指定运限三方四正内是否存在某些星耀 - 判断指定运限三方四正内是否存在四化 + - 判断指定宫位是否是空宫 - 其他 diff --git a/package.json b/package.json index df215a37..09ca8bca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iztro", - "version": "2.0.5", + "version": "2.0.6", "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", @@ -14,11 +14,10 @@ "lint": "eslint . --ext .ts", "test": "jest --config jestconfig.json --coverage", "prepare": "yarn build", - "prepublishOnly": "npm test && yarn lint", + "prepublishOnly": "npm test && yarn lint && yarn build:umd", "preversion": "yarn lint", "version": "yarn format && git add -A src", - "postversion": "git push && git push --tags", - "pub": "yarn build:umd && yarn publish" + "postversion": "git push && git push --tags" }, "files": [ "lib/**/*", diff --git a/src/__tests__/astro/astro.test.ts b/src/__tests__/astro/astro.test.ts index 29983296..9767c10d 100644 --- a/src/__tests__/astro/astro.test.ts +++ b/src/__tests__/astro/astro.test.ts @@ -27,6 +27,11 @@ describe('Astrolabe', () => { expect(result).toHaveProperty('body', '文昌'); expect(result).toHaveProperty('fiveElementsClass', '木三局'); + expect(result.palace('父母')?.isEmpty()).toBeTruthy(); + expect(result.palace('父母')?.isEmpty(['陀罗'])).toBeFalsy(); + expect(result.palace('命宫')?.isEmpty()).toBeFalsy(); + expect(result.palace('父母')?.isEmpty(['文昌', '文曲'])).toBeTruthy(); + const horoscope = result.horoscope('2023-8-19 3:12'); expect(horoscope).toHaveProperty('solarDate', '2023-8-19'); diff --git a/src/astro/FunctionalPalace.ts b/src/astro/FunctionalPalace.ts index f24f4849..f0accacc 100644 --- a/src/astro/FunctionalPalace.ts +++ b/src/astro/FunctionalPalace.ts @@ -57,6 +57,20 @@ export interface IFunctionalPalace extends Palace { * @returns true | false */ notHaveMutagen: (mutagen: Mutagen) => boolean; + + /** + * 判断一个宫位是否为空宫(没有主星), + * 有些派别在宫位内有某些星耀的情况下, + * 是不会将该宫位判断为空宫的。 + * 所以加入一个参数来传入星耀。 + * + * @version v2.0.6 + * + * @param excludeStars 星耀名称数组 + * + * @returns {boolean} true | false + */ + isEmpty: (excludeStars?: StarName[]) => boolean; } /** @@ -104,4 +118,15 @@ export default class FunctionalPalace implements IFunctionalPalace { hasOneOf = (stars: StarName[]): boolean => hasOneOfStars(this, stars); hasMutagen = (mutagen: Mutagen): boolean => hasMutagenInPlace(this, mutagen); notHaveMutagen = (mutagen: Mutagen): boolean => notHaveMutagenInPalce(this, mutagen); + isEmpty = (excludeStars?: StarName[]) => { + if (this.majorStars?.filter((star) => star.type === 'major').length) { + return false; + } + + if (excludeStars?.length && this.hasOneOf(excludeStars)) { + return false; + } + + return true; + }; }