@gracefullight/saju 0.2.0 → 0.3.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.
Files changed (45) hide show
  1. package/README.en.md +250 -28
  2. package/README.md +250 -28
  3. package/dist/__tests__/luck.test.d.ts +2 -0
  4. package/dist/__tests__/luck.test.d.ts.map +1 -0
  5. package/dist/__tests__/luck.test.js +33 -0
  6. package/dist/__tests__/relations.test.d.ts +2 -0
  7. package/dist/__tests__/relations.test.d.ts.map +1 -0
  8. package/dist/__tests__/relations.test.js +90 -0
  9. package/dist/__tests__/saju.test.d.ts +2 -0
  10. package/dist/__tests__/saju.test.d.ts.map +1 -0
  11. package/dist/__tests__/saju.test.js +133 -0
  12. package/dist/__tests__/solar-terms.test.d.ts +2 -0
  13. package/dist/__tests__/solar-terms.test.d.ts.map +1 -0
  14. package/dist/__tests__/solar-terms.test.js +121 -0
  15. package/dist/__tests__/strength.test.d.ts +2 -0
  16. package/dist/__tests__/strength.test.d.ts.map +1 -0
  17. package/dist/__tests__/strength.test.js +44 -0
  18. package/dist/__tests__/ten-gods.test.d.ts +2 -0
  19. package/dist/__tests__/ten-gods.test.d.ts.map +1 -0
  20. package/dist/__tests__/ten-gods.test.js +119 -0
  21. package/dist/__tests__/yongshen.test.d.ts +2 -0
  22. package/dist/__tests__/yongshen.test.d.ts.map +1 -0
  23. package/dist/__tests__/yongshen.test.js +62 -0
  24. package/dist/core/luck.d.ts +41 -0
  25. package/dist/core/luck.d.ts.map +1 -0
  26. package/dist/core/luck.js +96 -0
  27. package/dist/core/relations.d.ts +94 -0
  28. package/dist/core/relations.d.ts.map +1 -0
  29. package/dist/core/relations.js +305 -0
  30. package/dist/core/solar-terms.d.ts +155 -0
  31. package/dist/core/solar-terms.d.ts.map +1 -0
  32. package/dist/core/solar-terms.js +266 -0
  33. package/dist/core/strength.d.ts +18 -0
  34. package/dist/core/strength.d.ts.map +1 -0
  35. package/dist/core/strength.js +255 -0
  36. package/dist/core/ten-gods.d.ts +130 -0
  37. package/dist/core/ten-gods.d.ts.map +1 -0
  38. package/dist/core/ten-gods.js +335 -0
  39. package/dist/core/yongshen.d.ts +20 -0
  40. package/dist/core/yongshen.d.ts.map +1 -0
  41. package/dist/core/yongshen.js +216 -0
  42. package/dist/index.d.ts +53 -0
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +47 -0
  45. package/package.json +12 -12
package/README.en.md CHANGED
@@ -15,7 +15,13 @@
15
15
  - **Solar Time Correction** - Optional mean solar time adjustment based on longitude
16
16
  - **Tree-shakeable** - Import only what you need
17
17
  - **Fully Typed** - Complete TypeScript definitions
18
- - **Well Tested** - 85+ tests with 91%+ coverage
18
+ - **Well Tested** - 180+ tests with 91%+ coverage
19
+ - **Ten Gods Analysis** - Detailed ten gods and five elements distribution with hidden stems
20
+ - **Strength Assessment** - 9-level strength analysis with monthly strength (得令), root strength (通根), transparency (透干), and hidden stem weights (本中餘氣)
21
+ - **Relations Analysis** - Combinations, clashes, harms, punishments with transformation (化) status and conditions
22
+ - **Major/Yearly Luck** - Solar term (節氣) based accurate luck start calculation, major luck and yearly luck based on gender and year pillar
23
+ - **Yongshen Extraction** - Favorable element recommendation following 格局→抑扶→調候 priority with fortune enhancement guide
24
+ - **Solar Terms Analysis** - Current/next solar term info with elapsed days calculation
19
25
 
20
26
  ## What is Saju (四柱)?
21
27
 
@@ -56,6 +62,39 @@ pnpm add date-fns date-fns-tz
56
62
 
