From 2e1def3e452c021560e6671ec6cd8d7f3031a751 Mon Sep 17 00:00:00 2001 From: Sylar Date: Sat, 11 Nov 2023 00:30:43 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=AA=84=20add=20empty=20palace=20verif?= =?UTF-8?q?ication=20#92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 12 ++++++++++++ package.json | 7 +++---- src/__tests__/astro/astro.test.ts | 5 +++++ src/astro/FunctionalPalace.ts | 25 +++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) 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/package.json b/package.json index df215a37..04401c53 100644 --- a/package.json +++ b/package.json @@ -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\"", @@ -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/**/*", 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; + }; } From 9e03376122255e6dcbe711bd8f0ee20cbabbf8fe Mon Sep 17 00:00:00 2001 From: Sylar Date: Sat, 11 Nov 2023 00:31:42 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=83=20update=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 32bd88b6..ce615215 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ - 判断指定运限宫位内是否存在四化 - 判断指定运限三方四正内是否存在某些星耀 - 判断指定运限三方四正内是否存在四化 + - 判断指定宫位是否是空宫 - 其他 From f0181e97e00de0ea7f262922f5ec96d5a7ea3000 Mon Sep 17 00:00:00 2001 From: Sylar Date: Sat, 11 Nov 2023 00:37:09 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A7=B9=20update=20package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 04401c53..d9954f1b 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,13 @@ "unpkg": "dist/iztro.min.js", "jsdelivr": "dist/iztro.min.js", "scripts": { - "build": "tsc && yarn build:umd", + "build": "tsc", "rollup": "rollup -c --bundleConfigAsCjs", "build:umd": "webpack", "format": "prettier --write \"src/**/*.ts\"", "lint": "eslint . --ext .ts", "test": "jest --config jestconfig.json --coverage", - "prepare": "yarn build", + "prepare": "yarn build && yarn build:umd", "prepublishOnly": "npm test && yarn lint", "preversion": "yarn lint", "version": "yarn format && git add -A src", From 259fb5e0cc39f6f5c4dc499ba931db5576d6175a Mon Sep 17 00:00:00 2001 From: Sylar Date: Sat, 11 Nov 2023 00:40:14 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A7=B9=20update=20package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d9954f1b..09ca8bca 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "format": "prettier --write \"src/**/*.ts\"", "lint": "eslint . --ext .ts", "test": "jest --config jestconfig.json --coverage", - "prepare": "yarn build && yarn build:umd", - "prepublishOnly": "npm test && yarn lint", + "prepare": "yarn build", + "prepublishOnly": "npm test && yarn lint && yarn build:umd", "preversion": "yarn lint", "version": "yarn format && git add -A src", "postversion": "git push && git push --tags"