0.2.5 • Published 5 months ago

@lunisolar/plugin-char8ex v0.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@lunisolar/plugin-char8ex

lunisolar.js八字增强插件

lunisolar.js文档请进入lunisolar.js.org

简介

lunisolar.js本身可能过Lunisolar实例的char8属性实现基本的八字查询功能, 但未包括十神和神煞等功能。使用Char8Ex插件后,将会在Lunisolar``实例上添加一个char8ex()方法, 除了包含原char8的功能外,还加入了十神和神煞的查询。

/**
 * @param sex 性别 0:坤造,1: 乾造
 * @return 返回一个Char8Ex实例对象
 */
lunisolar().char8ex(sex: 0 | 1): Char8Ex

注意:加载char8ex插件时,将自动加载takeSound插件(五行纳音插件),所以请不要再重复加载takeSound

快速上手

安装:

# 由于八字增强插件虽要用到五行纳音,所以同时安装五行纳音插件
npm add @lunisolar/plugin-char8ex @lunisolar/plugin-takesound
// 引入lunisolar
import lunisolar from 'lunisolar'
// 引入 theGods 插件
import { char8ex } from '@lunisolar/plugin-char8ex'
// 加载插件 (加载char8ex时,takesound插件也会自动加载)
lunisolar.extend(char8ex)


// ---  使用
// 创建一个Char8Ex实例对象, 该八字为 2023-01-15 12:26出生的男孩
const c8ex =  lunisolar('2023-01-15 12:26').char8ex(1)

console.log(c8ex.toString()) // 乾造: 壬寅 癸丑 癸酉 戊午

// Char8Ex实例可通过year,month,day,hour属性取得四柱实例 Pillar
// 而每个四柱实例(Pillar)又包含纳音、天干、地支、天干十神、地支十神、四柱神煞等功能查询

// 取各柱天干十神, 十神和神煞都是以对象形式存在
console.log(c8ex.year.stemTenGod.name) // 劫財
console.log(c8ex.month.stemTenGod.name) // 比肩
// 注:日主实际并不是十神之一,它位于日柱天干,十神以此推算。
console.log(c8ex.day.stemTenGod.name) // 日主
console.log(c8ex.hour.stemTenGod.name) // 正官

// 取各柱地支藏干十神
// 地支十神通过地支所藏天干推算,所以各柱的地支十神可能存在的个数为1至3个,故以数组形式返回
console.log(c8ex.year.branchTenGod.map(i => i.name)) // [ '傷官', '正財', '正官' ]
console.log(c8ex.month.branchTenGod.map(i => i.name)) // ['七殺', '比肩', '梟神']
console.log(c8ex.day.branchTenGod.map(i => i.name)) // ['梟神']
console.log(c8ex.hour.branchTenGod.map(i => i.name)) // ['偏財', '七殺']

//取年柱纳音
console.log(c8ex.year.takeSound) // 金箔金

//空亡地支 missing属性返回一个元组,该元组包含两个地支实例: [Branch, Branch]
// c8ex.missing 等同于 c8ex.day.missing
console.log(c8ex.missing.map(i => i.name)) //  [ '戌', '亥' ]

// 取得年柱上的神煞,其它柱类似
console.log(c8ex.year.gods.map(item => item.name)) // ['文昌貴人', '金輿', '天廚貴人', '劫煞']

:::tip char8ex插件默认语言与lunisolar一样为繁体中文,如需要其它语言,须再另外加载 :::

Char8Ex类

通过 lunisolar().char8ex(sex: 0 | 1): Char8Ex取得Char8Ex实例

为什么char8ex方法要设置性别参数?

因为个别神煞的计算方法男女不同。

属性或方法描述参数返回类型
me取得日主Stem
sexValue取得性别值0 | 1
sex取得性别 如'乾造' 或 '坤造'string
year取得年柱对象Pillar
month取得月柱对象Pillar
day取得日柱对象Pillar
hour取得时柱对象Pillar
gods取得各柱所有神煞{year: C8God[], month: C8God[], day: C8God[], hour: C8God[]}
list四柱列表Pillar, Pillar, Pillar, Pillar
embryo()胎元, 返回一个天干地支对象SB
ownSign()命宫, 返回一个天干地支对象SB
bodySign()身宫, 返回一个天干地支对象SB
toString()返回八字的基本信息描述SB

Pillar 四柱类

四柱类是SB类的增强版,主要补充了十神和神煞等属性

属性或方法描述参数返回类型
gods返回该柱所算出的所有神煞C8God[]
stem该柱天干Stem
branch该柱地支Branch
value该天干地支组合的索引值, 范围[0, 59]number
name该天干地支组合的字符串, 如 甲子string
takeSound取得五行纳音描述string
takeSoundE5取得五行纳音的五行对象Element5
stemTenGod取得天干十神TenGod
branchTenGod取得地支十神, 因为是按地支藏干算的, 所以返回提一个列表TenGod[]
missing返回旬空地支Branch, Branch
toString()该天干地支组合的字符串, 等同于name属性string

C8God 四柱神煞类

属性或方法描述参数返回类型
luckLevel吉凶等级, 1为吉, -1凶, 0不定number
key该神煞的key(以繁体中文神煞名作为key)string
name该神煞名string
toString()该天干地支组合的字符串, 等同于name属性string

TenGod 十神类

属性或方法描述参数返回类型
key该十神的key(以繁体中文神煞名作为key)string
name该十神名称string
toString()该天干地支组合的字符串, 等同于name属性string
0.2.5

5 months ago

0.2.4

9 months ago

0.2.3

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.2

1 year ago

0.1.0

1 year ago