0.20.2 • Published 4 years ago

@tony801015/chinese-lunar v0.20.2

Weekly downloads
58
License
ISC
Repository
github
Last release
4 years ago

命理基本的查詢

npm version npm Build Status Coverage Status codebeat badge

目前已提供年柱,月柱,日柱,時柱,農曆月,農曆日,節氣,星期,生肖,星座,紫白,納音,胎元,命宮,身宮,藏幹,副星的資訊

ChangeLog

  • 2021/01/30 0.20.0 版本修復#16
  • 2020/11/16 0.19.0 版本移除moment.js改用day.js
  • 2020/04/05 0.18.0 版本提供胎元, 命宮, 身宮 .getTaiYuan() .getMingGong() .getShenGong()
  • 2020/02/21 0.17.0 版本提供取得紫白九星的方法和取得納音屬性 .getNayin() .getPurpleWhites()
  • 2020/02/08 0.16.0 版本提供日期加減的計算 .add() .subtract()
  • 2020/02/02 0.15.0 版本提供上(下)一個節氣的距離天數 .getSolarTermDistance()
  • 2020/01/25 0.14.0 版本農曆轉公(國)曆的功能囉 .lunarToSolar()
  • 2020/01/18 0.13.0 版本提供讓八字有更精準的計算。底下的特殊方法有介紹八字計算,歡迎大家試算看看唷~
  • 2020/01/08 0.12.1-beta版本提供更簡單的使用方式,預設當前時間,也可以自訂自己使用的時間。
  • 2019/10/24 0.9.0版本提供了此年的農曆中每個月有多少天getLunarPerMonthHasDays,這裡可以搭配0.6.4版推出的閏月是哪一天來應用。
  • 2019/10/23 0.8.0版本提供了星座,可以從.getJson()constellationproperty 拿到
  • 2019/10/23 0.8.1版本修復十神,十神需提供使用者出生的年柱做搭配
  • 2019/10/21 0.7.0版本提供了更長的範圍,從 1956 到 1900 補齊囉~接下來應該就會再往 2050 年之後邁進
  • 2019/10/19 0.6.4版本提供了此年的閏月是哪一個月份的查詢,新增在AdvancedLunar
  • 2019/10/18 0.6.2版本提供了十神的查詢,新增在ApplicationLunar,所以要使用此方法需 new ApplicationLunar()。
  • 2019/10/17 0.6.0版本提供了生肖的查詢。
  • 2019/10/16 0.5.0版本提供了.getJson()的方法讓大家可以方便取得所有資訊。

使用範例

npm i @tony801015/chinese-lunar -S

預設使用方式

const lunar = require("@tony801015/chinese-lunar");
console.log(lunar().getJson()); // 抓取目前的年,月,日

自定日期

const lunar = require("@tony801015/chinese-lunar");
console.log(lunar("2020", "01", "09").getJson()); 

取得參數

const lunar = require("@tony801015/chinese-lunar");
const data = lunar("2020", "01", "09").getJson();
console.log(data.year); // 2020
console.log(data.week); // 4
console.log(data.constellation); // 魔羯座

提供特殊方法

setTime() 自訂時間

如果沒有輸入,程式會抓取當前時間

const lunar = require("@tony801015/chinese-lunar");
const data = lunar('2021', '02', '13')
  .setTime('00')
  .getJson();
console.log(data.chineseTime); // 庚子

setChineseAge() 自訂出生年(天干地支)

如果沒有輸入程式會顯示提醒 請輸入年齡

const lunar = require("@tony801015/chinese-lunar");
const data = lunar('2021', '02', '13') // 出生年月日
  .setTime('00') // 出生時
  .setChineseAge('壬子') // 出生年
  .getJson();
console.log(data.chineseYearTenGod); // 印
console.log(data.chineseMonthTenGod); // ㄗ
console.log(data.chineseDayTenGod); // 比
console.log(data.chineseTimeTenGod); // ㄗ