57
63
  ## Quick Start
58
64
 
65
+ ```typescript
66
+ import { DateTime } from "luxon";
67
+ import { createLuxonAdapter } from "@gracefullight/saju/adapters/luxon";
68
+ import { getSaju, STANDARD_PRESET } from "@gracefullight/saju";
69
+
70
+ const adapter = await createLuxonAdapter();
71
+
72
+ const birthDateTime = DateTime.fromObject(
73
+ { year: 2000, month: 1, day: 1, hour: 18, minute: 0 },
74
+ { zone: "Asia/Seoul" }
75
+ );
76
+
77
+ // getSaju: Calculate pillars, ten gods, strength, relations, yongshen, solar terms, major luck, yearly luck all at once
78
+ const result = getSaju(adapter, birthDateTime, {
79
+ longitudeDeg: 126.9778,
80
+ gender: "male", // Required: needed for major luck calculation
81
+ preset: STANDARD_PRESET,
82
+ currentYear: 2024, // For default yearly luck range (optional)
83
+ yearlyLuckRange: { from: 2024, to: 2030 }, // Specify yearly luck range directly (optional)
84
+ });
85
+
86
+ console.log(result.pillars); // { year: "己卯", month: "丙子", ... }
87
+ console.log(result.tenGods); // Ten gods and hidden stems analysis
88
+ console.log(result.strength); // Strength assessment (e.g., "weak")
89
+ console.log(result.relations); // Relations analysis
90
+ console.log(result.yongShen); // Yongshen and fortune tips
91
+ console.log(result.solarTerms); // Solar term info (current/next term, elapsed days)
92
+ console.log(result.majorLuck); // Major luck info
93
+ console.log(result.yearlyLuck); // Yearly luck info
94
+ ```
95
+
96
+ ### Calculate Four Pillars Only
97
+
59
98
  ```typescript
60
99
  import { DateTime } from "luxon";
61
100
  import { createLuxonAdapter } from "@gracefullight/saju/adapters/luxon";
@@ -74,24 +113,6 @@ const result = getFourPillars(adapter, birthDateTime, {
74
113
  });
75
114
 
76
115
  console.log(result);
77
- // {
78
- // year: "己卯", // Year Pillar (Heavenly Stem + Earthly Branch)
79
- // month: "丙子", // Month Pillar
80
- // day: "辛巳", // Day Pillar
81
- // hour: "戊戌", // Hour Pillar
82
- // lunar: {
83
- // lunarYear: 1999,
84
- // lunarMonth: 11,
85
- // lunarDay: 25,
86
- // isLeapMonth: false
87
- // },
88
- // meta: {
89
- // solarYearUsed: 1999,
90
- // sunLonDeg: 280.9,
91
- // effectiveDayDate: { year: 2000, month: 1, day: 1 },
92
- // adjustedDtForHour: "2000-01-01T18:00:00.000+09:00"
93
- // }
94
- // }
95
116
  ```
96
117
 
97
118
  ## Usage
@@ -206,12 +227,27 @@ Traditional interpretation with Zi hour (23:00) day boundary and solar time corr
206
227
  }
207
228
  ```
208
229
 
209
- #### Deprecated Aliases
210
- - `presetA` → Use `STANDARD_PRESET`
211
- - `presetB` → Use `TRADITIONAL_PRESET`
212
-
213
230
  ### Core Functions
214
231
 
232
+ #### `getSaju(adapter, datetime, options)`
233
+
234
+ Calculate all saju analysis results (pillars, ten gods, strength, relations, yongshen, solar terms, major luck, yearly luck) at once.
235
+
236
+ ```typescript
237
+ function getSaju<T>(
238
+ adapter: DateAdapter<T>,
239
+ dtLocal: T,
240
+ options: {
241
+ longitudeDeg: number;
242
+ gender: "male" | "female"; // Required
243
+ tzOffsetHours?: number;
244
+ preset?: typeof STANDARD_PRESET;
245
+ currentYear?: number; // For default yearly luck range
246
+ yearlyLuckRange?: { from: number; to: number }; // Specify yearly luck range directly
247
+ }
248
+ ): SajuResult;
249
+ ```
250
+
215
251
  #### `getFourPillars(adapter, datetime, options)`
216
252
 
217
253
  Calculate all four pillars (year, month, day, hour).
@@ -425,6 +461,109 @@ function effectiveDayDate<T>(
425
461
  }
426
462
  ```
