-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathichingObject.js
253 lines (243 loc) · 8.08 KB
/
ichingObject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
const triBase = [
['Ch’ien', 111, `Qian`, `乾`, `☰`],
['Tui', 11, `Dui`, `兌`, `☱`],
['Li', 101, `Li`, `離`, `☲`],
['Chên', 1, `Zhen`, `震`, `☳`],
['Sun', 110, `Xun`, `巽`, `☴`],
['K’an', 10, `Kan`, `坎`, `☵`],
['Kên', 100, `Gen`, `艮`, `☶`],
['K’un', 0, `Kun`, `坤`, `☷`],
];
const trigrams = triBase.map(( [oldName, bin, name, char, unicodeChar], i) => ({
name, oldName, char, unicode: (9776 + i), unicodeChar, htmlEntity: `&#${9776 + i};`, bin, binStr: bin.toString().padStart(3, "0")
}));
const hexagrams = [
[1, 111111, 63, 77, '3F'],
[2, 0, 0, 0, '0'],
[3, 10001, 17, 21, '11'],
[4, 100010, 34, 42, '22'],
[5, 10111, 23, 27, '17'],
[6, 111010, 58, 72, '3A'],
[7, 10, 2, 2, '2'],
[8, 10000, 16, 20, '10'],
[9, 110111, 55, 67, '37'],
[10, 111011, 59, 73, '3B'],
[11, 111, 7, 7, '7'],
[12, 111000, 56, 70, '38'],
[13, 111101, 61, 75, '3D'],
[14, 101111, 47, 57, '2F'],
[15, 100, 4, 4, '4'],
[16, 1000, 8, 10, '8'],
[17, 11001, 25, 31, '19'],
[18, 100110, 38, 46, '26'],
[19, 11, 3, 3, '3'],
[20, 110000, 48, 60, '30'],
[21, 101001, 41, 51, '29'],
[22, 100101, 37, 45, '25'],
[23, 100000, 32, 40, '20'],
[24, 1, 1, 1, '1'],
[25, 111001, 57, 71, '39'],
[26, 100111, 39, 47, '27'],
[27, 100001, 33, 41, '21'],
[28, 11110, 30, 36, '1E'],
[29, 10010, 18, 22, '12'],
[30, 101101, 45, 55, '2D'],
[31, 11100, 28, 34, '1C'],
[32, 1110, 14, 16, 'E'],
[33, 111100, 60, 74, '3C'],
[34, 1111, 15, 17, 'F'],
[35, 101000, 40, 50, '28'],
[36, 10, 2, 2, '2'],
[37, 110101, 53, 65, '35'],
[38, 101011, 43, 53, '2B'],
[39, 10100, 20, 24, '14'],
[40, 1010, 10, 12, 'A'],
[41, 100011, 35, 43, '23'],
[42, 110001, 49, 61, '31'],
[43, 11111, 31, 37, '1F'],
[44, 111110, 62, 76, '3E'],
[45, 11000, 24, 30, '18'],
[46, 110, 6, 6, '6'],
[47, 11010, 26, 32, '1A'],
[48, 10110, 22, 26, '16'],
[49, 11101, 29, 35, '1D'],
[50, 101110, 46, 56, '2E'],
[51, 110, 6, 6, '6'],
[52, 100100, 36, 44, '24'],
[53, 110100, 52, 64, '34'],
[54, 1011, 11, 13, 'B'],
[55, 1101, 13, 15, 'D'],
[56, 101100, 44, 54, '2C'],
[57, 110110, 54, 66, '36'],
[58, 11011, 27, 33, '1B'],
[59, 110010, 50, 62, '32'],
[60, 10011, 19, 23, '13'],
[61, 110011, 51, 63, '33'],
[62, 1100, 12, 14, 'C'],
[63, 10101, 21, 25, '15'],
[64, 101010, 42, 52, '2A'],
];
const names = [
[1, `乾`, `Qián`],
[2, `坤`, `Kūn`],
[3, `屯`, `Zhūn`],
[4, `蒙`, `Méng`],
[5, `需`, `Xū`],
[6, `訟`, `Sòng`],
[7, `師`, `Shī`],
[8, `比`, `Bǐ`],
[9, `小畜`, `Xiǎo Xù`],
[10, `履`, `Lǚ`],
[11, `泰`, `Tài`],
[12, `否`, `Pǐ`],
[13, `同人`, `Tóng Rén`],
[14, `大有`, `Dà Yǒu`],
[15, `謙`, `Qiān`],
[16, `豫`, `Yù`],
[17, `隨`, `Suí`],
[18, `蠱`, `Gŭ`],
[19, `臨`, `Lín`],
[20, `觀`, `Guān`],
[21, `噬嗑`, `Shì Kè`],
[22, `賁`, `Bì`],
[23, `剝`, `Bō`],
[24, `復`, `Fù`],
[25, `無妄`, `Wú Wàng`],
[26, `大畜`, `Dà Xù`],
[27, `頤`, `Yí`],
[28, `大過`, `Dà Guò`],
[29, `坎`, `Kǎn`],
[30, `離`, `Lí`],
[31, `咸`, `Xián`],
[32, `恆`, `Héng`],
[33, `遯`, `Dùn`],
[34, `大壯`, `Dà Zhuàng`],
[35, `晉`, `Jìn`],
[36, `明夷`, `Míng Yí`],
[37, `家人`, `Jiā Rén`],
[38, `睽`, `Kuí`],
[39, `蹇`, `Jiǎn`],
[40, `解`, `Xiè`],
[41, `損`, `Sǔn`],
[42, `益`, `Yì`],
[43, `夬`, `Guài`],
[44, `姤`, `Gòu`],
[45, `萃`, `Cuì`],
[46, `升`, `Shēng`],
[47, `困`, `Kùn`],
[48, `井`, `Jǐng`],
[49, `革`, `Gé`],
[50, `鼎`, `Tǐng`],
[51, `震`, `Zhèn`],
[52, `艮`, `Gèn`],
[53, `漸`, `Jiàn`],
[54, `歸妹`, `Guī Mèi`],
[55, `豐`, `Fēng`],
[56, `旅`, `Lǚ`],
[57, `巽`, `Xùn`],
[58, `兌`, `Duì`],
[59, `渙`, `Huàn`],
[60, `節`, `Jié`],
[61, `中孚`, `Zhōng Fú`],
[62, `小過`, `Xiǎo Guò`],
[63, `既濟`, `Jì Jì`],
[64, `未濟`, `Wèi Jì`],
];
const names2 = [
`1 Ch’ien 乾 The Creative`,
`2 K’un 坤 The Receptive`,
`3 Chun 屯 Difficulty at the Beginning`,
`4 Mêng 蒙 Youthful Folly`,
`5 Hsü 需 Waiting (Nourishment)`,
`6 Sung 訟 Conflict`,
`7 Shih 師 The Army`,
`8 Pi 比 Holding Together [Union]`,
`9 Hsiao Ch’u 小畜 The Taming Power of the Small`,
`10 Lü 履 Treading [Conduct]`,
`11 T’ai 泰 Peace`,
`12 P’i 否 Standstill [Stagnation]`,
`13 T’ung Jên 同人 Fellowship with Men`,
`14 Ta Yu 大有 Possession in Great Measure`,
`15 Ch’ien 謙 Modesty`,
`16 Yü 豫 Enthusiasm`,
`17 Sui 隨 Following`,
`18 Ku 蠱 Work on what has been spoiled [Decay]`,
`19 Lin 臨 Approach`,
`20 Kuan 觀 Contemplation (View)`,
`21 Shih Ho 噬嗑 Biting Through`,
`22 Pi 賁 Grace`,
`23 Po 剝 Splitting Apart`,
`24 Fu 復 Return (The Turning Point)`,
`25 Wu Wang 無妄 Innocence (The Unexpected)`,
`26 Ta Ch’u 大畜 The Taming Power of the Great`,
`27 I 頤 Corners of the Mouth (Providing Nourishment)`,
`28 Ta Kuo 大過 Preponderance of the Great`,
`29 K’an 坎 The Abysmal (Water)`,
`30 Li 離 The Clinging, Fire`,
`31 Hsien 咸 Influence (Wooing)`,
`32 Hêng 恆 Duration`,
`33 Tun 遯 Retreat`,
`34 Ta Chuang 大壯 The Power of the Great`,
`35 Chin 晉 Progress`,
`36 Ming I 明夷 Darkening of the light`,
`37 Chia Jên 家人 The Family [The Clan]`,
`38 K’uei 睽 Opposition`,
`39 Chien 蹇 Obstruction`,
`40 Hsieh 解 Deliverance`,
`41 Sun 損 Decrease`,
`42 I 益 Increase`,
`43 Kuai 夬 Break-through (Resoluteness)`,
`44 Kou 姤 Coming to Meet`,
`45 Ts’ui 萃 Gathering Together [Massing]`,
`46 Shêng 升 Pushing Upward`,
`47 K’un 困 Oppression (Exhaustion)`,
`48 Ching 井 The Well `,
`49 Ko 革 Revolution (Molting)`,
`50 Ting 鼎 The Caldron`,
`51 Chên 震 The Arousing (Shock, Thunder)`,
`52 Kên 艮 Keeping Still, Mountain`,
`53 Chien 漸 Development (Gradual Progress)`,
`54 Kuei Mei 歸妹 The Marrying Maiden`,
`55 Fêng 豐 Abundance [Fullness]`,
`56 Lü 旅 The Wanderer`,
`57 Sun 巽 The Gentle (The Penetrating, Wind)`,
`58 Tui 兌 The Joyous, Lake`,
`59 Huan 渙 Dispersion [Dissolution]`,
`60 Chieh 節 Limitation`,
`61 Chung Fu 中孚 Inner Truth`,
`62 Hsiao Kuo 小過 Preponderance of the Small`,
`63 Chi Chi 既濟 After Completion`,
`64 Wei Chi 未濟 Before Completion`,
].map(s => {
const chars2 = s.match(/ \p{sc=Han}+ /u).pop().trim();
const [fore, title] = s.split(chars2);
const [xx, strKW, oldName] = fore.trim().match(/(\d+) (.*)/);
return { kingWen: parseInt(strKW), oldName, chars2, title: title.trim() };
});
const pantherRanges = [
[1, 10],
[11, 20],
[21, 30],
[31, 41,],
[42, 52],
[53, 64],
];
const pantherUrl = kingWen => {
base = `http://www.pantherwebworks.com/I_Ching/`;
const [lo, hi] = pantherRanges.filter(([lo, hi]) => kingWen >= lo && kingWen <= hi).pop();
return `${base}bk1h${lo}-${hi}.html#${kingWen}`;
}
const iChing = hexagrams.map(([kingWen, bin, dec, oct, hexStr]) => ({ kingWen, bin, dec, oct, hexStr, binStr: bin.toString().padStart(6, "0"), }))
.map(h => {
const { binStr } = h;
const upper = trigrams.find( t => t.binStr === binStr.slice(0, 3));
const lower = trigrams.find( t => t.binStr === binStr.slice(3));
const [kW, chars, name] = names.find(n => n[0] === h.kingWen)
const { x, kingWen, oldName, chars2, title } = names2.find(n => n.kingWen === h.kingWen);
const uniCode = parseInt("4DBF", 16) + kingWen;
const unicodeChar = String.fromCharCode(uniCode);
const htmlEntity = `&#${uniCode};`;
return { name, oldName, chars, title, ...h, uniCode, unicodeChar, htmlEntity, upper, lower, url: pantherUrl(kingWen) };
});
// iChing;
module.exports = {iChing, trigrams};