@solarita-sdk/typescript
v0.0.7
Published
A TypeScript SDK for calculating Chinese astrology (Kanshi) and zodiac signs with high-precision astronomical calculations using astronomy-engine (Node.js) and pure JavaScript fallback (mobile/web)
Downloads
185
Readme
solarita-sdk
A TypeScript SDK for calculating Chinese and Western astrology with high-precision calculations.
Installation
npm install solarita-sdkUsage
Basic Usage
import { getKanshi, getZodiac, getSolaritaType } from 'solarita-sdk';
// Create a Date object with birth date and time
const birthday = new Date('1990-05-15T14:30:00');
// Get Kanshi (Chinese astrology) information
const kanshi = getKanshi(birthday);
console.log(kanshi);
// Output:
// {
// yearStemType: "Steel",
// yearStemChar: "庚",
// yearStemCode: "6",
// yearAnimal: "Horse",
// yearAnimalChar: "午",
// yearAnimalCode: "a07",
// // ... more properties
// }
// Get Western astrology information
const zodiac = getZodiac(birthday);
console.log(zodiac);
// Output:
// {
// sunSign: "Taurus",
// sunCode: "b",
// moonSign: "Gemini",
// moonCode: "c",
// mercurySign: "Taurus",
// mercuryCode: "b",
// // ... more properties
// }
// Get Solarita type (combination of zodiac and day stem)
const solaritaType = getSolaritaType(birthday);
console.log(solaritaType);
// Output: "b6" (example)API Reference
getKanshi(birthday: Date): Kanshi
Calculates the Chinese astrology (Kanshi) information for a given birth date and time.
Parameters:
birthday: Date object containing birth date and time
Returns:
Kanshiobject containing:yearStemType,yearStemChar,yearStemCode: Year stem informationyearAnimal,yearAnimalChar,yearAnimalCode: Year animal informationmonthStemType,monthStemChar,monthStemCode: Month stem informationmonthAnimal,monthAnimalChar,monthAnimalCode: Month animal informationdayStemType,dayStemChar,dayStemCode: Day stem informationdayAnimal,dayAnimalChar,dayAnimalCode: Day animal informationhourStemType,hourStemChar,hourStemCode: Hour stem informationhourAnimal,hourAnimalChar,hourAnimalCode: Hour animal informationcolor: RGB color string corresponding todayStemType
getZodiac(birthday: Date, latitude?: number, longitude?: number): ZodiacInfo
Calculates the Western astrology information for a given birth date and location.
Parameters:
birthday: Date object containing birth date and timelatitude: Latitude of birth location (default: 35.6762 - Tokyo)longitude: Longitude of birth location (default: 139.6503 - Tokyo)
Returns:
ZodiacInfoobject containing:sunSign,sunCode: Sun sign informationmoonSign,moonCode: Moon sign informationmercurySign,mercuryCode: Mercury sign informationvenusSign,venusCode: Venus sign informationmarsSign,marsCode: Mars sign informationjupiterSign,jupiterCode: Jupiter sign informationsaturnSign,saturnCode: Saturn sign informationuranusSign,uranusCode: Uranus sign informationneptuneSign,neptuneCode: Neptune sign informationplutoSign,plutoCode: Pluto sign informationascendant,ascendantCode: Ascendant (rising sign) informationMC,MCCode: Midheaven (MC) informationnorthNode,northNodeCode: North Node information
getSolaritaType(birthday: Date): string
Calculates the Solarita type (combination of zodiac sign and day stem).
Parameters:
birthday: Date object containing birth date and time
Returns:
- String representing the Solarita type (e.g., "b6")
Types
Kanshi
type Kanshi = {
hourStemType: string;
hourStemChar: string;
hourStemCode: string;
dayStemType: string;
dayStemChar: string;
dayStemCode: string;
monthStemType: string;
monthStemChar: string;
monthStemCode: string;
yearStemType: string;
yearStemChar: string;
yearStemCode: string;
hourAnimal: string;
hourAnimalChar: string;
hourAnimalCode: string;
dayAnimal: string;
dayAnimalChar: string;
dayAnimalCode: string;
monthAnimal: string;
monthAnimalChar: string;
monthAnimalCode: string;
yearAnimal: string;
yearAnimalChar: string;
yearAnimalCode: string;
/** RGB color corresponding to dayStemType */
color: string;
};ZodiacInfo
type ZodiacInfo = {
sunSign: string;
sunCode: string;
moonSign: string;
moonCode: string;
mercurySign: string;
mercuryCode: string;
venusSign: string;
venusCode: string;
marsSign: string;
marsCode: string;
jupiterSign: string;
jupiterCode: string;
saturnSign: string;
saturnCode: string;
uranusSign: string;
uranusCode: string;
neptuneSign: string;
neptuneCode: string;
plutoSign: string;
plutoCode: string;
ascendant: string;
ascendantCode: string;
MC: string;
MCCode: string;
northNode: string;
northNodeCode: string;
};Features
- High Precision: Uses astronomy-engine for accurate astronomical calculations
- Chinese Astrology: Complete Kanshi (Four Pillars) calculations
- Western Astrology: All major planets and points including Ascendant, MC, and North Node
- TypeScript Support: Full type definitions included
- Location Support: Customizable latitude/longitude for accurate house calculations
- Performance: Optimized calculations for both Node.js and mobile/web environments
Development
Building
npm run buildTesting
npm testType Checking
npm run typecheckPublishing
Important: Supabase Functions import this SDK via npm. After making changes to the SDK, you must publish a new version to npm to ensure the functions use the updated code.
# Update version in package.json
npm version patch # or minor/major
# Build and publish
npm run build
npm publishLicense
MIT
