lunisolar
Version:
专业农历库,支持公历阴历互转,支持各类黄历数据查询,如八字四柱、阴历、神煞宜忌、时辰吉凶、建除十二神、胎神占方、五行纳音等。支持自定义插件。
35 lines (31 loc) • 1.04 kB
text/typescript
import takeSound from '../takeSound'
import { setLocales } from './utils'
import zh from './locale/zh'
import { Char8Ex } from './class/char8ex'
import { Pillar } from './class/pillar'
import { C8God } from './class/c8God'
import { TenGod } from './class/tenGod'
const char8ex: lunisolar.PluginFunc = async (options, lsClass, lsFactory) => {
lsFactory.locale(zh, true)
setLocales(lsFactory._globalConfig.locales)
// 加載纳音功能
lsFactory.extend(takeSound)
const lsPrototype = lsClass.prototype
Object.defineProperty(lsPrototype, 'char8ex', {
value: function (sex: 0 | 1) {
const cacheKey = `char8ex:sex_${sex}`
if (this.cache.has(cacheKey)) {
const cacheData = this.cache.get(cacheKey)
if (cacheData instanceof Char8Ex) return cacheData
}
const char8ex = new Char8Ex(this, sex)
this.cache.set(cacheKey, char8ex)
return char8ex
}
})
}
char8ex.Char8Ex = Char8Ex
char8ex.Pillar = Pillar
char8ex.C8God = C8God
char8ex.TenGod = TenGod
export default char8ex