This project is an updated version of the swisseph library, originally designed to provide Swiss Ephemeris calculations for Node.js applications. The Swiss Ephemeris is a highly precise ephemeris developed by Astrodienst AG, used for astrological calculations.
The original swisseph project made the power of the Swiss Ephemeris accessible to Node.js developers but was not maintained for compatibility with the latest versions of Node.js. This fork aims to update the library, ensuring it works seamlessly with the most recent Node.js and npm versions, thereby extending its utility to the current development environment.
This work builds upon the original swisseph project. The original project can be found at [\https://www.npmjs.com/package/swisseph]. I am deeply grateful to author for their pioneering work on making the Swiss Ephemeris accessible to the Node.js community. This updated version stands as a testament to the foundational work laid by the original author(s).
See Swiss Ephemeris for more details.
Visit our website: shilaavinyaas which uses this library for calculations.
Supported platforms: Mac OS X | Windows | Linux | FreeBSD
To install run:
$ npm install swisseph-v2
Compatibility with the latest Node.js versions. All original swisseph functionality preserved and made accessible for modern Node.js environments.
import * as Swisseph from 'swisseph-v2';
export default class vBase {
static setHouseMethod(hsys:string) {
this.houseMethod = hsys;
}
static setEphemeridesPath(path: string | null = null) {
if (path) {
Swisseph.swe_set_ephe_path(path);
}
}
static getPlanet(date: Date, planet: number):any {
const julianDate = this.toJulianUTCDate(date);
const flags = Swisseph.SEFLG_SPEED;
const planetData = Swisseph.swe_calc_ut(julianDate, planet, flags);
return planetData;
}
static toJulianUTCDate(date: Date) {
const julianDay = Swisseph.swe_utc_to_jd(
date.getUTCFullYear(),
date.getUTCMonth() + 1,
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
0,
Swisseph.SE_GREG_CAL
);
let jdUT : any;
if ('julianDayUT' in julianDay) {
jdUT =julianDay.julianDayUT;
}else if ('error' in julianDay) {
// Handle the error case
jdUT = julianDay.error;
}
return jdUT;
}
static toGregorianUTCDate(julianDate:number):any {
return Swisseph.swe_jdut1_to_utc(julianDate, Swisseph.SE_GREG_CAL);
}
}
var swisseph = require ('swisseph-v2');
var date = {year: 2015, month: 1, day: 1, hour: 0};
var julday = swisseph.swe_julday (date.year, date.month, date.day, date.hour, swisseph.SE_GREG_CAL);
Example:
var swisseph = require ('swisseph-v2');
// Test date
var date = {year: 2012, month: 1, day: 1, hour: 0};
console.log ('Test date:', date);
var flag = swisseph.SEFLG_SPEED;
// path to ephemeris data
swisseph.swe_set_ephe_path (__dirname + '/../ephe');
// Julian day
swisseph.swe_julday (date.year, date.month, date.day, date.hour, swisseph.SE_GREG_CAL, function (julday_ut) {
assert.equal (julday_ut, 2455927.5);
console.log ('Julian UT day for date:', julday_ut);
// Sun position
swisseph.swe_calc_ut (julday_ut, swisseph.SE_SUN, flag, function (body) {
assert (!body.error, body.error);
console.log ('Sun position:', body);
});
// Moon position
swisseph.swe_calc_ut (julday_ut, swisseph.SE_MOON, flag, function (body) {
assert (!body.error, body.error);
console.log ('Moon position:', body);
});
});
For more examples see examples and test folders.
On computing planet, star, node or apside positions, and using SEFLG_EQUATORIAL or SEFLG_XYZ in flag bits, name of the resulting property will be different from the case with ecliptic coordinates. Run examples/issue-23.js in details, please.
There are 3 different types of ephemeris supported:
- Steve Moshier interpolation, covers 3000 BC – 3000 AD, preision 0.1 arcsec, no data files required.
- Swiss Ephemeris is compressed version of DE431, covers 13000 BC - 17000 AD, precision 0.001 arcseconds, requires data files about 90MB. Download from ftp://www.astro.com/pub/swisseph/ephe.
- JPL NASA ephemeris is the state of the art ephemeris, DE431 covers 13000 BC - 17000 AD, maximum possible precision, requires data files 2.9GB. Download from ftp://www.astro.com/pub/jplfiles.
To use data files download them and put in folder then set path to the ephemeris folder by:
swisseph.swe_set_ephe_path ('/path/to/downloaded/ephemeris');
And select ephemeris by setting the flag:
// for Moshier
body = swisseph.swe_calc_ut (julday_ut, swisseph.SE_SUN, swisseph.SEFLG_SPEED | swisseph.SEFLG_MOSEPH)
// for Swiss Ephemeris
body = swisseph.swe_calc_ut (julday_ut, swisseph.SE_SUN, swisseph.SEFLG_SPEED | swisseph.SEFLG_SWIEPH)
// for JPL NASA ephemeris
body = swisseph.swe_calc_ut (julday_ut, swisseph.SE_SUN, swisseph.SEFLG_SPEED | swisseph.SEFLG_JPLEPH)
To execute tests run from the root folder:
npm test
See Programming interface to the Swiss Ephemeris for more details.
This javascript programming interface is little different from the original api, basically for return values. For more details see src/*.h.
Please feel free to fill issues for bugs, erros and features.
The license for this project is the same as original Swiss Ephemeris.