@swisseph/node 1.0.5 → 1.1.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 +47 -14
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -0
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/swisseph.node +0 -0
- package/prebuilds/win32-x64/swisseph.node +0 -0
package/README.md
CHANGED
|
@@ -6,14 +6,21 @@ High precision astronomical calculations for Node.js using native bindings to th
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @swisseph/node
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @swisseph/node
|
|
11
|
+
# or
|
|
12
|
+
bun add @swisseph/node
|
|
9
13
|
```
|
|
10
14
|
|
|
11
15
|
**Requirements:**
|
|
12
|
-
- Node.js 14.0.0 or higher
|
|
13
|
-
|
|
16
|
+
- Node.js 14.0.0 or higher (or Bun)
|
|
17
|
+
|
|
18
|
+
**Prebuilt binaries are included** for common platforms (macOS, Linux, Windows). No C++ compiler needed for most users.
|
|
14
19
|
|
|
15
20
|
<details>
|
|
16
|
-
<summary>
|
|
21
|
+
<summary>Building from source (optional)</summary>
|
|
22
|
+
|
|
23
|
+
If prebuilt binaries aren't available for your platform, the package will automatically build from source. You'll need C++ build tools:
|
|
17
24
|
|
|
18
25
|
**macOS:**
|
|
19
26
|
```bash
|
|
@@ -35,7 +42,7 @@ npm install --global windows-build-tools
|
|
|
35
42
|
|
|
36
43
|
```typescript
|
|
37
44
|
import {
|
|
38
|
-
|
|
45
|
+
dateToJulianDay,
|
|
39
46
|
calculatePosition,
|
|
40
47
|
calculateHouses,
|
|
41
48
|
Planet,
|
|
@@ -44,8 +51,9 @@ import {
|
|
|
44
51
|
|
|
45
52
|
// No setup required! Ephemeris files are bundled and auto-loaded.
|
|
46
53
|
|
|
47
|
-
// Calculate planetary position
|
|
48
|
-
const
|
|
54
|
+
// Calculate planetary position using Date object
|
|
55
|
+
const date = new Date('2007-03-03T00:00:00Z');
|
|
56
|
+
const jd = dateToJulianDay(date);
|
|
49
57
|
const sun = calculatePosition(jd, Planet.Sun);
|
|
50
58
|
console.log(`Sun: ${sun.longitude}°`);
|
|
51
59
|
|
|
@@ -60,10 +68,28 @@ console.log(`MC: ${houses.mc}°`);
|
|
|
60
68
|
### Date & Time
|
|
61
69
|
|
|
62
70
|
```typescript
|
|
71
|
+
// Convert JavaScript Date to Julian day (recommended)
|
|
72
|
+
dateToJulianDay(date, calendarType?)
|
|
73
|
+
|
|
74
|
+
// Convert date components to Julian day
|
|
63
75
|
julianDay(year, month, day, hour?, calendarType?)
|
|
76
|
+
|
|
77
|
+
// Convert Julian day back to date
|
|
64
78
|
julianDayToDate(jd, calendarType?)
|
|
65
79
|
```
|
|
66
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
|
+
|
|
67
93
|
### Planetary Positions
|
|
68
94
|
|
|
69
95
|
```typescript
|
|
@@ -140,7 +166,7 @@ import {
|
|
|
140
166
|
|
|
141
167
|
```typescript
|
|
142
168
|
import {
|
|
143
|
-
|
|
169
|
+
dateToJulianDay,
|
|
144
170
|
calculatePosition,
|
|
145
171
|
calculateHouses,
|
|
146
172
|
Planet,
|
|
@@ -149,7 +175,8 @@ import {
|
|
|
149
175
|
} from '@swisseph/node';
|
|
150
176
|
|
|
151
177
|
// Birth: May 15, 1990, 14:30 UTC, New York (40.7128°N, 74.0060°W)
|
|
152
|
-
const
|
|
178
|
+
const birthDate = new Date('1990-05-15T14:30:00Z');
|
|
179
|
+
const jd = dateToJulianDay(birthDate);
|
|
153
180
|
|
|
154
181
|
// Calculate all planet positions
|
|
155
182
|
const planets = [
|
|
@@ -213,9 +240,10 @@ close();
|
|
|
213
240
|
### Planetary Aspects
|
|
214
241
|
|
|
215
242
|
```typescript
|
|
216
|
-
import {
|
|
243
|
+
import { dateToJulianDay, calculatePosition, Planet, close } from '@swisseph/node';
|
|
217
244
|
|
|
218
|
-
|
|
245
|
+
// Calculate for current time
|
|
246
|
+
const jd = dateToJulianDay(new Date());
|
|
219
247
|
|
|
220
248
|
// Calculate positions
|
|
221
249
|
const sun = calculatePosition(jd, Planet.Sun);
|
|
@@ -253,16 +281,21 @@ Complete documentation is available in the [GitHub repository](https://github.co
|
|
|
253
281
|
|
|
254
282
|
## Troubleshooting
|
|
255
283
|
|
|
284
|
+
**"Module did not self-register" or platform errors**
|
|
285
|
+
- The package includes prebuilt binaries for common platforms
|
|
286
|
+
- If your platform isn't supported, the package will try to build from source
|
|
287
|
+
- Install C++ build tools if needed (see "Building from source" above)
|
|
288
|
+
- Try rebuilding: `npm rebuild @swisseph/node`
|
|
289
|
+
|
|
256
290
|
**Build fails with "node-gyp rebuild failed"**
|
|
257
|
-
- Install C++ build tools (see
|
|
291
|
+
- Install C++ build tools (see "Building from source" section above)
|
|
292
|
+
- On macOS: ensure Xcode Command Line Tools are installed
|
|
293
|
+
- On Windows: ensure Visual Studio Build Tools are installed
|
|
258
294
|
|
|
259
295
|
**"Cannot find ephemeris files"**
|
|
260
296
|
- Files are bundled with the package. Check `node_modules/@swisseph/node/ephemeris/` exists
|
|
261
297
|
- If using custom files, verify path in `setEphemerisPath()`
|
|
262
298
|
|
|
263
|
-
**"Module did not self-register"**
|
|
264
|
-
- Rebuild for your Node.js version: `npm rebuild @swisseph/node`
|
|
265
|
-
|
|
266
299
|
## License
|
|
267
300
|
|
|
268
301
|
AGPL-3.0 (same as Swiss Ephemeris)
|
package/dist/index.d.ts
CHANGED
|
@@ -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
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,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B,KAAK,GAAE,oBAAqD,EAC5D,WAAW,GAAE,oBAAwB,EACrC,QAAQ,GAAE,OAAe,GACxB,YAAY,CAwBd;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAClC,cAAc,EAAE,MAAM,EACtB,KAAK,GAAE,oBAAqD,EAC5D,WAAW,GAAE,oBAAwB,EACrC,QAAQ,GAAE,OAAe,GACxB,YAAY,CAwBd;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAEhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,IAAI,IAAI,CAE5B;AAGD,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ 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;
|
|
@@ -128,6 +129,40 @@ function setEphemerisPath(path) {
|
|
|
128
129
|
function julianDay(year, month, day, hour = 0, calendarType = core_1.CalendarType.Gregorian) {
|
|
129
130
|
return binding.julday(year, month, day, hour, calendarType);
|
|
130
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Calculate Julian day number from a JavaScript Date object
|
|
134
|
+
*
|
|
135
|
+
* Convenience function that converts a JavaScript Date to Julian day number.
|
|
136
|
+
* The Date is interpreted as UTC.
|
|
137
|
+
*
|
|
138
|
+
* @param date - JavaScript Date object (interpreted as UTC)
|
|
139
|
+
* @param calendarType - Calendar system (default: Gregorian)
|
|
140
|
+
* @returns Julian day number
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* // From Date object
|
|
144
|
+
* const date = new Date('1990-05-15T14:30:00Z');
|
|
145
|
+
* const jd = dateToJulianDay(date);
|
|
146
|
+
*
|
|
147
|
+
* // From timestamp
|
|
148
|
+
* const now = new Date();
|
|
149
|
+
* const jdNow = dateToJulianDay(now);
|
|
150
|
+
*
|
|
151
|
+
* // Equivalent to julianDay(1990, 5, 15, 14.5)
|
|
152
|
+
* const jd2 = dateToJulianDay(new Date(Date.UTC(1990, 4, 15, 14, 30)));
|
|
153
|
+
*/
|
|
154
|
+
function dateToJulianDay(date, calendarType = core_1.CalendarType.Gregorian) {
|
|
155
|
+
const year = date.getUTCFullYear();
|
|
156
|
+
const month = date.getUTCMonth() + 1; // JavaScript months are 0-indexed
|
|
157
|
+
const day = date.getUTCDate();
|
|
158
|
+
const hours = date.getUTCHours();
|
|
159
|
+
const minutes = date.getUTCMinutes();
|
|
160
|
+
const seconds = date.getUTCSeconds();
|
|
161
|
+
const milliseconds = date.getUTCMilliseconds();
|
|
162
|
+
// Convert to decimal hours
|
|
163
|
+
const decimalHours = hours + minutes / 60 + seconds / 3600 + milliseconds / 3600000;
|
|
164
|
+
return julianDay(year, month, day, decimalHours, calendarType);
|
|
165
|
+
}
|
|
131
166
|
/**
|
|
132
167
|
* Convert Julian day number to calendar date
|
|
133
168
|
*
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|