@swisseph/node 1.0.6 → 1.2.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.
package/README.md CHANGED
@@ -42,7 +42,7 @@ npm install --global windows-build-tools
42
42
 
43
43
  ```typescript
44
44
  import {
45
- julianDay,
45
+ dateToJulianDay,
46
46
  calculatePosition,
47
47
  calculateHouses,
48
48
  Planet,
@@ -51,8 +51,9 @@ import {
51
51
 
52
52
  // No setup required! Ephemeris files are bundled and auto-loaded.
53
53
 
54
- // Calculate planetary position
55
- const jd = julianDay(2007, 3, 3);
54
+ // Calculate planetary position using Date object
55
+ const date = new Date('2007-03-03T00:00:00Z');
56
+ const jd = dateToJulianDay(date);
56
57
  const sun = calculatePosition(jd, Planet.Sun);
57
58
  console.log(`Sun: ${sun.longitude}°`);
58
59
 
@@ -67,10 +68,28 @@ console.log(`MC: ${houses.mc}°`);
67
68
  ### Date & Time
68
69
 
69
70
  ```typescript
71
+ // Convert JavaScript Date to Julian day (recommended)
72
+ dateToJulianDay(date, calendarType?)
73
+
74
+ // Convert date components to Julian day
70
75
  julianDay(year, month, day, hour?, calendarType?)
76
+
77
+ // Convert Julian day back to date
71
78
  julianDayToDate(jd, calendarType?)
72
79
  ```
73
80
 
81
+ **Examples:**
82
+ ```typescript
83
+ // Using Date object (easiest)
84
+ const jd = dateToJulianDay(new Date('1990-05-15T14:30:00Z'));
85
+
86
+ // Using date components
87
+ const jd2 = julianDay(1990, 5, 15, 14.5); // Same result
88
+
89
+ // Current time
90
+ const now = dateToJulianDay(new Date());
91
+ ```
92
+
74
93
  ### Planetary Positions
75
94
 
76
95
  ```typescript
