UNPKG

lunisolar

Version:

专业农历库,支持公历阴历互转,支持各类黄历数据查询,如八字四柱、阴历、神煞宜忌、时辰吉凶、建除十二神、胎神占方、五行纳音等。支持自定义插件。

62 lines (50 loc) 1.34 kB
import type { GodBase } from './godBase' import { createGodBase } from '../utils/gods' import { trans } from '../utils' export class God { private godBase: GodBase private lang: string = 'zh' supple = new Map<string, any>() constructor(opt: GodClassOpt) { const { key, cate, fromDict, lang } = opt let godBase: GodBase | undefined if (typeof opt.godBase !== 'undefined') { godBase = opt.godBase } else if (typeof key !== 'undefined' && typeof cate !== 'undefined') { godBase = createGodBase(key, cate, fromDict) } if (!godBase) { throw new Error('no this god') } // if (!godBase) throw new Error('no this god') this.godBase = godBase if (lang) this.lang = lang } get key() { return this.godBase.key } get data() { return this.godBase.data } get alias(): string[] { return this.data.alias.map(i => trans(i, this.lang, 'gods')) } get name(): string { return trans(this.godBase.key, this.lang, 'gods') } get cate() { return this.data.cate } get good(): string[] { return this.data.good.map(i => trans(i, this.lang, 'acts')) } get bad(): string[] { return this.data.bad.map(i => trans(i, this.lang, 'acts')) } get luckLevel() { return this.data.luckLevel } toString() { return this.name } }