427
463
 
464
+ ### Analysis Functions
465
+
466
+ #### `analyzeTenGods(year, month, day, hour)`
467
+
468
+ Analyzes ten gods and hidden stems of the four pillars.
469
+
470
+ ```typescript
471
+ function analyzeTenGods(
472
+ year: string,
473
+ month: string,
474
+ day: string,
475
+ hour: string
476
+ ): FourPillarsTenGods;
477
+ ```
478
+
479
+ #### `analyzeStrength(year, month, day, hour)`
480
+
481
+ Assesses the strength of the day master on a 7-level scale.
482
+
483
+ ```typescript
484
+ function analyzeStrength(
485
+ year: string,
486
+ month: string,
487
+ day: string,
488
+ hour: string
489
+ ): StrengthResult;
490
+ ```
491
+
492
+ #### `analyzeRelations(year, month, day, hour)`
493
+
494
+ Analyzes combinations, clashes, harms, and punishments between stems and branches.
495
+
496
+ ```typescript
497
+ function analyzeRelations(
498
+ year: string,
499
+ month: string,
500
+ day: string,
501
+ hour: string
502
+ ): RelationsResult;
503
+ ```
504
+
505
+ #### `calculateMajorLuck(adapter, datetime, gender, year, month)`
506
+
507
+ Calculates major luck periods and starting age.
508
+
509
+ ```typescript
510
+ function calculateMajorLuck<T>(
511
+ adapter: DateAdapter<T>,
512
+ birthDateTime: T,
513
+ gender: "male" | "female",
514
+ yearPillar: string,
515
+ monthPillar: string
516
+ ): MajorLuckResult;
517
+ ```
518
+
519
+ #### `analyzeYongShen(year, month, day, hour)`
520
+
521
+ Extracts favorable elements considering suppression and climate adjustment.
522
+
523
+ ```typescript
524
+ function analyzeYongShen(
525
+ year: string,
526
+ month: string,
527
+ day: string,
528
+ hour: string
529
+ ): YongShenResult;
530
+ ```
531
+
532
+ #### `analyzeSolarTerms(adapter, datetime)`
533
+
534
+ Calculates current and next solar term info with elapsed days.
535
+
536
+ ```typescript
537
+ function analyzeSolarTerms<T>(
538
+ adapter: DateAdapter<T>,
539
+ dtLocal: T
540
+ ): SolarTermInfo;
541
+ ```
542
+
543
+ **Returns:**
544
+ ```typescript
545
+ {
546
+ current: { name: "소한", hanja: "小寒", longitude: 285 },
547
+ currentDate: { year: 2024, month: 1, day: 6, hour: 5, minute: 30 },
548
+ daysSinceCurrent: 5,
549
+ next: { name: "대한", hanja: "大寒", longitude: 300 },
550
+ nextDate: { year: 2024, month: 1, day: 20, hour: 12, minute: 15 },
551
+ daysUntilNext: 10
552
+ }
553
+ ```
554
+
555
+ #### `getSolarTermsForYear(adapter, year, timezone)`
556
+
557
+ Calculates all 24 solar terms for a specific year.
558
+
559
+ ```typescript
560
+ function getSolarTermsForYear<T>(
561
+ adapter: DateAdapter<T>,
562
+ year: number,
563
+ timezone: string
564
+ ): Array<{ term: SolarTerm; date: {...} }>;
565
+ ```
566
+
428
567
  ## Advanced Usage
429
568
 
430
569
  ### Solar Time Correction
@@ -499,6 +638,85 @@ Common city longitudes for reference:
499
638
 
500
639
  ## Examples
501
640
 