// 這樣簡單的八字計算就出來囉。 歡迎自己算算看唷~ console.log(年=> ${data.chineseYear}, 十神=> ${data.chineseYearTenGod}); // 年=> 辛丑, 十神=> 印 console.log(月=> ${data.chineseMonth}, 十神=> ${data.chineseMonthTenGod}); // 月=> 庚寅, 十神=> ㄗ console.log(日=> ${data.chineseDay}, 十神=> ${data.chineseDayTenGod}); // 日=> 壬辰, 十神=> 比 console.log(時=> ${data.chineseTime}, 十神=> ${data.chineseTimeTenGod}); // 時=> 庚子, 十神=> ㄗ

#### lunarToSolar() 農曆轉公(國)曆
```js
const lunar = require("@tony801015/chinese-lunar");
const data = lunar(
  '2020', '04', '16'
)
  .lunarToSolar() 
  // 如果有遇到閏月,要轉國曆請記得加true, 不然預設都會是false 非閏月的月份
  // lunarToSolar({{true|false}})
  .setTime('00')
  .setChineseAge('壬子')
  .getJson();
console.log(`農曆月=> ${data.lunarMonth}, 農曆日=> ${data.lunarDay}`); 
// 農曆月=> 四月, 農曆日=> 十六
console.log(`國曆月=> ${data.month}, 國曆日=> ${data.day}`);
// 國曆月=> 05, 國曆日=> 08

getSolarTermDistance() 查看距離上(下)一個節氣天數

const lunar = require("@tony801015/chinese-lunar");
const data = lunar(
  '2019', '07', '07'
).getSolarTermDistance();
// 因節氣會看到小時,這裡有提供 diffDistanceDetail 這個參數再乘上24即可得知幾個小時
// { previous: 
//    { solarTerm: '夏至',
//      diffDistanceDay: 16,
//      diffDistanceDetail: 15.004062500000002 },
//   next: 
//    { solarTerm: '大暑',
//      diffDistanceDay: 16,
//      diffDistanceDetail: 16.451574074074074 } }

subtract()、add() 計算加減

const lunar = require("@tony801015/chinese-lunar");
const demoAdd = lunar('2019', '07', '07').add(1,'d').day // 08
const demoSubtract = lunar('2019', '07', '07').subtract(1,'d').day // 06
// add()與subtract()這背後是使用moment.js這個好用的套件所完成的,因此有用過moment.js的朋友一定不陌生

兩個method的文件如下:
subtract() 減的使用方式
add() 加的使用方式

紫白與納音

const lunar = require("@tony801015/chinese-lunar");
lunar('2020', '02', '21').getNayin(); // 土

lunar('2020', '02', '21').getPurpleWhites(); 
// [ '八白', '七赤', '六白', '五黃', '四綠', '三碧', '二黑', '一白', '九紫', '八白', '七赤', '六白' ]

胎元,命宮,身宮,藏幹,副星

const lunar = require("@tony801015/chinese-lunar");
// 身宮
lunar('2020', '04', '05').getShenGong(); // 戊子
// 命宮
lunar('2020', '04', '05').getMingGong(); // 壬午
// 空亡
lunar('2020', '04', '05').getKongWang('子', '甲');  // 戌亥
// 藏幹
lunar('2020', '04', '05').getCangGan('子'); // 癸
// 胎元
lunar('2020', '04', '05').getTaiYuan(); // 辛未

使用getJson()會得到以下參數

中文名稱參數名稱型態範例備註
yearstring2020
monthstring01
daystring09
節氣solarTermsstring小寒
農曆月lunarMonthstring腊月
農曆日lunarDaystring十五
農曆月數值lunarMonthDigitnumber12
農曆日數值lunarDayDigitnumber15
當前農曆月份是否閏月isLunarLeapMonthbooleanfalse
當年閏幾月leapMonthnumber0
年柱chineseYearstring己亥
月柱chineseMonthstring丁丑
日柱chineseDaystring辛亥
時柱chineseTimestring戊子需要先 setTime() 如果沒有就會是目前的時間
年柱十神chineseYearTenGodstring需要先 setChineseAge()
月柱十神chineseMonthTenGodstring需要先 setChineseAge()
日柱十神chineseDayTenGodstring需要先 setChineseAge()
時柱十神chineseTimeTenGodstring需要先 setChineseAge()
時柱十神清單chineseTimesTenGodarray 'ㄗ', '印', '比', '劫', '食', '傷', '才', '財', '殺', '官', 'ㄗ', '印' 需要先 setChineseAge()
時柱清單chineseTimesarray '戊子', '己丑', '庚寅', '辛卯', '壬辰', '癸巳', '甲午', '乙未', '丙申', '丁酉', '戊戌', '己亥'
星期weekstring4
生肖animalstring
星座constellationstring魔羯座
國曆二月是否有閏月chineseFebbooleantrue
登貴dengGuistring戌午
農曆潤幾月leapMonthnumber4
農曆每月有幾日lunarPerMonthHasDaysarray '29','30','30','30','29','30','29','29','30','29','30','29','30'

分享

設定檔 config.js 裡面有一些整理過的資訊,希望可以幫助到大家對於命理上的研究。歡迎大家找我討論~

注意事項

  • 目前計算的時間以 1900 年開始至 2050 年,1900 以前的都無法計算。

未來規劃

未來會再增加

  • 星座 BasicLunar 2019/10/23 完成 0.8.0
  • 此年的閏月是幾月 AdvancedLunar 2019/10/19 完成 0.6.4
  • 此年的農曆中每個月有多少天 AdvancedLunar 2019/10/24 完成 0.9.0
  • 農曆日期的差距有幾天 ApplicationLunar
  • 十神的查詢 ApplicationLunar 2019/10/17 完成 0.6.2
  • 提供時間的輸入,在八字裡面其實就是把,,,轉成年柱,月柱,日柱,時柱,因此要把八字更精準推出命理相關的數據,需要的協助囉。 2020/01/18 完成 0.13.0
  • 輸入農曆轉換成國曆 2020/1/25 完成 0.14.0
  • 製作前端使用js 2020/1/25 完成 0.14.3
  • 加強節氣資訊,距離前(後)節氣天數 2020/2/2 完成 0.15.0
  • 加減 subtract(), add() 2020/02/08 完成 0.16.0
  • 取得紫白九星的方法 2020/02/21 完成 0.17.0
  • 取得納音屬性 2020/02/21 完成 0.17.0
  • 提供「農曆的日期」數字的形式呈現 #7 感謝 @creatxrgithub 大大提供建議 0.17.3
  • 提供胎元,命宮,身宮,藏幹,副星 0.18.0
  • 支援較舊的版本 IOS6 感謝 @921010wxm 大大提供建議 0.20.0 #16
  • 製作萬年曆
  • 查詢農曆年的API
  • 查詢流年,流月,大運
  • 建立使用手冊
0.20.2

4 years ago

0.20.1

4 years ago

0.20.0

4 years ago

0.19.0-beta

4 years ago

0.19.0

5 years ago

0.18.5

5 years ago

0.18.4

5 years ago

0.18.3

5 years ago

0.18.2

5 years ago

0.18.1

5 years ago

0.18.0

5 years ago

0.17.3

5 years ago

0.17.2

5 years ago

0.17.0

5 years ago

0.17.1

5 years ago

0.16.0

5 years ago

0.16.1

5 years ago

0.15.0

5 years ago

0.15.1

5 years ago

0.14.4

5 years ago

0.14.2

5 years ago

0.14.3

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.0

5 years ago

0.12.4

6 years ago

0.12.3

6 years ago

0.12.2-beta

6 years ago

0.12.1-beta

6 years ago

0.12.0-beta

6 years ago

0.11.4

6 years ago

0.11.3

6 years ago

0.11.2

6 years ago

0.11.1

6 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.3

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago