swisseph-wasm 0.0.1
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/DOCUMENTATION.md +888 -0
- package/LICENSE +41 -0
- package/QUICK_REFERENCE.md +263 -0
- package/README.md +305 -0
- package/examples/README.md +239 -0
- package/examples/basic-usage.js +301 -0
- package/examples/birth-chart.js +386 -0
- package/examples/demo.html +543 -0
- package/package.json +75 -0
- package/src/swisseph.js +1092 -0
- package/types/index.d.ts +255 -0
- package/wsam/swisseph.data +0 -0
- package/wsam/swisseph.js +3412 -0
- package/wsam/swisseph.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2024 prolaxu
|
|
5
|
+
|
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
This program is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU General Public License
|
|
17
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
ADDITIONAL TERMS FOR SWISS EPHEMERIS
|
|
20
|
+
|
|
21
|
+
This software is a JavaScript wrapper around the Swiss Ephemeris library.
|
|
22
|
+
The Swiss Ephemeris is subject to the following license terms:
|
|
23
|
+
|
|
24
|
+
Swiss Ephemeris License:
|
|
25
|
+
- For non-commercial use: Free under GNU General Public License
|
|
26
|
+
- For commercial use: Requires a commercial license from Astrodienst AG
|
|
27
|
+
|
|
28
|
+
For commercial licensing of the Swiss Ephemeris, please contact:
|
|
29
|
+
Astrodienst AG
|
|
30
|
+
Dammstrasse 23
|
|
31
|
+
CH-8702 Zollikon
|
|
32
|
+
Switzerland
|
|
33
|
+
Email: swisseph@astro.com
|
|
34
|
+
Website: https://www.astro.com/swisseph/
|
|
35
|
+
|
|
36
|
+
The Swiss Ephemeris source code and documentation can be found at:
|
|
37
|
+
https://www.astro.com/swisseph/
|
|
38
|
+
|
|
39
|
+
This wrapper library (swisseph-wasm) is provided under GPL-3.0-or-later,
|
|
40
|
+
but commercial use may require additional licensing for the underlying
|
|
41
|
+
Swiss Ephemeris calculations.
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# SwissEph Quick Reference Guide
|
|
2
|
+
|
|
3
|
+
## Basic Setup
|
|
4
|
+
|
|
5
|
+
```javascript
|
|
6
|
+
import SwissEph from './src/swisseph.js';
|
|
7
|
+
|
|
8
|
+
const swe = new SwissEph();
|
|
9
|
+
await swe.initSwissEph();
|
|
10
|
+
|
|
11
|
+
// Your calculations here
|
|
12
|
+
|
|
13
|
+
swe.close(); // Always clean up
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Essential Functions
|
|
17
|
+
|
|
18
|
+
### Date & Time
|
|
19
|
+
```javascript
|
|
20
|
+
// Julian Day calculation
|
|
21
|
+
const jd = swe.julday(2023, 6, 15, 12.5);
|
|
22
|
+
|
|
23
|
+
// UTC to Julian Day
|
|
24
|
+
const result = swe.utc_to_jd(2023, 6, 15, 12, 30, 0, swe.SE_GREG_CAL);
|
|
25
|
+
|
|
26
|
+
// Julian Day to calendar date
|
|
27
|
+
const date = swe.revjul(jd, swe.SE_GREG_CAL);
|
|
28
|
+
|
|
29
|
+
// Sidereal time
|
|
30
|
+
const sidTime = swe.sidtime(jd);
|
|
31
|
+
|
|
32
|
+
// Delta T
|
|
33
|
+
const deltaT = swe.deltat(jd);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Planet Positions
|
|
37
|
+
```javascript
|
|
38
|
+
// Basic calculation
|
|
39
|
+
const pos = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH);
|
|
40
|
+
// Returns: [longitude, latitude, distance, speed]
|
|
41
|
+
|
|
42
|
+
// Detailed calculation
|
|
43
|
+
const detailed = swe.calc(jd, swe.SE_MOON, swe.SEFLG_SWIEPH);
|
|
44
|
+
// Returns: {longitude, latitude, distance, longitudeSpeed, latitudeSpeed, distanceSpeed}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Sidereal Calculations
|
|
48
|
+
```javascript
|
|
49
|
+
// Set sidereal mode
|
|
50
|
+
swe.set_sid_mode(swe.SE_SIDM_LAHIRI, 0, 0);
|
|
51
|
+
|
|
52
|
+
// Calculate sidereal position
|
|
53
|
+
const sidereal = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH | swe.SEFLG_SIDEREAL);
|
|
54
|
+
|
|
55
|
+
// Get ayanamsa
|
|
56
|
+
const ayanamsa = swe.get_ayanamsa(jd);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Planet Constants
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
// Major planets
|
|
63
|
+
swe.SE_SUN = 0 swe.SE_JUPITER = 5
|
|
64
|
+
swe.SE_MOON = 1 swe.SE_SATURN = 6
|
|
65
|
+
swe.SE_MERCURY = 2 swe.SE_URANUS = 7
|
|
66
|
+
swe.SE_VENUS = 3 swe.SE_NEPTUNE = 8
|
|
67
|
+
swe.SE_MARS = 4 swe.SE_PLUTO = 9
|
|
68
|
+
|
|
69
|
+
// Lunar nodes
|
|
70
|
+
swe.SE_MEAN_NODE = 10
|
|
71
|
+
swe.SE_TRUE_NODE = 11
|
|
72
|
+
|
|
73
|
+
// Asteroids
|
|
74
|
+
swe.SE_CHIRON = 15 swe.SE_CERES = 17
|
|
75
|
+
swe.SE_PHOLUS = 16 swe.SE_PALLAS = 18
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Calculation Flags
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
// Ephemeris types
|
|
82
|
+
swe.SEFLG_SWIEPH = 2 // Swiss Ephemeris (default)
|
|
83
|
+
swe.SEFLG_JPLEPH = 1 // JPL Ephemeris
|
|
84
|
+
swe.SEFLG_MOSEPH = 4 // Moshier Ephemeris
|
|
85
|
+
|
|
86
|
+
// Coordinate systems
|
|
87
|
+
swe.SEFLG_HELCTR = 8 // Heliocentric
|
|
88
|
+
swe.SEFLG_BARYCTR = 16384 // Barycentric
|
|
89
|
+
swe.SEFLG_TOPOCTR = 32768 // Topocentric
|
|
90
|
+
swe.SEFLG_EQUATORIAL = 2048 // Equatorial coordinates
|
|
91
|
+
|
|
92
|
+
// Special flags
|
|
93
|
+
swe.SEFLG_SPEED = 256 // Include speed
|
|
94
|
+
swe.SEFLG_SIDEREAL = 65536 // Sidereal positions
|
|
95
|
+
swe.SEFLG_RADIANS = 8192 // Results in radians
|
|
96
|
+
swe.SEFLG_J2000 = 32 // J2000 coordinates
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Sidereal Modes
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
swe.SE_SIDM_FAGAN_BRADLEY = 0
|
|
103
|
+
swe.SE_SIDM_LAHIRI = 1
|
|
104
|
+
swe.SE_SIDM_DELUCE = 2
|
|
105
|
+
swe.SE_SIDM_RAMAN = 3
|
|
106
|
+
swe.SE_SIDM_KRISHNAMURTI = 5
|
|
107
|
+
swe.SE_SIDM_USER = 255
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Common Patterns
|
|
111
|
+
|
|
112
|
+
### Birth Chart Calculation
|
|
113
|
+
```javascript
|
|
114
|
+
async function birthChart(year, month, day, hour, minute, timezone) {
|
|
115
|
+
const swe = new SwissEph();
|
|
116
|
+
await swe.initSwissEph();
|
|
117
|
+
|
|
118
|
+
const utcHour = hour + minute / 60 - timezone;
|
|
119
|
+
const jd = swe.julday(year, month, day, utcHour);
|
|
120
|
+
|
|
121
|
+
const planets = [swe.SE_SUN, swe.SE_MOON, swe.SE_MERCURY, swe.SE_VENUS,
|
|
122
|
+
swe.SE_MARS, swe.SE_JUPITER, swe.SE_SATURN];
|
|
123
|
+
|
|
124
|
+
const chart = {};
|
|
125
|
+
for (const planet of planets) {
|
|
126
|
+
const pos = swe.calc_ut(jd, planet, swe.SEFLG_SWIEPH);
|
|
127
|
+
chart[swe.get_planet_name(planet)] = pos[0];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
swe.close();
|
|
131
|
+
return chart;
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Current Planetary Positions
|
|
136
|
+
```javascript
|
|
137
|
+
async function currentPositions() {
|
|
138
|
+
const swe = new SwissEph();
|
|
139
|
+
await swe.initSwissEph();
|
|
140
|
+
|
|
141
|
+
const now = new Date();
|
|
142
|
+
const jd = swe.julday(
|
|
143
|
+
now.getUTCFullYear(),
|
|
144
|
+
now.getUTCMonth() + 1,
|
|
145
|
+
now.getUTCDate(),
|
|
146
|
+
now.getUTCHours() + now.getUTCMinutes() / 60
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const sunPos = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH);
|
|
150
|
+
const moonPos = swe.calc_ut(jd, swe.SE_MOON, swe.SEFLG_SWIEPH);
|
|
151
|
+
|
|
152
|
+
swe.close();
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
sun: sunPos[0],
|
|
156
|
+
moon: moonPos[0],
|
|
157
|
+
julianDay: jd
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Sidereal vs Tropical
|
|
163
|
+
```javascript
|
|
164
|
+
async function comparePositions(year, month, day, hour) {
|
|
165
|
+
const swe = new SwissEph();
|
|
166
|
+
await swe.initSwissEph();
|
|
167
|
+
|
|
168
|
+
const jd = swe.julday(year, month, day, hour);
|
|
169
|
+
|
|
170
|
+
// Tropical
|
|
171
|
+
const tropical = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH);
|
|
172
|
+
|
|
173
|
+
// Sidereal (Lahiri)
|
|
174
|
+
swe.set_sid_mode(swe.SE_SIDM_LAHIRI, 0, 0);
|
|
175
|
+
const sidereal = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH | swe.SEFLG_SIDEREAL);
|
|
176
|
+
|
|
177
|
+
swe.close();
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
tropical: tropical[0],
|
|
181
|
+
sidereal: sidereal[0],
|
|
182
|
+
difference: tropical[0] - sidereal[0]
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Utility Functions
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
// Normalize degrees (0-360)
|
|
191
|
+
const normalized = swe.degnorm(370); // Returns 10
|
|
192
|
+
|
|
193
|
+
// Split degrees into D°M'S"
|
|
194
|
+
const split = swe.split_deg(123.456, swe.SE_SPLIT_DEG_ROUND_SEC);
|
|
195
|
+
// Returns: {degree: 123, min: 27, second: 24, sign: 4}
|
|
196
|
+
|
|
197
|
+
// Day of week (0=Monday, 6=Sunday)
|
|
198
|
+
const dayOfWeek = swe.day_of_week(jd);
|
|
199
|
+
|
|
200
|
+
// Planet name
|
|
201
|
+
const name = swe.get_planet_name(swe.SE_SUN); // Returns "Sun"
|
|
202
|
+
|
|
203
|
+
// Version info
|
|
204
|
+
const version = swe.version();
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Error Handling Template
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
async function safeCalculation() {
|
|
211
|
+
let swe = null;
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
swe = new SwissEph();
|
|
215
|
+
await swe.initSwissEph();
|
|
216
|
+
|
|
217
|
+
// Your calculations here
|
|
218
|
+
const jd = swe.julday(2023, 6, 15, 12);
|
|
219
|
+
const result = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH);
|
|
220
|
+
|
|
221
|
+
return { success: true, data: result };
|
|
222
|
+
|
|
223
|
+
} catch (error) {
|
|
224
|
+
return { success: false, error: error.message };
|
|
225
|
+
} finally {
|
|
226
|
+
if (swe) swe.close();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Performance Tips
|
|
232
|
+
|
|
233
|
+
1. **Reuse instances** for multiple calculations
|
|
234
|
+
2. **Batch calculations** in single session
|
|
235
|
+
3. **Always call close()** to prevent memory leaks
|
|
236
|
+
4. **Validate inputs** before calculation
|
|
237
|
+
5. **Use appropriate flags** for your needs
|
|
238
|
+
|
|
239
|
+
## Common Gotchas
|
|
240
|
+
|
|
241
|
+
- **Time zones**: Convert to UTC before calculation
|
|
242
|
+
- **Month numbering**: Use 1-12, not 0-11
|
|
243
|
+
- **Memory management**: Always call `close()`
|
|
244
|
+
- **Async initialization**: Always `await initSwissEph()`
|
|
245
|
+
- **Flag combinations**: Use bitwise OR (`|`) to combine flags
|
|
246
|
+
|
|
247
|
+
## Browser Requirements
|
|
248
|
+
|
|
249
|
+
- WebAssembly support
|
|
250
|
+
- ES6 modules
|
|
251
|
+
- Modern JavaScript (async/await)
|
|
252
|
+
|
|
253
|
+
## File Structure
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
your-project/
|
|
257
|
+
├── src/
|
|
258
|
+
│ └── swisseph.js # Main library
|
|
259
|
+
├── wsam/
|
|
260
|
+
│ ├── swisseph.js # WASM module
|
|
261
|
+
│ └── swisseph.wasm # WASM binary
|
|
262
|
+
└── your-app.js # Your application
|
|
263
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# SwissEph WebAssembly Library
|
|
2
|
+
|
|
3
|
+
A high-precision JavaScript wrapper for the Swiss Ephemeris WebAssembly module, providing professional-grade astronomical calculations for astrology, astronomy, and related applications.
|
|
4
|
+
|
|
5
|
+
## 🌟 Features
|
|
6
|
+
|
|
7
|
+
- **High Precision**: Based on the renowned Swiss Ephemeris
|
|
8
|
+
- **WebAssembly Performance**: Fast calculations in the browser and Node.js
|
|
9
|
+
- **Comprehensive API**: Full access to Swiss Ephemeris functions
|
|
10
|
+
- **Modern JavaScript**: ES6+ with async/await support
|
|
11
|
+
- **Well Tested**: 106 tests with 86% coverage
|
|
12
|
+
- **Complete Documentation**: Extensive guides and examples
|
|
13
|
+
- **Professional Grade**: Suitable for commercial applications
|
|
14
|
+
|
|
15
|
+
## 📦 Installation
|
|
16
|
+
|
|
17
|
+
### npm
|
|
18
|
+
```bash
|
|
19
|
+
npm install swisseph-wasm
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### yarn
|
|
23
|
+
```bash
|
|
24
|
+
yarn add swisseph-wasm
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### pnpm
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add swisseph-wasm
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 📦 What's Included
|
|
33
|
+
|
|
34
|
+
- **Core Library** (`src/swisseph.js`) - Main JavaScript wrapper
|
|
35
|
+
- **WebAssembly Module** (`wsam/`) - Compiled Swiss Ephemeris
|
|
36
|
+
- **Comprehensive Tests** (`tests/`) - 106 tests covering all functionality
|
|
37
|
+
- **Documentation** - Complete API reference and guides
|
|
38
|
+
- **Examples** - Practical usage examples and patterns
|
|
39
|
+
- **Quick Reference** - Handy developer reference
|
|
40
|
+
- **TypeScript Definitions** - Full type support
|
|
41
|
+
|
|
42
|
+
## 🚀 Quick Start
|
|
43
|
+
|
|
44
|
+
### Basic Usage
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import SwissEph from 'swisseph-wasm';
|
|
48
|
+
|
|
49
|
+
// Create and initialize
|
|
50
|
+
const swe = new SwissEph();
|
|
51
|
+
await swe.initSwissEph();
|
|
52
|
+
|
|
53
|
+
// Calculate planetary position
|
|
54
|
+
const jd = swe.julday(2023, 6, 15, 12.0); // June 15, 2023, 12:00 UTC
|
|
55
|
+
const sunPos = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH);
|
|
56
|
+
|
|
57
|
+
console.log(`Sun longitude: ${sunPos[0]}°`);
|
|
58
|
+
|
|
59
|
+
// Clean up
|
|
60
|
+
swe.close();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Birth Chart Example
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import SwissEph from 'swisseph-wasm';
|
|
67
|
+
|
|
68
|
+
// You can also import the example calculator
|
|
69
|
+
// import { BirthChartCalculator } from 'swisseph-wasm/examples/birth-chart.js';
|
|
70
|
+
|
|
71
|
+
const calculator = new BirthChartCalculator();
|
|
72
|
+
|
|
73
|
+
const chart = await calculator.calculateBirthChart({
|
|
74
|
+
year: 1990, month: 5, day: 15,
|
|
75
|
+
hour: 14, minute: 30, timezone: -5,
|
|
76
|
+
latitude: 40.7128, longitude: -74.0060
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
console.log('Planetary Positions:');
|
|
80
|
+
Object.entries(chart.planets).forEach(([name, planet]) => {
|
|
81
|
+
console.log(`${planet.symbol} ${name}: ${planet.zodiacSign.formatted}`);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
calculator.destroy();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 📚 Documentation
|
|
88
|
+
|
|
89
|
+
| Document | Description |
|
|
90
|
+
|----------|-------------|
|
|
91
|
+
| [**DOCUMENTATION.md**](DOCUMENTATION.md) | Complete API reference and usage guide |
|
|
92
|
+
| [**QUICK_REFERENCE.md**](QUICK_REFERENCE.md) | Quick developer reference |
|
|
93
|
+
| [**examples/README.md**](examples/README.md) | Example usage patterns |
|
|
94
|
+
| [**tests/README.md**](tests/README.md) | Test suite documentation |
|
|
95
|
+
|
|
96
|
+
## 🎯 Core Capabilities
|
|
97
|
+
|
|
98
|
+
### Planetary Calculations
|
|
99
|
+
- All major planets (Sun through Pluto)
|
|
100
|
+
- Lunar nodes and apogee
|
|
101
|
+
- Major asteroids (Chiron, Ceres, Pallas, etc.)
|
|
102
|
+
- Uranian planets
|
|
103
|
+
- Fixed stars
|
|
104
|
+
|
|
105
|
+
### Coordinate Systems
|
|
106
|
+
- Tropical and sidereal positions
|
|
107
|
+
- Geocentric, heliocentric, topocentric
|
|
108
|
+
- Ecliptic and equatorial coordinates
|
|
109
|
+
- Multiple ayanamsa systems
|
|
110
|
+
|
|
111
|
+
### Time Functions
|
|
112
|
+
- Julian Day calculations
|
|
113
|
+
- Time zone conversions
|
|
114
|
+
- Sidereal time
|
|
115
|
+
- Delta T calculations
|
|
116
|
+
- Calendar conversions
|
|
117
|
+
|
|
118
|
+
### Advanced Features
|
|
119
|
+
- Eclipse calculations
|
|
120
|
+
- Rise/set/transit times
|
|
121
|
+
- House systems
|
|
122
|
+
- Aspect calculations
|
|
123
|
+
- Atmospheric refraction
|
|
124
|
+
- Coordinate transformations
|
|
125
|
+
|
|
126
|
+
## 🧪 Testing
|
|
127
|
+
|
|
128
|
+
The library includes a comprehensive test suite with 106 tests:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm install
|
|
132
|
+
npm test # Run all tests
|
|
133
|
+
npm run test:coverage # Run with coverage report
|
|
134
|
+
npm run test:watch # Watch mode
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Test Coverage:**
|
|
138
|
+
- ✅ 106 tests passing
|
|
139
|
+
- ✅ 86.1% statement coverage
|
|
140
|
+
- ✅ 66.66% function coverage
|
|
141
|
+
- ✅ All major functionality covered
|
|
142
|
+
|
|
143
|
+
## 📁 Project Structure
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
swiss-wasm/
|
|
147
|
+
├── src/
|
|
148
|
+
│ └── swisseph.js # Main library file
|
|
149
|
+
├── wsam/
|
|
150
|
+
│ ├── swisseph.js # WebAssembly module
|
|
151
|
+
│ └── swisseph.wasm # WebAssembly binary
|
|
152
|
+
├── tests/
|
|
153
|
+
│ ├── swisseph.test.js # Core functionality tests
|
|
154
|
+
│ ├── swisseph-advanced.test.js # Advanced features tests
|
|
155
|
+
│ ├── swisseph-integration.test.js # Integration tests
|
|
156
|
+
│ ├── swisseph-constants.test.js # Constants validation
|
|
157
|
+
│ ├── __mocks__/ # Mock implementations
|
|
158
|
+
│ └── README.md # Test documentation
|
|
159
|
+
├── examples/
|
|
160
|
+
│ ├── basic-usage.js # Basic usage examples
|
|
161
|
+
│ ├── birth-chart.js # Birth chart calculator
|
|
162
|
+
│ └── README.md # Examples documentation
|
|
163
|
+
├── DOCUMENTATION.md # Complete API reference
|
|
164
|
+
├── QUICK_REFERENCE.md # Quick developer guide
|
|
165
|
+
└── README.md # This file
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## 🌐 Browser Support
|
|
169
|
+
|
|
170
|
+
**Modern Browsers:**
|
|
171
|
+
- Chrome 61+
|
|
172
|
+
- Firefox 60+
|
|
173
|
+
- Safari 11+
|
|
174
|
+
- Edge 16+
|
|
175
|
+
|
|
176
|
+
**Requirements:**
|
|
177
|
+
- WebAssembly support
|
|
178
|
+
- ES6 modules support
|
|
179
|
+
- Async/await support
|
|
180
|
+
|
|
181
|
+
## 💡 Examples
|
|
182
|
+
|
|
183
|
+
### Current Planetary Positions
|
|
184
|
+
```javascript
|
|
185
|
+
async function getCurrentPositions() {
|
|
186
|
+
const swe = new SwissEph();
|
|
187
|
+
await swe.initSwissEph();
|
|
188
|
+
|
|
189
|
+
const now = new Date();
|
|
190
|
+
const jd = swe.julday(
|
|
191
|
+
now.getUTCFullYear(),
|
|
192
|
+
now.getUTCMonth() + 1,
|
|
193
|
+
now.getUTCDate(),
|
|
194
|
+
now.getUTCHours() + now.getUTCMinutes() / 60
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const planets = [swe.SE_SUN, swe.SE_MOON, swe.SE_MERCURY];
|
|
198
|
+
const positions = {};
|
|
199
|
+
|
|
200
|
+
for (const planet of planets) {
|
|
201
|
+
const pos = swe.calc_ut(jd, planet, swe.SEFLG_SWIEPH);
|
|
202
|
+
positions[swe.get_planet_name(planet)] = pos[0];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
swe.close();
|
|
206
|
+
return positions;
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Sidereal vs Tropical
|
|
211
|
+
```javascript
|
|
212
|
+
async function compareSystems(year, month, day) {
|
|
213
|
+
const swe = new SwissEph();
|
|
214
|
+
await swe.initSwissEph();
|
|
215
|
+
|
|
216
|
+
const jd = swe.julday(year, month, day, 12);
|
|
217
|
+
|
|
218
|
+
// Tropical
|
|
219
|
+
const tropical = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH);
|
|
220
|
+
|
|
221
|
+
// Sidereal (Lahiri)
|
|
222
|
+
swe.set_sid_mode(swe.SE_SIDM_LAHIRI, 0, 0);
|
|
223
|
+
const sidereal = swe.calc_ut(jd, swe.SE_SUN, swe.SEFLG_SWIEPH | swe.SEFLG_SIDEREAL);
|
|
224
|
+
|
|
225
|
+
swe.close();
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
tropical: tropical[0],
|
|
229
|
+
sidereal: sidereal[0],
|
|
230
|
+
difference: tropical[0] - sidereal[0]
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## 🔧 Development
|
|
236
|
+
|
|
237
|
+
### Running Examples
|
|
238
|
+
```bash
|
|
239
|
+
# Basic usage examples
|
|
240
|
+
node examples/basic-usage.js
|
|
241
|
+
|
|
242
|
+
# Birth chart calculation
|
|
243
|
+
node examples/birth-chart.js
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Performance Tips
|
|
247
|
+
1. **Reuse instances** for multiple calculations
|
|
248
|
+
2. **Batch operations** in single sessions
|
|
249
|
+
3. **Always clean up** with `swe.close()`
|
|
250
|
+
4. **Validate inputs** before calculations
|
|
251
|
+
5. **Use appropriate flags** for your needs
|
|
252
|
+
|
|
253
|
+
### Error Handling
|
|
254
|
+
```javascript
|
|
255
|
+
async function safeCalculation() {
|
|
256
|
+
let swe = null;
|
|
257
|
+
try {
|
|
258
|
+
swe = new SwissEph();
|
|
259
|
+
await swe.initSwissEph();
|
|
260
|
+
// calculations here
|
|
261
|
+
return result;
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.error('Calculation failed:', error);
|
|
264
|
+
return null;
|
|
265
|
+
} finally {
|
|
266
|
+
if (swe) swe.close();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## 📄 License
|
|
272
|
+
|
|
273
|
+
This library is a wrapper around the Swiss Ephemeris, which is licensed under the GNU General Public License (GPL) for non-commercial use. For commercial use, a license from Astrodienst is required.
|
|
274
|
+
|
|
275
|
+
**Swiss Ephemeris License:**
|
|
276
|
+
- Non-commercial use: Free under GPL
|
|
277
|
+
- Commercial use: Requires license from [Astrodienst](https://www.astro.com/swisseph/)
|
|
278
|
+
|
|
279
|
+
## 🤝 Contributing
|
|
280
|
+
|
|
281
|
+
1. Fork the repository
|
|
282
|
+
2. Create a feature branch
|
|
283
|
+
3. Add tests for new functionality
|
|
284
|
+
4. Ensure all tests pass
|
|
285
|
+
5. Update documentation
|
|
286
|
+
6. Submit a pull request
|
|
287
|
+
|
|
288
|
+
## 📞 Support
|
|
289
|
+
|
|
290
|
+
- **Documentation**: Check the comprehensive docs in this repository
|
|
291
|
+
- **Examples**: Review the examples directory for usage patterns
|
|
292
|
+
- **Tests**: Look at test files for detailed usage examples
|
|
293
|
+
- **Issues**: File issues on the project repository
|
|
294
|
+
|
|
295
|
+
## 🏆 Credits
|
|
296
|
+
|
|
297
|
+
- **Swiss Ephemeris**: Created by Astrodienst AG
|
|
298
|
+
- **WebAssembly Port**: Compiled for web use
|
|
299
|
+
- **JavaScript Wrapper**: Modern ES6+ interface
|
|
300
|
+
- **Test Suite**: Comprehensive validation
|
|
301
|
+
- **Documentation**: Complete developer guides
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
**Ready to calculate the cosmos? Start with the [Quick Reference](QUICK_REFERENCE.md) or dive into the [Complete Documentation](DOCUMENTATION.md)!** 🌟
|