641
+ ### Major and Yearly Luck Calculation
642
+
643
+ ```typescript
644
+ const saju = getSaju(adapter, dt, {
645
+ longitudeDeg: 126.9778,
646
+ gender: "female",
647
+ yearlyLuckRange: { from: 2024, to: 2030 }
648
+ });
649
+
650
+ // Check major luck
651
+ console.log(saju.majorLuck.pillars); // Major luck pillars list
652
+ console.log(saju.majorLuck.startAge); // Starting age for major luck
653
+
654
+ // Check yearly luck
655
+ saju.yearlyLuck.forEach(luck => {
656
+ console.log(`Year ${luck.year} (${luck.pillar}): Age ${luck.age}`);
657
+ });
658
+ ```
659
+
660
+ ### Solar Terms Info
661
+
662
+ ```typescript
663
+ const saju = getSaju(adapter, dt, {
664
+ longitudeDeg: 126.9778,
665
+ gender: "male",
666
+ });
667
+
668
+ // Current solar term
669
+ console.log(saju.solarTerms.current.name); // "소한"
670
+ console.log(saju.solarTerms.current.hanja); // "小寒"
671
+ console.log(saju.solarTerms.daysSinceCurrent); // 5 (days since term started)
672
+
673
+ // Next solar term
674
+ console.log(saju.solarTerms.next.name); // "대한"
675
+ console.log(saju.solarTerms.daysUntilNext); // 10 (days until next term)
676
+
677
+ // Solar term dates
678
+ console.log(saju.solarTerms.currentDate); // { year: 2024, month: 1, day: 6, ... }
679
+ console.log(saju.solarTerms.nextDate); // { year: 2024, month: 1, day: 20, ... }
680
+ ```
681
+
682
+ ### Ten Gods and Five Elements Analysis
683
+
684
+ ```typescript
685
+ import { analyzeTenGods, countElements } from "@gracefullight/saju";
686
+
687
+ const tenGods = analyzeTenGods("己卯", "丙子", "辛巳", "戊戌");
688
+ console.log(tenGods.dayMaster); // "辛"
689
+
690
+ const elements = countElements(tenGods);
691
+ console.log(elements); // { wood: 1, fire: 1, earth: 3, metal: 1, water: 2 }
692
+ ```
693
+
694
+ ### Strength and Yongshen Analysis
695
+
696
+ ```typescript
697
+ import { analyzeStrength, analyzeYongShen, getElementRecommendations } from "@gracefullight/saju";
698
+
699
+ const strength = analyzeStrength("己卯", "丙子", "辛巳", "戊戌");
700
+ console.log(strength.level); // "weak"
701
+
702
+ const yongShen = analyzeYongShen("己卯", "丙子", "辛巳", "戊戌");
703
+ console.log(yongShen.primary); // Favorable element (e.g., "earth")
704
+
705
+ const tips = getElementRecommendations(yongShen);
706
+ console.log(tips.colors); // Lucky colors
707
+ ```
708
+
709
+ ### Relations Analysis
710
+
711
+ ```typescript
712
+ import { analyzeRelations } from "@gracefullight/saju";
713
+
714
+ const relations = analyzeRelations("己卯", "丙子", "辛巳", "戊戌");
715
+ relations.clashes.forEach(c => {
716
+ console.log(`${c.positions[0]}-${c.positions[1]} branch clash: ${c.pair[0]}-${c.pair[1]}`);
717
+ });
718
+ ```
719
+
502
720
  ### Calculate for Different Timezones
503
721
 
504
722
  ```typescript
@@ -606,7 +824,15 @@ packages/saju/
606
824
  │ │ ├── luxon.ts # Luxon adapter
607
825
  │ │ └── date-fns.ts # date-fns adapter
608
826
  │ ├── core/ # Core calculation logic
609
- │ │ └── four-pillars.ts # Main algorithms
827
+ │ │ ├── four-pillars.ts # Four pillars calculation
828
+ │ │ ├── ten-gods.ts # Ten gods analysis
829
+ │ │ ├── strength.ts # Strength assessment
830
+ │ │ ├── relations.ts # Relations analysis
831
+ │ │ ├── luck.ts # Major/yearly luck
832
+ │ │ ├── yongshen.ts # Yongshen extraction
833
+ │ │ ├── solar-terms.ts # Solar terms calculation
834
+ │ │ └── lunar.ts # Lunar conversion
835
+ │ ├── types/ # Type definitions
610
836
  │ ├── __tests__/ # Test suites
611
837
  │ └── index.ts # Public API
612
838
  ├── dist/ # Compiled output
@@ -723,7 +949,3 @@ This library is based on traditional Chinese calendar algorithms and astronomica
723
949
  - [Documentation](https://github.com/gracefullight/saju#readme)
724
950
  - [Issue Tracker](https://github.com/gracefullight/saju/issues)
725
951
  - [Discussions](https://github.com/gracefullight/saju/discussions)
726
-
727
- ---
728
-
729
- Made by [gracefullight](https://github.com/gracefullight)
package/README.md CHANGED
@@ -15,7 +15,13 @@
15
15
  - **태양시 보정** - 경도 기반 평균 태양시 조정 옵션
16
16
  - **트리쉐이킹 지원** - 필요한 것만 import
17
17
  - **완전한 타입 지원** - TypeScript 정의 완비
18
- - **풍부한 테스트** - 85개 이상 테스트, 91% 이상 커버리지
18
+ - **풍부한 테스트** - 180개 이상 테스트, 91% 이상 커버리지
19
+ - **십신 분석** - 장간(藏干)을 포함한 상세 십신 및 오행 분포 분석
20
+ - **신강/신약 판정** - 월령 득령(得令), 통근(通根), 투간(透干), 본중여기(本中餘氣) 가중치를 고려한 9단계 신강도 분석
21
+ - **합충형파해** - 천간합, 육합, 삼합, 방합 및 충, 해, 형, 파 분석. 합(合)과 화(化) 성립 조건 분리 표기
22
+ - **대운/세운 계산** - 절기(節氣) 기반 정확한 기운(起運) 계산, 성별 및 연간 음양을 고려한 대운 및 연도별 세운 계산
23
+ - **용신 추출** - 격국(格局), 억부(抑扶), 조후(調候) 순서로 용신 추천 및 개운법 가이드
24
+ - **절기 분석** - 현재/다음 절기 정보 및 경과일 계산
19
25
 
20
26
  ## 사주(四柱)란?
21
27
 
@@ -56,6 +62,39 @@ pnpm add date-fns date-fns-tz
56
62
 
57
63
  ## 빠른 시작
58
64
 
65
+ ```typescript
66
+ import { DateTime } from "luxon";
67
+ import { createLuxonAdapter } from "@gracefullight/saju/adapters/luxon";
68
+ import { getSaju, STANDARD_PRESET } from "@gracefullight/saju";
69
+
70
+ const adapter = await createLuxonAdapter();
71
+
72
+ const birthDateTime = DateTime.fromObject(
73
+ { year: 2000, month: 1, day: 1, hour: 18, minute: 0 },
74
+ { zone: "Asia/Seoul" }
75
+ );
76
+
77
+ // getSaju: 사주 팔자, 십신, 신강약, 합충, 용신, 절기, 대운, 세운을 한 번에 계산
78
+ const result = getSaju(adapter, birthDateTime, {
79
+ longitudeDeg: 126.9778,
80
+ gender: "male", // 필수: 대운 계산에 필요
81
+ preset: STANDARD_PRESET,
82
+ currentYear: 2024, // 세운 기본 범위 계산용 (선택)
83
+ yearlyLuckRange: { from: 2024, to: 2030 }, // 세운 범위 직접 지정 (선택)
84
+ });
85
+
86
+ console.log(result.pillars); // { year: "己卯", month: "丙子", ... }
87
+ console.log(result.tenGods); // 십신 및 장간 분석
88
+ console.log(result.strength); // 신강/신약 판정 (예: "신약")
89
+ console.log(result.relations); // 합충형파해 분석
90
+ console.log(result.yongShen); // 용신 및 개운법
91
+ console.log(result.solarTerms); // 절기 정보 (현재/다음 절기, 경과일)
92
+ console.log(result.majorLuck); // 대운 정보
93
+ console.log(result.yearlyLuck); // 세운 정보
94
+ ```
95
+
96
+ ### 사주 팔자만 계산하기
97
+
59
98
  ```typescript
60
99
  import { DateTime } from "luxon";
61
100
  import { createLuxonAdapter } from "@gracefullight/saju/adapters/luxon";
@@ -74,24 +113,6 @@ const result = getFourPillars(adapter, birthDateTime, {
74
113
  });
75
114
 
76
115
  console.log(result);
