liuyao 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,11 +6,11 @@ For more packages, see [my homepage](https://baendlorel.github.io/?repoType=npm)
6
6
 
7
7
  ## Features
8
8
 
9
- - Create a yao from its yang-count representation.
10
- - Build a hexagram from six yao lines or from a known hexagram name.
9
+ - Create a yao from its Yang-count representation, quaternary or various arguments.
10
+ - Build a hexagram from six Yao lines or from a known hexagram name.
11
11
  - Inspect hexagram metadata such as its name, palace, phase, and setup information.
12
12
  - Derive the changed hexagram for dynamic lines.
13
- - Access six-god ordering data for different heavenly stems.
13
+ - Access Six God ordering data for different heavenly stems.
14
14
 
15
15
  ## Installation
16
16
 
@@ -23,16 +23,9 @@ pnpm add liuyao
23
23
  ```ts
24
24
  import { Hexagram, Yao, SixGodList } from 'liuyao';
25
25
 
26
- const hexagram = Hexagram.fromYaos([
27
- new Yao(3),
28
- new Yao(1),
29
- new Yao(2),
30
- new Yao(2),
31
- new Yao(1),
32
- new Yao(0),
33
- ]);
26
+ const hexagram = Hexagram.fromQuaternary('111222'); // gets a Hexagram instance of '地天泰'
34
27
 
35
- if (!hexagram) {
28
+ if (hexagram === null) {
36
29
  throw new Error('Invalid hexagram');
37
30
  }
38
31
 
@@ -101,11 +94,19 @@ Useful factory methods:
101
94
 
102
95
  The package currently exports:
103
96
 
97
+ **Classes:**
104
98
  - `Hexagram`
105
99
  - `Yao`
106
- - `YaoIndex`
107
- - `SixGodList`
100
+
101
+ **Data Lists:**
102
+ - `HexagramList`(六十四卦): Includes 64 static hexagram info objects with traditional metadata.
103
+ - `HexagramYaoIndex`(六十四卦爻位名)
104
+ - `TrigramList`(八卦): Includes 8 static trigram info objects with traditional metadata.
105
+ - `SixGodList`(六神表)
106
+
107
+ **Types:**
108
108
  - type `SixGod`
109
+ - type `SixGodInfo`
109
110
  - type `SetupGramInfo`
110
111
 
111
112
  ## Notes
package/dist/index.d.ts CHANGED
@@ -30,7 +30,7 @@ interface PalaceIndexName {
30
30
  name: string;
31
31
  nameEn: string;
32
32
  }
33
- declare const PalaceIndexList: PalaceIndexName[];
33
+ declare const PalaceIndexTable: PalaceIndexName[];
34
34
  interface HexagramInfo {
35
35
  /**
36
36
  * Binary representation of the hexagram, where 0 represents a yin line and 1 represents a yang line. The lines are ordered from the bottom (first line) to the top (sixth line).
@@ -82,7 +82,7 @@ interface HexagramInfo {
82
82
  */
83
83
  setupInfo: [SetupGramInfo, SetupGramInfo, SetupGramInfo, SetupGramInfo, SetupGramInfo, SetupGramInfo];
84
84
  }
85
- declare const HexagramList: readonly HexagramInfo[];
85
+ declare const HexagramInfoTable: readonly HexagramInfo[];
86
86
  interface TrigramInfo {
87
87
  /**
88
88
  * Presents the trigram as a 3-digit binary string. 1 represents a Yang line and 0 represents a Yin line.
@@ -118,7 +118,7 @@ interface TrigramInfo {
118
118
  /**
119
119
  * List of all trigrams in the I Ching, with their binary representation, number of yang lines, name, what they represent, and their corresponding sign.
120
120
  */
121
- declare const TrigramList: readonly TrigramInfo[];
121
+ declare const TrigramInfoTable: readonly TrigramInfo[];
122
122
 
123
123
  type SixGod = '玄武' | '白虎' | '螣蛇' | '勾陈' | '朱雀' | '青龙';
124
124
  interface SixGodInfo {
@@ -145,7 +145,7 @@ interface SixGodInfo {
145
145
  /**
146
146
  * @see 《增删卜易·六神章》
147
147
  */
148
- declare const SixGodList: readonly SixGodInfo[];
148
+ declare const SixGodTable: readonly SixGodInfo[];
149
149
 
150
150
  declare class Yao {
151
151
  static getName(yangCount: number): "老阴" | "少阳" | "少阴" | "老阳";
@@ -226,7 +226,7 @@ declare class Yao {
226
226
  }
227
227
 
228
228
  type LiuYao = [Yao, Yao, Yao, Yao, Yao, Yao];
229
- declare const YaoIndex: readonly ["初爻", "二爻", "三爻", "四爻", "五爻", "上爻"];
229
+ declare const HexagramYaoOrder: readonly ["初爻", "二爻", "三爻", "四爻", "五爻", "上爻"];
230
230
  /**
231
231
  * Hexagram class represents a hexagram, which consists of 6 Yao.
232
232
  * - Each Yao can be either yin or yang, and can be changing or not.
@@ -237,7 +237,7 @@ declare class Hexagram {
237
237
  /**
238
238
  * Use tokens like `'012132'` to create a Hexagram, where each digit represents the count of Yang in the corresponding Yao (0 for 老阴, 1 for 少阳, 2 for 少阴, 3 for 老阳). The first digit represents the first Yao (初爻) and the last digit represents the sixth Yao (上爻).
239
239
  */
240
- static fromBinary(quaternary: string): Hexagram | null;
240
+ static fromQuaternary(quaternary: string): Hexagram | null;
241
241
  /**
242
242
  * Use tokens like `'单单拆拆重重'` to create a Hexagram.
243
243
  *
@@ -292,11 +292,32 @@ declare class Hexagram {
292
292
  * - e.g.:“本卦乾为天,变卦坤为地,动爻:初爻、三爻”
293
293
  */
294
294
  toDescription(): string;
295
- toDescriptionEn(): string;
295
+ /**
296
+ * This output is meant for AI skills.
297
+ */
298
+ toAIReadable(): {
299
+ 本卦: HexagramAIReadable<'本卦'>;
300
+ 变卦: HexagramAIReadable<'变卦'> | null;
301
+ };
296
302
  clone(): Hexagram;
297
303
  toString(): string;
298
- [Symbol.toPrimitive](hint: string): string;
304
+ [Symbol.toPrimitive](): string;
305
+ }
306
+ interface YaoInfo {
307
+ 爻象: string;
308
+ 类型: '世' | '应' | null;
309
+ 六亲五行: string;
310
+ }
311
+ interface HexagramAIReadable<T extends '本卦' | '变卦'> {
312
+ 初爻: YaoInfo;
313
+ 二爻: YaoInfo;
314
+ 三爻: YaoInfo;
315
+ 四爻: YaoInfo;
316
+ 五爻: YaoInfo;
317
+ 上爻: YaoInfo;
318
+ 卦名: string;
319
+ 变爻?: string[];
299
320
  }
300
321
 
301
- export { Hexagram, HexagramList, PalaceIndexList, SixGodList, TrigramList, Yao, YaoIndex };
322
+ export { Hexagram, HexagramInfoTable, HexagramYaoOrder, PalaceIndexTable, SixGodTable, TrigramInfoTable, Yao };
302
323
  export type { HexagramInfo, SetupGramInfo, SixGod, SixGodInfo, TrigramInfo };
package/dist/index.mjs CHANGED
@@ -1655,7 +1655,7 @@ class h {
1655
1655
  const r = [ "初爻", "二爻", "三爻", "四爻", "五爻", "上爻" ];
1656
1656
 
1657
1657
  class l {
1658
- static fromBinary(n) {
1658
+ static fromQuaternary(n) {
1659
1659
  const i = n.split("").map(h.fromDigitString);
1660
1660
  return i.every(n => null !== n) ? new l(i) : null;
1661
1661
  }
@@ -1708,14 +1708,88 @@ class l {
1708
1708
  return new l(this.yaos.map(n => n.toChanged()));
1709
1709
  }
1710
1710
  toDescription() {
1711
- const n = [ `本卦${this.info.id}` ], i = this.toChanged();
1712
- return i ? (n.push(`变卦${i.info.id}`), n.push(`动爻:${this.yaos.map((n, i) => n.isDynamic ? `${r[i]}` : null).filter(n => null !== n).join("、")}`)) : n.push("无动爻"),
1713
- n.join(",");
1711
+ const n = this.info.setupInfo.findIndex(n => "世" === n.hostGuest), i = this.info.setupInfo.findIndex(n => "应" === n.hostGuest), e = [ `本卦${this.info.id}`, `世爻为${r[n]}`, `应爻为${r[i]}` ], s = this.toChanged();
1712
+ if (s) {
1713
+ e.push(`${this.yaos.map((n, i) => n.isDynamic ? `${r[i]}` : null).filter(n => null !== n).join("、")}是动爻`),
1714
+ e.push(`变卦为${s.info.id}`);
1715
+ const n = s.info.setupInfo.findIndex(n => "世" === n.hostGuest);
1716
+ this.yaos[n].isDynamic ? e.push(`变卦世爻为${r[n]}`) : e.push("未变出新的世爻");
1717
+ const i = s.info.setupInfo.findIndex(n => "应" === n.hostGuest);
1718
+ this.yaos[i].isDynamic ? e.push(`变卦应爻为${r[i]}`) : e.push("未变出新的应爻");
1719
+ } else e.push("无动爻");
1720
+ return e.join(",");
1714
1721
  }
1715
- toDescriptionEn() {
1716
- const n = [ `Original Hexagram ${this.info.id}` ], i = this.toChanged();
1717
- return i ? (n.push(`Changed Hexagram ${i.info.id}`), n.push(`Dynamic Yaos: ${this.yaos.map((n, i) => n.isDynamic ? `${r[i]}` : null).filter(n => null !== n).join(", ")}`)) : n.push("No dynamic Yao"),
1718
- n.join(", ");
1722
+ toAIReadable() {
1723
+ const n = this.info.setupInfo, i = this.toChanged(), e = i?.info.setupInfo;
1724
+ return {
1725
+ "本卦": {
1726
+ "初爻": {
1727
+ "爻象": this.yaos[0].name,
1728
+ "类型": n[0].hostGuest || null,
1729
+ "六亲五行": n[0].kin
1730
+ },
1731
+ "二爻": {
1732
+ "爻象": this.yaos[1].name,
1733
+ "类型": n[1].hostGuest || null,
1734
+ "六亲五行": n[1].kin
1735
+ },
1736
+ "三爻": {
1737
+ "爻象": this.yaos[2].name,
1738
+ "类型": n[2].hostGuest || null,
1739
+ "六亲五行": n[2].kin
1740
+ },
1741
+ "四爻": {
1742
+ "爻象": this.yaos[3].name,
1743
+ "类型": n[3].hostGuest || null,
1744
+ "六亲五行": n[3].kin
1745
+ },
1746
+ "五爻": {
1747
+ "爻象": this.yaos[4].name,
1748
+ "类型": n[4].hostGuest || null,
1749
+ "六亲五行": n[4].kin
1750
+ },
1751
+ "上爻": {
1752
+ "爻象": this.yaos[5].name,
1753
+ "类型": n[5].hostGuest || null,
1754
+ "六亲五行": n[5].kin
1755
+ },
1756
+ "卦名": this.info.id,
1757
+ "变爻": this.isDynamic ? this.yaos.map((n, i) => n.isDynamic ? r[i] : null).filter(n => null !== n) : void 0
1758
+ },
1759
+ "变卦": e ? {
1760
+ "初爻": {
1761
+ "爻象": i.yaos[0].name,
1762
+ "类型": e[0].hostGuest || null,
1763
+ "六亲五行": e[0].kin
1764
+ },
1765
+ "二爻": {
1766
+ "爻象": i.yaos[1].name,
1767
+ "类型": e[1].hostGuest || null,
1768
+ "六亲五行": e[1].kin
1769
+ },
1770
+ "三爻": {
1771
+ "爻象": i.yaos[2].name,
1772
+ "类型": e[2].hostGuest || null,
1773
+ "六亲五行": e[2].kin
1774
+ },
1775
+ "四爻": {
1776
+ "爻象": i.yaos[3].name,
1777
+ "类型": e[3].hostGuest || null,
1778
+ "六亲五行": e[3].kin
1779
+ },
1780
+ "五爻": {
1781
+ "爻象": i.yaos[4].name,
1782
+ "类型": e[4].hostGuest || null,
1783
+ "六亲五行": e[4].kin
1784
+ },
1785
+ "上爻": {
1786
+ "爻象": i.yaos[5].name,
1787
+ "类型": e[5].hostGuest || null,
1788
+ "六亲五行": e[5].kin
1789
+ },
1790
+ "卦名": i.info.id
1791
+ } : null
1792
+ };
1719
1793
  }
1720
1794
  clone() {
1721
1795
  return new l(this.yaos);
@@ -1723,9 +1797,9 @@ class l {
1723
1797
  toString() {
1724
1798
  return this.info.id;
1725
1799
  }
1726
- [Symbol.toPrimitive](n) {
1800
+ [Symbol.toPrimitive]() {
1727
1801
  return this.info.id;
1728
1802
  }
1729
1803
  }
1730
1804
 
1731
- export { l as Hexagram, i as HexagramList, n as PalaceIndexList, s as SixGodList, e as TrigramList, h as Yao, r as YaoIndex };
1805
+ export { l as Hexagram, i as HexagramInfoTable, r as HexagramYaoOrder, n as PalaceIndexTable, s as SixGodTable, e as TrigramInfoTable, h as Yao };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liuyao",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": {
5
5
  "name": "Kasukabe Tsumugi",
6
6
  "email": "futami16237@gmail.com"