项目作者: airicyu

项目描述 :
A Node.js Library for Chinese Astrology Common Codex. (中國術數基本codex)
高级语言: JavaScript
项目地址: git://github.com/airicyu/fortel-codex.git
创建时间: 2017-03-17T07:24:03Z
项目社区:https://github.com/airicyu/fortel-codex

开源协议:MIT License

下载


fortel-codex.js

npm version
node
Build
Codecov branch

GitHub issues
GitHub forks
GitHub stars
GitHub License
dependencies Status
devDependencies Status

This node.js module is a library for some basic codex of Chinese Astrology. It included “陰陽”, “五行”, “天干”, “地支”, “生肖”.

Project page

Wiki pages for Chinese Astrology:


Install

  1. $ npm install --save fortel-codex

Samples

MoonSun(陰陽)

  1. const fortelCodex = require('fortel-codex');
  2. const MoonSun = fortelCodex.MoonSun;
  3. var moon = MoonSun.get('陰');
  4. moon = MoonSun.Moon; //or equivalently
  5. console.log('陰:', moon);
  6. var sun = MoonSun.get('陽');
  7. sun = MoonSun.Sun; //or equivalently
  8. console.log('陽:', sun);

Console output

  1. 陰: MoonSun { index: 0, displayName: '陰' }
  2. 陽: MoonSun { index: 1, displayName: '陽' }

Element(五行)

基本五行

  1. const Element = fortelCodex.Element;
  2. /* 基本五行 Object */
  3. var gold = Element.Gold;
  4. gold = Element.get('金'); //or equivalently
  5. console.log('金: ', gold);
  6. var wood = Element.Wood;
  7. wood = Element.get('木'); //or equivalently
  8. console.log('木: ', wood);
  9. var earth = Element.Earth;
  10. earth = Element.get('土'); //or equivalently
  11. console.log('土: ', earth);
  12. var water = Element.Water;
  13. water = Element.get('水'); //or equivalently
  14. console.log('水: ', water);
  15. var fire = Element.Fire;
  16. fire = Element.get('火'); //or equivalently
  17. console.log('火: ', fire);

Console output

  1. 金: Element { index: 0, displayName: '金' }
  2. 木: Element { index: 1, displayName: '木' }
  3. 土: Element { index: 2, displayName: '土' }
  4. 水: Element { index: 3, displayName: '水' }
  5. 火: Element { index: 4, displayName: '火' }

五行關係

  1. console.log('五行生剋關係1:');
  2. console.log(`金${gold.to(gold).relationship}金`);
  3. console.log(`金${gold.to(wood).relationship}木`);
  4. console.log(`金${gold.to(earth).relationship}土`);
  5. console.log(`金${gold.to(water).relationship}水`);
  6. console.log(`金${gold.to(fire).relationship}火`);
  7. console.log('\n');
  8. console.log('五行生剋關係2:');
  9. console.log(`金生${gold.getEnhance().displayName}`);
  10. console.log(`金被${gold.getEnhancedBy().displayName}所生`);
  11. console.log(`金剋${gold.getSuppress().displayName}`);
  12. console.log(`金被${gold.getSuppressedBy().displayName}所剋`);

Console output

  1. 五行生剋關係1:
  2. 金同金
  3. 金剋木
  4. 金被生土
  5. 金生水
  6. 金被剋火
  7. 五行生剋關係2:
  8. 金生水
  9. 金被土所生
  10. 金剋木
  11. 金被火所剋

Stem(天干)

Array of Stem object(天干)

  1. const fortelCodex = require('fortel-codex');
  2. const Stem = fortelCodex.Stem;
  3. /* 基本天干 Object */
  4. var items = Stem.items; //Array of "天干"
  5. var output = "";
  6. for(let item of items){
  7. output += item.displayName;
  8. }
  9. console.log(output);

Console output

  1. 甲乙丙丁戊己庚辛壬癸

Get by index

  1. const util = require('util');
  2. const fortelCodex = require('fortel-codex');
  3. const Stem = fortelCodex.Stem;
  4. /* Get 天干 by index */
  5. console.log('0: '+util.inspect(Stem.get(0)));
  6. console.log('1: '+util.inspect(Stem.get(1)));
  7. console.log('......\n');

Console output

  1. 0: Stem {
  2. index: 0,
  3. displayName: '甲',
  4. moonSun: MoonSun { index: 1, displayName: '陽' },
  5. element: Element { index: 1, displayName: '木' } }
  6. 1: Stem {
  7. index: 1,
  8. displayName: '乙',
  9. moonSun: MoonSun { index: 0, displayName: '陰' },
  10. element: Element { index: 1, displayName: '木' } }