77
- // {
78
- // year: "己卯", // 연주 (천간 + 지지)
79
- // month: "丙子", // 월주
80
- // day: "辛巳", // 일주
81
- // hour: "戊戌", // 시주
82
- // lunar: {
83
- // lunarYear: 1999,
84
- // lunarMonth: 11,
85
- // lunarDay: 25,
86
- // isLeapMonth: false
87
- // },
88
- // meta: {
89
- // solarYearUsed: 1999,
90
- // sunLonDeg: 280.9,
91
- // effectiveDayDate: { year: 2000, month: 1, day: 1 },
92
- // adjustedDtForHour: "2000-01-01T18:00:00.000+09:00"
93
- // }
94
- // }
95
116
  ```
96
117
 
97
118
  ## 사용법
@@ -206,12 +227,27 @@ const myAdapter: DateAdapter<MyDateType> = {
206
227
  }
207
228
  ```
208
229
 
209
- #### 사용 중단된 별칭
210
- - `presetA` → `STANDARD_PRESET` 사용 권장
211
- - `presetB` → `TRADITIONAL_PRESET` 사용 권장
212
-
213
230
  ### 핵심 함수
214
231
 
232
+ #### `getSaju(adapter, datetime, options)`
233
+
234
+ 사주 분석의 모든 결과(팔자, 십신, 신강약, 합충, 용신, 대운)를 한 번에 계산합니다.
235
+
236
+ ```typescript
237
+ function getSaju<T>(
238
+ adapter: DateAdapter<T>,
239
+ dtLocal: T,
240
+ options: {
241
+ longitudeDeg: number;
242
+ gender: "male" | "female"; // 필수
243
+ tzOffsetHours?: number;
244
+ preset?: typeof STANDARD_PRESET;
245
+ currentYear?: number; // 세운 기본 범위 계산용
246
+ yearlyLuckRange?: { from: number; to: number }; // 세운 범위 직접 지정
247
+ }
248
+ ): SajuResult;
249
+ ```
250
+
215
251
  #### `getFourPillars(adapter, datetime, options)`
216
252
 
217
253
  네 기둥(연주, 월주, 일주, 시주) 모두 계산
@@ -425,6 +461,109 @@ function effectiveDayDate<T>(
425
461
  }