@@ -147,7 +166,7 @@ import {
147
166
 
148
167
  ```typescript
149
168
  import {
150
- julianDay,
169
+ dateToJulianDay,
151
170
  calculatePosition,
152
171
  calculateHouses,
153
172
  Planet,
@@ -156,7 +175,8 @@ import {
156
175
  } from '@swisseph/node';
157
176
 
158
177
  // Birth: May 15, 1990, 14:30 UTC, New York (40.7128°N, 74.0060°W)
159
- const jd = julianDay(1990, 5, 15, 14.5);
178
+ const birthDate = new Date('1990-05-15T14:30:00Z');
179
+ const jd = dateToJulianDay(birthDate);
160
180
 
161
181
  // Calculate all planet positions
162
182
  const planets = [
@@ -220,9 +240,10 @@ close();
220
240
  ### Planetary Aspects
221
241
 
222
242
  ```typescript
223
- import { julianDay, calculatePosition, Planet, close } from '@swisseph/node';
243
+ import { dateToJulianDay, calculatePosition, Planet, close } from '@swisseph/node';
224
244
 
225
- const jd = julianDay(2025, 6, 15);
245
+ // Calculate for current time
246
+ const jd = dateToJulianDay(new Date());
226
247
 
227
248
  // Calculate positions
228
249
  const sun = calculatePosition(jd, Planet.Sun);
@@ -249,6 +249,115 @@ Napi::Value Houses(const Napi::CallbackInfo& info) {
249
249
  return result;
250
250
  }
251
251
 
252
+ // Wrapper for swe_set_sid_mode
253
+ Napi::Value SetSidMode(const Napi::CallbackInfo& info) {
254
+ Napi::Env env = info.Env();
255
+
256
+ if (info.Length() < 1) {
257
+ Napi::TypeError::New(env, "Expected sid_mode, [t0], [ayan_t0]")
258
+ .ThrowAsJavaScriptException();
259
+ return env.Undefined();
260
+ }
261
+
262
+ int32 sid_mode = info[0].As<Napi::Number>().Int32Value();
263
+ double t0 = info.Length() >= 2 ? info[1].As<Napi::Number>().DoubleValue() : 0.0;
264
+ double ayan_t0 = info.Length() >= 3 ? info[2].As<Napi::Number>().DoubleValue() : 0.0;
265
+
266
+ swe_set_sid_mode(sid_mode, t0, ayan_t0);
267
+
268
+ return env.Undefined();
269
+ }
270
+
271
+ // Wrapper for swe_set_topo
272
+ Napi::Value SetTopo(const Napi::CallbackInfo& info) {
273
+ Napi::Env env = info.Env();
274
+
275
+ if (info.Length() < 3) {
276
+ Napi::TypeError::New(env, "Expected geolon, geolat, geoalt")
277
+ .ThrowAsJavaScriptException();
278
+ return env.Undefined();
279
+ }
280
+
281
+ double geolon = info[0].As<Napi::Number>().DoubleValue();
282
+ double geolat = info[1].As<Napi::Number>().DoubleValue();
283
+ double geoalt = info[2].As<Napi::Number>().DoubleValue();
284
+
285
+ swe_set_topo(geolon, geolat, geoalt);
286
+
287
+ return env.Undefined();
288
+ }
289
+
290
+ // Wrapper for swe_get_ayanamsa_ut
291
+ Napi::Value GetAyanamsaUt(const Napi::CallbackInfo& info) {
292
+ Napi::Env env = info.Env();
293
+
294
+ if (info.Length() < 1) {
295
+ Napi::TypeError::New(env, "Expected tjd_ut")
296
+ .ThrowAsJavaScriptException();
297
+ return env.Undefined();
298
+ }
299
+
300
+ double tjd_ut = info[0].As<Napi::Number>().DoubleValue();
301
+ double ayanamsa = swe_get_ayanamsa_ut(tjd_ut);
302
+
303
+ return Napi::Number::New(env, ayanamsa);
304
+ }
305
+
306
+ // Wrapper for swe_rise_trans
307
+ Napi::Value RiseTrans(const Napi::CallbackInfo& info) {
308
+ Napi::Env env = info.Env();
309
+
310
+ if (info.Length() < 4) {
311
+ Napi::TypeError::New(env, "Expected tjd_ut, ipl, rsmi, geopos (array), [epheflag], [atpress], [attemp]")
312
+ .ThrowAsJavaScriptException();
313
+ return env.Undefined();
314
+ }
315
+
316
+ double tjd_ut = info[0].As<Napi::Number>().DoubleValue();
317
+ int32 ipl = info[1].As<Napi::Number>().Int32Value();
318
+ int32 rsmi = info[2].As<Napi::Number>().Int32Value();
319
+
320
+ // geopos is expected as an array [longitude, latitude, altitude]
321
+ if (!info[3].IsArray()) {
322
+ Napi::TypeError::New(env, "geopos must be an array [longitude, latitude, altitude]")
323
+ .ThrowAsJavaScriptException();
324
+ return env.Undefined();
325
+ }
326
+
327
+ Napi::Array geoposArray = info[3].As<Napi::Array>();
328
+ if (geoposArray.Length() < 3) {
329
+ Napi::TypeError::New(env, "geopos must have 3 elements [longitude, latitude, altitude]")
330
+ .ThrowAsJavaScriptException();
331
+ return env.Undefined();
332
+ }
333
+
334
+ double geopos[3];
335
+ geopos[0] = geoposArray.Get(0u).As<Napi::Number>().DoubleValue();
336
+ geopos[1] = geoposArray.Get(1u).As<Napi::Number>().DoubleValue();
337
+ geopos[2] = geoposArray.Get(2u).As<Napi::Number>().DoubleValue();
338
+
339
+ int32 epheflag = info.Length() >= 5 ? info[4].As<Napi::Number>().Int32Value() : SEFLG_SWIEPH;
340
+ double atpress = info.Length() >= 6 ? info[5].As<Napi::Number>().DoubleValue() : 0.0;
341
+ double attemp = info.Length() >= 7 ? info[6].As<Napi::Number>().DoubleValue() : 0.0;
342
+
343
+ double tret;
344
+ char serr[256];
345
+
346
+ // starname is NULL for planets (only used for fixed stars)
347
+ int32 ret = swe_rise_trans(tjd_ut, ipl, NULL, epheflag, rsmi, geopos, atpress, attemp, &tret, serr);
348
+
349
+ if (ret < 0) {
350
+ Napi::Error::New(env, serr).ThrowAsJavaScriptException();
351
+ return env.Undefined();
352
+ }
353
+
354
+ Napi::Array result = Napi::Array::New(env, 2);
355
+ result[0u] = Napi::Number::New(env, ret);
356
+ result[1u] = Napi::Number::New(env, tret);
357
+
358
+ return result;
359
+ }
360
+
252
361
  // Initialize the addon
253
362
  Napi::Object Init(Napi::Env env, Napi::Object exports) {
254
363
  exports.Set("set_ephe_path", Napi::Function::New(env, SetEphePath));
@@ -260,6 +369,10 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
260
369
  exports.Set("lun_eclipse_when", Napi::Function::New(env, LunEclipseWhen));
261
370
  exports.Set("sol_eclipse_when_glob", Napi::Function::New(env, SolEclipseWhenGlob));
262
371
  exports.Set("houses", Napi::Function::New(env, Houses));
372
+ exports.Set("set_sid_mode", Napi::Function::New(env, SetSidMode));
373
+ exports.Set("set_topo", Napi::Function::New(env, SetTopo));
374
+ exports.Set("get_ayanamsa_ut", Napi::Function::New(env, GetAyanamsaUt));
375
+ exports.Set("rise_trans", Napi::Function::New(env, RiseTrans));
263
376
 
264
377
  return exports;
265
378
  }
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * This module provides a modern, type-safe API for Swiss Ephemeris astronomical calculations.
5
5
  * It wraps the native C library with developer-friendly TypeScript interfaces.
6
6
  */
7
- import { CalendarType, CelestialBody, HouseSystem, CalculationFlagInput, EclipseTypeFlagInput, PlanetaryPosition, HouseData, LunarEclipse, SolarEclipse, ExtendedDateTime } from '@swisseph/core';
7
+ import { CalendarType, CelestialBody, HouseSystem, CalculationFlagInput, EclipseTypeFlagInput, PlanetaryPosition, HouseData, LunarEclipse, SolarEclipse, ExtendedDateTime, RiseTransitSet } from '@swisseph/core';
8
8
  /**
9
9
  * Set the directory path for ephemeris files
10
10
  *
@@ -42,6 +42,29 @@ export declare function setEphemerisPath(path?: string | null): void;
42
42
  * console.log(jdWithTime); // 2454163.104166667
43
43
  */
44
44
  export declare function julianDay(year: number, month: number, day: number, hour?: number, calendarType?: CalendarType): number;
45
+ /**
46
+ * Calculate Julian day number from a JavaScript Date object
47
+ *
48
+ * Convenience function that converts a JavaScript Date to Julian day number.
49
+ * The Date is interpreted as UTC.
50
+ *
51
+ * @param date - JavaScript Date object (interpreted as UTC)
52
+ * @param calendarType - Calendar system (default: Gregorian)
53
+ * @returns Julian day number
54
+ *
55
+ * @example
56
+ * // From Date object
57
+ * const date = new Date('1990-05-15T14:30:00Z');
58
+ * const jd = dateToJulianDay(date);
59
+ *
60
+ * // From timestamp
61
+ * const now = new Date();
62
+ * const jdNow = dateToJulianDay(now);
63
+ *
64
+ * // Equivalent to julianDay(1990, 5, 15, 14.5)
65
+ * const jd2 = dateToJulianDay(new Date(Date.UTC(1990, 4, 15, 14, 30)));
66
+ */
67
+ export declare function dateToJulianDay(date: Date, calendarType?: CalendarType): number;
45
68
  /**
46
69
  * Convert Julian day number to calendar date
47
70
  *
@@ -178,6 +201,173 @@ export declare function findNextSolarEclipse(startJulianDay: number, flags?: Cal
178
201
  * console.log(sunName); // "Sun"
179
202
  */
180
203
  export declare function getCelestialBodyName(body: CelestialBody): string;
204
+ /**
205
+ * Set the sidereal mode (ayanamsa system) for sidereal calculations
206
+ *
207
+ * This function must be called before calculating sidereal positions with
208
+ * CalculationFlag.Sidereal. Different ayanamsa systems are used in various
209
+ * traditions of astrology, particularly in Vedic (Jyotish) astrology.
210
+ *
211
+ * @param siderealMode - Ayanamsa system to use (e.g., SiderealMode.Lahiri for Vedic)
212
+ * @param t0 - Reference date (Julian day) for custom ayanamsa (default: 0)
213
+ * @param ayanT0 - Initial value of ayanamsa in degrees for custom mode (default: 0)
214
+ *
215
+ * @example
216
+ * import { setSiderealMode, SiderealMode, calculatePosition, CalculationFlag, Planet } from '@swisseph/node';
217
+ *
218
+ * // Set Lahiri ayanamsa (most common in Vedic astrology)
219
+ * setSiderealMode(SiderealMode.Lahiri);
220
+ *
221
+ * // Calculate sidereal position of Sun
222
+ * const jd = julianDay(2025, 1, 1);
223
+ * const sun = calculatePosition(jd, Planet.Sun, CalculationFlag.Sidereal | CalculationFlag.Speed);
224
+ * console.log(`Sidereal Sun: ${sun.longitude}°`);
225
+ *
226
+ * // Set Raman ayanamsa
227
+ * setSiderealMode(SiderealMode.Raman);
228
+ *
229
+ * // Set custom ayanamsa
230
+ * setSiderealMode(SiderealMode.UserDefined, 2451545.0, 23.85);
231
+ */
232
+ export declare function setSiderealMode(siderealMode: number, t0?: number, ayanT0?: number): void;
233
+ /**
234
+ * Set the geographic location for topocentric calculations
235
+ *
236
+ * This function must be called before calculating topocentric positions with
237
+ * CalculationFlag.Topocentric. Topocentric positions account for the observer's
238
+ * location on Earth, which is particularly important for the Moon due to parallax.
239
+ *
240
+ * @param longitude - Geographic longitude in degrees (positive = east, negative = west)
241
+ * @param latitude - Geographic latitude in degrees (positive = north, negative = south)
242
+ * @param altitude - Altitude above sea level in meters
243
+ *
244
+ * @example
245
+ * import { setTopocentric, calculatePosition, CalculationFlag, Planet } from '@swisseph/node';
246
+ *
247
+ * // Set location to New York City
248
+ * setTopocentric(-74.0060, 40.7128, 10); // lon, lat, altitude
249
+ *
250
+ * // Calculate topocentric Moon position
251
+ * const jd = julianDay(2025, 1, 1);
252
+ * const moon = calculatePosition(
253
+ * jd,
254
+ * Planet.Moon,
255
+ * CalculationFlag.Topocentric | CalculationFlag.Speed
256
+ * );
257
+ * console.log(`Topocentric Moon: ${moon.longitude}°`);
258
+ *
259
+ * // Set location to Mumbai for Vedic calculations
260
+ * setTopocentric(72.8777, 19.0760, 14);
261
+ * setSiderealMode(SiderealMode.Lahiri);
262
+ * const siderealMoon = calculatePosition(
263
+ * jd,
264
+ * Planet.Moon,
265
+ * CalculationFlag.Sidereal | CalculationFlag.Topocentric | CalculationFlag.Speed
266
+ * );
267
+ */
268
+ export declare function setTopocentric(longitude: number, latitude: number, altitude: number): void;
269
+ /**
270
+ * Get the ayanamsa (sidereal offset) value for a given date
271
+ *
272
+ * The ayanamsa is the distance between the tropical and sidereal zodiacs.
273
+ * This function returns the current offset in degrees for the ayanamsa system
274
+ * that was set with setSiderealMode().
275
+ *
276
+ * @param julianDay - Julian day number in Universal Time
277
+ * @returns Ayanamsa value in degrees
278
+ *
279
+ * @example
280
+ * import { getAyanamsa, setSiderealMode, SiderealMode, julianDay } from '@swisseph/node';
281
+ *
282
+ * // Get Lahiri ayanamsa for a date
283
+ * setSiderealMode(SiderealMode.Lahiri);
284
+ * const jd = julianDay(2025, 1, 1);
285
+ * const ayanamsa = getAyanamsa(jd);
286
+ * console.log(`Lahiri ayanamsa: ${ayanamsa.toFixed(4)}°`);
287
+ *
288
+ * // Compare different ayanamsa systems
289
+ * setSiderealMode(SiderealMode.Raman);
290
+ * const ramanAyanamsa = getAyanamsa(jd);
291
+ * console.log(`Raman ayanamsa: ${ramanAyanamsa.toFixed(4)}°`);
292
+ *
293
+ * setSiderealMode(SiderealMode.Krishnamurti);
294
+ * const kpAyanamsa = getAyanamsa(jd);
295
+ * console.log(`KP ayanamsa: ${kpAyanamsa.toFixed(4)}°`);
296
+ */
297
+ export declare function getAyanamsa(julianDay: number): number;
298
+ /**
299
+ * Calculate rise, transit, or set time for a celestial body
300
+ *
301
+ * Finds the time when a celestial body rises, transits (culminates), or sets
302
+ * for a given location. This is essential for calculating almanac data,
303
+ * planetary hours, and observational astrology.
304
+ *
305
+ * @param startJulianDay - Julian day to start search from
306
+ * @param body - Celestial body to calculate
307
+ * @param eventType - Type of event (RiseTransitFlag.Rise, Set, UpperTransit, or LowerTransit)
308
+ * @param longitude - Geographic longitude in degrees (positive = east, negative = west)
309
+ * @param latitude - Geographic latitude in degrees (positive = north, negative = south)
310
+ * @param altitude - Altitude above sea level in meters
311
+ * @param flags - Calculation flags (default: SwissEphemeris)
312
+ * @param atmosphericPressure - Atmospheric pressure in millibars (default: 0 = standard)
313
+ * @param atmosphericTemperature - Atmospheric temperature in Celsius (default: 0 = standard)
314
+ * @returns RiseTransitSet object with time of event
315
+ *
316
+ * @example
317
+ * import {
318
+ * calculateRiseTransitSet,
319
+ * RiseTransitFlag,
320
+ * Planet,
321
+ * julianDay,
322
+ * julianDayToDate
323
+ * } from '@swisseph/node';
324
+ *
325
+ * // Find sunrise in New York
326
+ * const jd = julianDay(2025, 1, 1);
327
+ * const sunrise = calculateRiseTransitSet(
328
+ * jd,
329
+ * Planet.Sun,
330
+ * RiseTransitFlag.Rise,
331
+ * -74.0060, // New York longitude
332
+ * 40.7128, // New York latitude
333
+ * 10 // altitude in meters
334
+ * );
335
+ * console.log(`Sunrise: ${julianDayToDate(sunrise.time)}`);
336
+ *
337
+ * // Find moonrise
338
+ * const moonrise = calculateRiseTransitSet(
339
+ * jd,
340
+ * Planet.Moon,
341
+ * RiseTransitFlag.Rise,
342
+ * -74.0060,
343
+ * 40.7128,
344
+ * 10
345
+ * );
346
+ *
347
+ * // Find Sun's upper transit (noon)
348
+ * const noon = calculateRiseTransitSet(
349
+ * jd,
350
+ * Planet.Sun,
351
+ * RiseTransitFlag.UpperTransit,
352
+ * -74.0060,
353
+ * 40.7128,
354
+ * 10
355
+ * );
356
+ *
357
+ * // With atmospheric refraction correction
358
+ * const preciseRise = calculateRiseTransitSet(
359
+ * jd,
360
+ * Planet.Sun,
361
+ * RiseTransitFlag.Rise,
362
+ * -74.0060,
363
+ * 40.7128,
364
+ * 10,
365
+ * CalculationFlag.SwissEphemeris,
366
+ * 1013.25, // standard pressure in millibars
367
+ * 15 // temperature in Celsius
368
+ * );
369
+ */
370
+ export declare function calculateRiseTransitSet(startJulianDay: number, body: CelestialBody, eventType: number, longitude: number, latitude: number, altitude: number, flags?: CalculationFlagInput, atmosphericPressure?: number, atmosphericTemperature?: number): RiseTransitSet;
181
371
  /**
182
372
  * Close Swiss Ephemeris and free resources
183
373
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,YAAY,EAEZ,aAAa,EACb,WAAW,EAEX,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,YAAY,EAEZ,gBAAgB,EAQjB,MAAM,gBAAgB,CAAC;AAkCxB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAU3D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAU,EAChB,YAAY,GAAE,YAAqC,GAClD,MAAM,CAER;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,EACV,YAAY,GAAE,YAAqC,GAClD,gBAAgB,CAGlB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,aAAa,EACnB,KAAK,GAAE,oBAAmE,GACzE,iBAAiB,CAenB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,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c,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,IAAI,CAEN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,aAAa,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,GAAE,oBAAqD,EAC5D,mBAAmB,GAAE,MAAU,EAC/B,sBAAsB,GAAE,MAAU,GACjC,cAAc,CAqBhB;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,IAAI,IAAI,CAE5B;AAGD,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -44,12 +44,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.setEphemerisPath = setEphemerisPath;
46
46
  exports.julianDay = julianDay;
47
+ exports.dateToJulianDay = dateToJulianDay;
47
48
  exports.julianDayToDate = julianDayToDate;
48
49
  exports.calculatePosition = calculatePosition;
49
50
  exports.calculateHouses = calculateHouses;
50
51
  exports.findNextLunarEclipse = findNextLunarEclipse;
51
52
  exports.findNextSolarEclipse = findNextSolarEclipse;
52
53
  exports.getCelestialBodyName = getCelestialBodyName;
54
+ exports.setSiderealMode = setSiderealMode;
55
+ exports.setTopocentric = setTopocentric;
56
+ exports.getAyanamsa = getAyanamsa;
57
+ exports.calculateRiseTransitSet = calculateRiseTransitSet;
53
58
  exports.close = close;
54
59
  const core_1 = require("@swisseph/core");
55
60
  const path = __importStar(require("path"));
@@ -128,6 +133,40 @@ function setEphemerisPath(path) {
128
133
  function julianDay(year, month, day, hour = 0, calendarType = core_1.CalendarType.Gregorian) {
129
134
  return binding.julday(year, month, day, hour, calendarType);
130
135
  }
136
+ /**
137
+ * Calculate Julian day number from a JavaScript Date object
138
+ *
139
+ * Convenience function that converts a JavaScript Date to Julian day number.
140
+ * The Date is interpreted as UTC.
141
+ *
142
+ * @param date - JavaScript Date object (interpreted as UTC)
143
+ * @param calendarType - Calendar system (default: Gregorian)
144
+ * @returns Julian day number
145
+ *
146
+ * @example
147
+ * // From Date object
148
+ * const date = new Date('1990-05-15T14:30:00Z');
149
+ * const jd = dateToJulianDay(date);
150
+ *
151
+ * // From timestamp
152
+ * const now = new Date();
153
+ * const jdNow = dateToJulianDay(now);
154
+ *
155
+ * // Equivalent to julianDay(1990, 5, 15, 14.5)
156
+ * const jd2 = dateToJulianDay(new Date(Date.UTC(1990, 4, 15, 14, 30)));
157
+ */
158
+ function dateToJulianDay(date, calendarType = core_1.CalendarType.Gregorian) {
159
+ const year = date.getUTCFullYear();
160
+ const month = date.getUTCMonth() + 1; // JavaScript months are 0-indexed
161
+ const day = date.getUTCDate();
162
+ const hours = date.getUTCHours();
163
+ const minutes = date.getUTCMinutes();
164
+ const seconds = date.getUTCSeconds();
165
+ const milliseconds = date.getUTCMilliseconds();
166
+ // Convert to decimal hours
167
+ const decimalHours = hours + minutes / 60 + seconds / 3600 + milliseconds / 3600000;
168
+ return julianDay(year, month, day, decimalHours, calendarType);
169
+ }
131
170
  /**
132
171
  * Convert Julian day number to calendar date
133
172
  *
@@ -326,6 +365,189 @@ function findNextSolarEclipse(startJulianDay, flags = core_1.CalculationFlag.Swi
326
365
  function getCelestialBodyName(body) {
327
366
  return binding.get_planet_name(body);
328
367
  }
368
+ /**
369
+ * Set the sidereal mode (ayanamsa system) for sidereal calculations
370
+ *
371
+ * This function must be called before calculating sidereal positions with
372
+ * CalculationFlag.Sidereal. Different ayanamsa systems are used in various
373
+ * traditions of astrology, particularly in Vedic (Jyotish) astrology.
374
+ *
375
+ * @param siderealMode - Ayanamsa system to use (e.g., SiderealMode.Lahiri for Vedic)
376
+ * @param t0 - Reference date (Julian day) for custom ayanamsa (default: 0)
377
+ * @param ayanT0 - Initial value of ayanamsa in degrees for custom mode (default: 0)
378
+ *
379
+ * @example
380
+ * import { setSiderealMode, SiderealMode, calculatePosition, CalculationFlag, Planet } from '@swisseph/node';
381
+ *
382
+ * // Set Lahiri ayanamsa (most common in Vedic astrology)
383
+ * setSiderealMode(SiderealMode.Lahiri);
384
+ *
385
+ * // Calculate sidereal position of Sun
386
+ * const jd = julianDay(2025, 1, 1);
387
+ * const sun = calculatePosition(jd, Planet.Sun, CalculationFlag.Sidereal | CalculationFlag.Speed);
388
+ * console.log(`Sidereal Sun: ${sun.longitude}°`);
389
+ *
390
+ * // Set Raman ayanamsa
391
+ * setSiderealMode(SiderealMode.Raman);
392
+ *
393
+ * // Set custom ayanamsa
394
+ * setSiderealMode(SiderealMode.UserDefined, 2451545.0, 23.85);
395
+ */
396
+ function setSiderealMode(siderealMode, t0 = 0, ayanT0 = 0) {
397
+ binding.set_sid_mode(siderealMode, t0, ayanT0);
398
+ }
399
+ /**
400
+ * Set the geographic location for topocentric calculations
401
+ *
402
+ * This function must be called before calculating topocentric positions with
403
+ * CalculationFlag.Topocentric. Topocentric positions account for the observer's
404
+ * location on Earth, which is particularly important for the Moon due to parallax.
405
+ *
406
+ * @param longitude - Geographic longitude in degrees (positive = east, negative = west)
407
+ * @param latitude - Geographic latitude in degrees (positive = north, negative = south)
408
+ * @param altitude - Altitude above sea level in meters
409
+ *
410
+ * @example
411
+ * import { setTopocentric, calculatePosition, CalculationFlag, Planet } from '@swisseph/node';
412
+ *
413
+ * // Set location to New York City
414
+ * setTopocentric(-74.0060, 40.7128, 10); // lon, lat, altitude
415
+ *
416
+ * // Calculate topocentric Moon position
417
+ * const jd = julianDay(2025, 1, 1);
418
+ * const moon = calculatePosition(
419
+ * jd,
420
+ * Planet.Moon,
421
+ * CalculationFlag.Topocentric | CalculationFlag.Speed
422
+ * );
423
+ * console.log(`Topocentric Moon: ${moon.longitude}°`);
424
+ *
425
+ * // Set location to Mumbai for Vedic calculations
426
+ * setTopocentric(72.8777, 19.0760, 14);
427
+ * setSiderealMode(SiderealMode.Lahiri);
428
+ * const siderealMoon = calculatePosition(
429
+ * jd,
430
+ * Planet.Moon,
431
+ * CalculationFlag.Sidereal | CalculationFlag.Topocentric | CalculationFlag.Speed
432
+ * );
433
+ */
434
+ function setTopocentric(longitude, latitude, altitude) {
435
+ binding.set_topo(longitude, latitude, altitude);
436
+ }
437
+ /**
438
+ * Get the ayanamsa (sidereal offset) value for a given date
439
+ *
440
+ * The ayanamsa is the distance between the tropical and sidereal zodiacs.
441
+ * This function returns the current offset in degrees for the ayanamsa system
442
+ * that was set with setSiderealMode().
443
+ *
444
+ * @param julianDay - Julian day number in Universal Time
445
+ * @returns Ayanamsa value in degrees
446
+ *
447
+ * @example
448
+ * import { getAyanamsa, setSiderealMode, SiderealMode, julianDay } from '@swisseph/node';
449
+ *
450
+ * // Get Lahiri ayanamsa for a date
451
+ * setSiderealMode(SiderealMode.Lahiri);
452
+ * const jd = julianDay(2025, 1, 1);
453
+ * const ayanamsa = getAyanamsa(jd);
454
+ * console.log(`Lahiri ayanamsa: ${ayanamsa.toFixed(4)}°`);
455
+ *
456
+ * // Compare different ayanamsa systems
457
+ * setSiderealMode(SiderealMode.Raman);
458
+ * const ramanAyanamsa = getAyanamsa(jd);
459
+ * console.log(`Raman ayanamsa: ${ramanAyanamsa.toFixed(4)}°`);
460
+ *
461
+ * setSiderealMode(SiderealMode.Krishnamurti);
462
+ * const kpAyanamsa = getAyanamsa(jd);
463
+ * console.log(`KP ayanamsa: ${kpAyanamsa.toFixed(4)}°`);
464
+ */
465
+ function getAyanamsa(julianDay) {
466
+ return binding.get_ayanamsa_ut(julianDay);
467
+ }
468
+ /**
469
+ * Calculate rise, transit, or set time for a celestial body
470
+ *
471
+ * Finds the time when a celestial body rises, transits (culminates), or sets
472
+ * for a given location. This is essential for calculating almanac data,
473
+ * planetary hours, and observational astrology.
474
+ *
475
+ * @param startJulianDay - Julian day to start search from
476
+ * @param body - Celestial body to calculate
477
+ * @param eventType - Type of event (RiseTransitFlag.Rise, Set, UpperTransit, or LowerTransit)
478
+ * @param longitude - Geographic longitude in degrees (positive = east, negative = west)
479
+ * @param latitude - Geographic latitude in degrees (positive = north, negative = south)
480
+ * @param altitude - Altitude above sea level in meters
481
+ * @param flags - Calculation flags (default: SwissEphemeris)
482
+ * @param atmosphericPressure - Atmospheric pressure in millibars (default: 0 = standard)
483
+ * @param atmosphericTemperature - Atmospheric temperature in Celsius (default: 0 = standard)
484
+ * @returns RiseTransitSet object with time of event
485
+ *
486
+ * @example
487
+ * import {
488
+ * calculateRiseTransitSet,
489
+ * RiseTransitFlag,
490
+ * Planet,
491
+ * julianDay,
492
+ * julianDayToDate
493
+ * } from '@swisseph/node';
494
+ *
495
+ * // Find sunrise in New York
496
+ * const jd = julianDay(2025, 1, 1);
497
+ * const sunrise = calculateRiseTransitSet(
498
+ * jd,
499
+ * Planet.Sun,
500
+ * RiseTransitFlag.Rise,
501
+ * -74.0060, // New York longitude
502
+ * 40.7128, // New York latitude
503
+ * 10 // altitude in meters
504
+ * );
505
+ * console.log(`Sunrise: ${julianDayToDate(sunrise.time)}`);
506
+ *
507
+ * // Find moonrise
508
+ * const moonrise = calculateRiseTransitSet(
509
+ * jd,
510
+ * Planet.Moon,
511
+ * RiseTransitFlag.Rise,
512
+ * -74.0060,
513
+ * 40.7128,
514
+ * 10
515
+ * );
516
+ *
517
+ * // Find Sun's upper transit (noon)
518
+ * const noon = calculateRiseTransitSet(
519
+ * jd,
520
+ * Planet.Sun,
521
+ * RiseTransitFlag.UpperTransit,
522
+ * -74.0060,
523
+ * 40.7128,
524
+ * 10
525
+ * );
526
+ *
527
+ * // With atmospheric refraction correction
528
+ * const preciseRise = calculateRiseTransitSet(
529
+ * jd,
530
+ * Planet.Sun,
531
+ * RiseTransitFlag.Rise,
532
+ * -74.0060,
533
+ * 40.7128,
534
+ * 10,
535
+ * CalculationFlag.SwissEphemeris,
536
+ * 1013.25, // standard pressure in millibars
537
+ * 15 // temperature in Celsius
538
+ * );
539
+ */
540
+ function calculateRiseTransitSet(startJulianDay, body, eventType, longitude, latitude, altitude, flags = core_1.CalculationFlag.SwissEphemeris, atmosphericPressure = 0, atmosphericTemperature = 0) {
541
+ const normalizedFlags = (0, core_1.normalizeFlags)(flags);
542
+ ensureEphemerisInitialized(normalizedFlags);
543
+ const geopos = [longitude, latitude, altitude];
544
+ const result = binding.rise_trans(startJulianDay, body, eventType, geopos, normalizedFlags, atmosphericPressure, atmosphericTemperature);
545
+ const [retFlag, time] = result;
546
+ return {
547
+ time,
548
+ eventType: retFlag,
549
+ };
550
+ }
329
551
  /**
330
552
  * Close Swiss Ephemeris and free resources
331
553
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swisseph/node",
3
- "version": "1.0.6",
3
+ "version": "1.2.0",
4
4
  "description": "Swiss Ephemeris for Node.js - high precision astronomical calculations with native bindings",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -51,7 +51,7 @@
51
51
  "dependencies": {
52
52
  "node-addon-api": "^7.1.0",
53
53
  "node-gyp-build": "^4.8.4",
54
- "@swisseph/core": "1.0.4"
54
+ "@swisseph/core": "1.1.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/jest": "^29.5.11",
@@ -71,9 +71,9 @@
71
71
  "install": "node-gyp-build",
72
72
  "copy:libswe": "mkdir -p libswe && cp ../../native/libswe/* libswe/",
73
73
  "prebuild": "node scripts/setup-libswe.js && prebuildify --napi --strip --name swisseph",
74
- "build": "node-gyp rebuild && tsc",
74
+ "build": "node-gyp rebuild && tsc --build",
75
75
  "build:native": "node-gyp rebuild",
76
- "build:js": "tsc",
76
+ "build:js": "tsc --build",
77
77
  "test": "jest",
78
78
  "example": "npm run build && ts-node -P tsconfig.test.json examples/basic-usage.ts",
79
79
  "example:chart": "npm run build && ts-node -P tsconfig.test.json examples/birth-chart.ts",
Binary file
Binary file