Get by name

  1. const util = require('util');
  2. const fortelCodex = require('fortel-codex');
  3. const Stem = fortelCodex.Stem;
  4. /* Get 天干 by display name */
  5. console.log('0: '+util.inspect(Stem.get('甲')));
  6. console.log('1: '+util.inspect(Stem.get('乙')));
  7. console.log('......\n');

Console output

  1. 0: Stem {
  2. index: 0,
  3. displayName: '甲',
  4. moonSun: MoonSun { index: 1, displayName: '陽' },
  5. element: Element { index: 1, displayName: '木' } }
  6. 1: Stem {
  7. index: 1,
  8. displayName: '乙',
  9. moonSun: MoonSun { index: 0, displayName: '陰' },
  10. element: Element { index: 1, displayName: '木' } }

天干合化

  1. /* 天干合化 */
  2. console.log('甲己合化' + Stem.get('甲').getSythesisResult(Stem.get('己')).displayName); //甲己合化土
  3. console.log('乙庚合化' + Stem.get('乙').getSythesisResult(Stem.get('庚')).displayName); //乙庚合化金
  4. console.log('丙辛合化' + Stem.get('丙').getSythesisResult(Stem.get('辛')).displayName); //丙辛合化水
  5. console.log('丁壬合化' + Stem.get('丁').getSythesisResult(Stem.get('壬')).displayName); //丁壬合化木
  6. console.log('戊癸合化' + Stem.get('戊').getSythesisResult(Stem.get('癸')).displayName); //戊癸合化火

Console output

  1. 甲己合化土
  2. 乙庚合化金
  3. 丙辛合化水
  4. 丁壬合化木
  5. 戊癸合化火

天干相剋

  1. /* 天干相剋 */
  2. console.log('甲剋' + Stem.get('甲').getSuppress().displayName);
  3. console.log('戊被' + Stem.get('戊').getSuppressedBy().displayName + '所剋');

Console output

  1. 甲剋戊
  2. 戊被甲所剋

Branch(地支)

Array of Branch object(地支)

  1. const fortelCodex = require('fortel-codex');
  2. const Branch = fortelCodex.Branch;
  3. /* 基本地支 Object */
  4. var items = Branch.items; //Array of "地支"
  5. var output = "";
  6. for(let item of items){
  7. output += item.displayName;
  8. }
  9. console.log(output);

Console output

  1. 子丑寅卯辰巳午未申酉戌亥

Get by index

  1. /* Get 地支 by index */
  2. console.log('0: '+util.inspect(Branch.get(0)));
  3. console.log('1: '+util.inspect(Branch.get(1)));
  4. console.log('......\n');

Console output

  1. 0: Branch {
  2. index: 0,
  3. displayName: '子',
  4. moonSun: MoonSun { index: 1, displayName: '陽' },
  5. element: Element { index: 3, displayName: '水' },
  6. baseStem:
  7. Stem {
  8. index: 9,
  9. displayName: '癸',
  10. moonSun: MoonSun { index: 0, displayName: '陰' },
  11. element: Element { index: 3, displayName: '水' } },
  12. collectStem: null,
  13. remainStem: null }
  14. 1: Branch {
  15. index: 1,
  16. displayName: '丑',
  17. moonSun: MoonSun { index: 0, displayName: '陰' },
  18. element: Element { index: 2, displayName: '土' },
  19. baseStem:
  20. Stem {
  21. index: 5,
  22. displayName: '己',
  23. moonSun: MoonSun { index: 0, displayName: '陰' },
  24. element: Element { index: 2, displayName: '土' } },
  25. collectStem:
  26. Stem {
  27. index: 7,
  28. displayName: '辛',
  29. moonSun: MoonSun { index: 0, displayName: '陰' },
  30. element: Element { index: 0, displayName: '金' } },
  31. remainStem:
  32. Stem {
  33. index: 9,
  34. displayName: '癸',
  35. moonSun: MoonSun { index: 0, displayName: '陰' },
  36. element: Element { index: 3, displayName: '水' } } }
  37. ......

Get by name

  1. const util = require('util');
  2. const fortelCodex = require('fortel-codex');
  3. const Stem = fortelCodex.Stem;
  4. /* Get 地支 by display name */
  5. console.log('0: '+util.inspect(Stem.get('子')));
  6. console.log('1: '+util.inspect(Stem.get('丑')));
  7. console.log('......\n');