426
462
  ```
427
463
 
464
+ ### 분석 함수
465
+
466
+ #### `analyzeTenGods(year, month, day, hour)`
467
+
468
+ 사주 팔자의 십신과 지장간을 분석합니다.
469
+
470
+ ```typescript
471
+ function analyzeTenGods(
472
+ year: string,
473
+ month: string,
474
+ day: string,
475
+ hour: string
476
+ ): FourPillarsTenGods;
477
+ ```
478
+
479
+ #### `analyzeStrength(year, month, day, hour)`
480
+
481
+ 사주의 신강/신약을 9단계로 판정합니다.
482
+
483
+ ```typescript
484
+ function analyzeStrength(
485
+ year: string,
486
+ month: string,
487
+ day: string,
488
+ hour: string
489
+ ): StrengthResult;
490
+ ```
491
+
492
+ #### `analyzeRelations(year, month, day, hour)`
493
+
494
+ 천간과 지지의 합, 충, 형, 파, 해 관계를 분석합니다.
495
+
496
+ ```typescript
497
+ function analyzeRelations(
498
+ year: string,
499
+ month: string,
500
+ day: string,
501
+ hour: string
502
+ ): RelationsResult;
503
+ ```
504
+
505
+ #### `calculateMajorLuck(adapter, datetime, gender, year, month)`
506
+
507
+ 대운의 흐름과 시작 연령을 계산합니다.
508
+
509
+ ```typescript
510
+ function calculateMajorLuck<T>(
511
+ adapter: DateAdapter<T>,
512
+ birthDateTime: T,
513
+ gender: "male" | "female",
514
+ yearPillar: string,
515
+ monthPillar: string
516
+ ): MajorLuckResult;
517
+ ```
518
+
519
+ #### `analyzeYongShen(year, month, day, hour)`
520
+
521
+ 억부와 조후를 고려하여 용신과 희신을 추출합니다.
522
+
523
+ ```typescript
524
+ function analyzeYongShen(
525
+ year: string,
526
+ month: string,
527
+ day: string,
528
+ hour: string
529
+ ): YongShenResult;
530
+ ```
531
+
532
+ #### `analyzeSolarTerms(adapter, datetime)`
533
+
534
+ 현재 및 다음 절기 정보와 경과일을 계산합니다.
535
+
536
+ ```typescript
537
+ function analyzeSolarTerms<T>(
538
+ adapter: DateAdapter<T>,
539
+ dtLocal: T
540
+ ): SolarTermInfo;
541
+ ```
542
+
543
+ **반환값:**
544
+ ```typescript
545
+ {
546
+ current: { name: "소한", hanja: "小寒", longitude: 285 },
547
+ currentDate: { year: 2024, month: 1, day: 6, hour: 5, minute: 30 },
548
+ daysSinceCurrent: 5,
549
+ next: { name: "대한", hanja: "大寒", longitude: 300 },
550
+ nextDate: { year: 2024, month: 1, day: 20, hour: 12, minute: 15 },
551
+ daysUntilNext: 10
552
+ }
553
+ ```
554
+
555
+ #### `getSolarTermsForYear(adapter, year, timezone)`
556
+
557
+ 특정 연도의 24절기 날짜를 모두 계산합니다.
558
+
559
+ ```typescript
560
+ function getSolarTermsForYear<T>(
561
+ adapter: DateAdapter<T>,
562
+ year: number,
563
+ timezone: string
564
+ ): Array<{ term: SolarTerm; date: {...} }>;
565
+ ```
566
+
428
567
  ## 고급 사용법
429
568
 
430
569
  ### 태양시 보정
@@ -499,6 +638,85 @@ const result = getFourPillars(adapter, dt, {
499
638
 
500
639
  ## 예제
501
640
 
641
+ ### 대운과 세운 계산
642
+
643
+ ```typescript
644
+ const saju = getSaju(adapter, dt, {
645
+ longitudeDeg: 126.9778,
646
+ gender: "female",
647
+ yearlyLuckRange: { from: 2024, to: 2030 }
648
+ });
649
+
650
+ // 대운 확인
651
+ console.log(saju.majorLuck.pillars); // 대운 목록
652
+ console.log(saju.majorLuck.startAge); // 대운 시작 나이
653
+
654
+ // 세운 확인
655
+ saju.yearlyLuck.forEach(luck => {
656
+ console.log(`${luck.year}년(${luck.pillar}): ${luck.age}세`);
657
+ });
658
+ ```
659
+
660
+ ### 절기 정보 확인
661
+
662
+ ```typescript
663
+ const saju = getSaju(adapter, dt, {
664
+ longitudeDeg: 126.9778,
665
+ gender: "male",
666
+ });
667
+
668
+ // 현재 절기
669
+ console.log(saju.solarTerms.current.name); // "소한"
670
+ console.log(saju.solarTerms.current.hanja); // "小寒"
671
+ console.log(saju.solarTerms.daysSinceCurrent); // 5 (절기 경과일)
672
+
673
+ // 다음 절기
674
+ console.log(saju.solarTerms.next.name); // "대한"
675
+ console.log(saju.solarTerms.daysUntilNext); // 10 (다음 절기까지 남은 일)
676
+
677
+ // 절기 시작 날짜
678
+ console.log(saju.solarTerms.currentDate); // { year: 2024, month: 1, day: 6, ... }
679
+ console.log(saju.solarTerms.nextDate); // { year: 2024, month: 1, day: 20, ... }
680
+ ```
681
+
682
+ ### 십신 및 오행 분석
683
+
684
+ ```typescript
685
+ import { analyzeTenGods, countElements } from "@gracefullight/saju";
686
+
687
+ const tenGods = analyzeTenGods("己卯", "丙子", "辛巳", "戊戌");
688
+ console.log(tenGods.dayMaster); // "辛"
689
+
690
+ const elements = countElements(tenGods);
691
+ console.log(elements); // { wood: 1, fire: 1, earth: 3, metal: 1, water: 2 }
692
+ ```
693
+
694
+ ### 신강약 및 용신 분석
695
+
696
+ ```typescript
697
+ import { analyzeStrength, analyzeYongShen, getElementRecommendations } from "@gracefullight/saju";
698
+
699
+ const strength = analyzeStrength("己卯", "丙子", "辛巳", "戊戌");
700
+ console.log(strength.level); // "신약"
701
+
702
+ const yongShen = analyzeYongShen("己卯", "丙子", "辛巳", "戊戌");
703
+ console.log(yongShen.primary); // 용신 오행 (예: "earth")
704
+
705
+ const tips = getElementRecommendations(yongShen);
706
+ console.log(tips.colors); // 행운의 색상
707
+ ```
708
+
709
+ ### 합충형파해 분석
710
+
711
+ ```typescript
712
+ import { analyzeRelations } from "@gracefullight/saju";
713
+
714
+ const relations = analyzeRelations("己卯", "丙子", "辛巳", "戊戌");
715
+ relations.clashes.forEach(c => {
716
+ console.log(`${c.positions[0]}-${c.positions[1]} 지지 충: ${c.pair[0]}-${c.pair[1]}`);
717
+ });
718
+ ```
719
+
502
720
  ### 다양한 타임존에서 계산
503
721
 
504
722
  ```typescript
