Skip to content

Commit

Permalink
🪄 add empty palace verification #92
Browse files Browse the repository at this point in the history
  • Loading branch information
SylarLong committed Nov 10, 2023
1 parent b884c4b commit 2e1def3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 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.0.6

- 🪄 功能(feature)

🇨🇳

- 新增空宫判断 #92

🇺🇸

- add empty palace verification #92

## v2.0.5

- ✨ 改进(enhancement)
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"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",
"unpkg": "dist/iztro.min.js",
"jsdelivr": "dist/iztro.min.js",
"scripts": {
"build": "tsc",
"build": "tsc && yarn build:umd",
"rollup": "rollup -c --bundleConfigAsCjs",
"build:umd": "webpack",
"format": "prettier --write \"src/**/*.ts\"",
Expand All @@ -17,8 +17,7 @@
"prepublishOnly": "npm test && yarn lint",
"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/**/*",
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/astro/astro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
25 changes: 25 additions & 0 deletions src/astro/FunctionalPalace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
};
}

0 comments on commit 2e1def3

Please sign in to comment.