Console output

  1. 0: Branch {
  2. index: 0,
  3. displayName: '子',
  4. moonSun: MoonSun { index: 1, displayName: '陽' },
  5. element: Element { index: 3, displayName: '水' },
  6. baseStem:
  7. Stem {
  8. index: 9,
  9. displayName: '癸',
  10. moonSun: MoonSun { index: 0, displayName: '陰' },
  11. element: Element { index: 3, displayName: '水' } },
  12. collectStem: null,
  13. remainStem: null }
  14. 1: Branch {
  15. index: 1,
  16. displayName: '丑',
  17. moonSun: MoonSun { index: 0, displayName: '陰' },
  18. element: Element { index: 2, displayName: '土' },
  19. baseStem:
  20. Stem {
  21. index: 5,
  22. displayName: '己',
  23. moonSun: MoonSun { index: 0, displayName: '陰' },
  24. element: Element { index: 2, displayName: '土' } },
  25. collectStem:
  26. Stem {
  27. index: 7,
  28. displayName: '辛',
  29. moonSun: MoonSun { index: 0, displayName: '陰' },
  30. element: Element { index: 0, displayName: '金' } },
  31. remainStem:
  32. Stem {
  33. index: 9,
  34. displayName: '癸',
  35. moonSun: MoonSun { index: 0, displayName: '陰' },
  36. element: Element { index: 3, displayName: '水' } } }
  37. ......

地支六合局

  1. /* Get 地支六合局 */
  2. let combinations = Branch.checkCombinations([Branch.get('子'), Branch.get('丑')]);
  3. console.log("子丑合化"+combinations.sixSythesis[0].element.displayName);
  4. console.log("寅亥合化"+Branch.checkSixSythesis(Branch.get('寅'), Branch.get('亥')).displayName);

Console output

  1. 子丑合化土
  2. 寅亥合化木

地支三合局

  1. /* Get 地支三合局 */
  2. let combinations = Branch.checkCombinations([Branch.get('申'), Branch.get('子'), Branch.get('辰')]);
  3. console.log("申子辰三合"+combinations.threeSythesis[0].combination.element.displayName+"局");
  4. console.log("寅戌合"+Branch.checkThreeSythesis(Branch.get('寅'), Branch.get('戌')).element.displayName+"局");

Console output

  1. 申子辰三合水局
  2. 寅戌合火局

地支相沖

  1. /* Get 地支相沖 */
  2. console.log(Branch.checkOpposite(Branch.get('子'), Branch.get('午')));
  3. console.log(Branch.checkOpposite(Branch.get('子'), Branch.get('亥')));

Console output

  1. true
  2. false

地支相刑

  1. /* Get 地支相刑 */
  2. let combinations = Branch.checkCombinations([Branch.get('寅'), Branch.get('巳'), Branch.get('申')]);
  3. console.log(combinations.punishment[0].type);
  4. combinations = Branch.checkCombinations([Branch.get('午'), Branch.get('午')]);
  5. console.log(combinations.punishment[0].type);

Console output

  1. 無恩之刑
  2. 自刑

地支相害

  1. /* Get 地支相害 */
  2. /* Get 地支相刑 */
  3. console.log(Branch.checkHarm(Branch.get('子'), Branch.get('未')));
  4. console.log(Branch.checkHarm(Branch.get('子'), Branch.get('丑')));

Console output

  1. true
  2. false

BranchHour(時辰)

Array of BranchHour object(時辰)

  1. const fortelCodex = require('fortel-codex');
  2. const BranchHour = fortelCodex.BranchHour;
  3. var items = BranchHour.items; //Array of "時辰"
  4. console.log(items.map(item=>item.displayName).join(', '));

Console output

  1. 早子, 丑, 寅, 卯, 辰, 巳, 午, 未, 申, 酉, 戌, 亥, 晚子

Zodiac(生肖)

Array of Zodiac object(生肖)

  1. const fortelCodex = require('fortel-codex');
  2. const Zodiac = fortelCodex.Zodiac;
  3. var items = Zodiac.items; //Array of "生肖"
  4. console.log(items.map(item=>item.displayName).join(', '));

Console output

  1. 鼠, 牛, 虎, 兔, 龍, 蛇, 馬, 羊, 猴, 雞, 狗,

API

(Will update later)


Author Contact