@@ -606,7 +824,15 @@ packages/saju/
606
824
  │ │ ├── luxon.ts # Luxon 어댑터
607
825
  │ │ └── date-fns.ts # date-fns 어댑터
608
826
  │ ├── core/ # 핵심 계산 로직
609
- │ │ └── four-pillars.ts # 메인 알고리즘
827
+ │ │ ├── four-pillars.ts # 사주 팔자 계산
828
+ │ │ ├── ten-gods.ts # 십신 분석
829
+ │ │ ├── strength.ts # 신강/신약 판정
830
+ │ │ ├── relations.ts # 합충형파해 분석
831
+ │ │ ├── luck.ts # 대운/세운 계산
832
+ │ │ ├── yongshen.ts # 용신 추출
833
+ │ │ ├── solar-terms.ts # 절기 계산
834
+ │ │ └── lunar.ts # 음력 변환
835
+ │ ├── types/ # 타입 정의
610
836
  │ ├── __tests__/ # 테스트 스위트
611
837
  │ └── index.ts # 공개 API
612
838
  ├── dist/ # 컴파일된 출력
@@ -723,7 +949,3 @@ MIT © [gracefullight](https://github.com/gracefullight)
723
949
  - [문서](https://github.com/gracefullight/saju#readme)
724
950
  - [이슈 트래커](https://github.com/gracefullight/saju/issues)
725
951
  - [토론](https://github.com/gracefullight/saju/discussions)
726
-
727
- ---
728
-
729
- Made by [gracefullight](https://github.com/gracefullight)
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=luck.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"luck.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/luck.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { calculateYearlyLuck, getYearPillar } from "@/core/luck";
3
+ describe("luck", () => {
4
+ describe("getYearPillar", () => {
5
+ it("returns correct pillar for 1984 (甲子)", () => {
6
+ expect(getYearPillar(1984)).toBe("甲子");
7
+ });
8
+ it("returns correct pillar for 2024 (甲辰)", () => {
9
+ expect(getYearPillar(2024)).toBe("甲辰");
10
+ });
11
+ it("returns correct pillar for 2000 (庚辰)", () => {
12
+ expect(getYearPillar(2000)).toBe("庚辰");
13
+ });
14
+ });
15
+ describe("calculateYearlyLuck", () => {
16
+ it("calculates yearly luck for a range", () => {
17
+ const result = calculateYearlyLuck(1990, 2020, 2025);
18
+ expect(result).toHaveLength(6);
19
+ expect(result[0].year).toBe(2020);
20
+ expect(result[5].year).toBe(2025);
21
+ });
22
+ it("includes correct age calculation", () => {
23
+ const result = calculateYearlyLuck(1990, 2020, 2020);
24
+ expect(result[0].age).toBe(31);
25
+ });
26
+ it("returns pillar, stem, and branch for each year", () => {
27
+ const result = calculateYearlyLuck(1990, 2024, 2024);
28
+ expect(result[0].pillar).toBe("甲辰");
29
+ expect(result[0].stem).toBe("甲");
30
+ expect(result[0].branch).toBe("辰");
31
+ });
32
+ });
33
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=relations.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relations.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/relations.test.ts"],"names":[],"mappings":""}