@hatijs/helper
Version:
Node.js library, which has increased usability in @hatijs/core library.
235 lines (234 loc) • 9.28 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.position = void 0;
var core_1 = __importDefault(require("@hatijs/core"));
var _1 = require(".");
var position = function (tjdUT, geoLon, geoLat) {
/**
* Gets the position of the house 'name' according to 'hsys'.
* @param hsys House system name
* @param dodecatemoria Indication of dodecatemoria information
* @param name House 'Name' to know the position
* @returns Constellation name and Position of longitude (absolute, relative)
*/
var getHouse = function (hsys, dodecatemoria) {
var houses = _1.util.getHouses(tjdUT, geoLon, geoLat, hsys);
return function (name) {
var result = _1.util.convertDegreeToPosition(houses[name.toLowerCase()]);
if (dodecatemoria) {
return __assign(__assign({}, result), { dodecatemoria: _getDodecatemoria(result.position.longitude) });
}
return result;
};
};
/**
* Gets the position of the house 'number' according to 'hsys'.
* @param hsys House system name
* @param dodecatemoria Indication of dodecatemoria information
* @param number House 'number' to know the position
* @returns Constellation name and Position of longitude (absolute, relative)
*/
var getHouses = function (hsys, dodecatemoria) {
var houses = _1.util.getHouses(tjdUT, geoLon, geoLat, hsys).house;
return function (number) {
var result = _1.util.convertDegreeToPosition(houses[number]);
if (dodecatemoria) {
return __assign(__assign({}, result), { dodecatemoria: _getDodecatemoria(result.position.longitude) });
}
return result;
};
};
/**
* Gets the position according to the planet 'name'.
* @param name Name of planet you want to know position of
* @param dodecatemoria Indication of dodecatemoria information
* @returns Constellation name and Position of longitude, latitude, rectAscension, declination, Speed of longitude, latitude
*/
var getPlanet = function (name, dodecatemoria) {
var _a;
var planet = _1.constant.PLANET[name];
var resultSpeed = core_1.default.node_swe_calc_ut(tjdUT, planet, core_1.default.SEFLG_SPEED);
var resultEquatorial = core_1.default.node_swe_calc_ut(tjdUT, planet, core_1.default.SEFLG_EQUATORIAL);
if ('error' in resultSpeed)
throw new Error(resultSpeed.error);
if ('error' in resultEquatorial)
throw new Error(resultEquatorial.error);
var result = {
name: Object.keys(_1.constant.PLANET)[(_a = Object.values(_1.constant.PLANET)
.map(function (v, i) { return (v === planet ? i : undefined); })
.filter(function (v) { return v; })[0]) !== null && _a !== void 0 ? _a : 0],
constellation: {
name: '',
},
position: {
longitude: {
absolute: 0,
relative: 0,
},
latitude: 0,
rectAscension: 0,
declination: 0,
},
speed: {
absolute: {
longitude: 0,
latitude: 0,
},
relative: {
longitude: 0,
},
},
};
if ('longitude' in resultSpeed && 'declination' in resultEquatorial) {
result.constellation = {
name: _1.constant.CONSTELLATION[_1.util.getConstellationIndexFromLongitude(resultSpeed.longitude)],
};
result.position = {
longitude: {
absolute: resultSpeed.longitude,
relative: resultSpeed.longitude -
_1.util.getConstellationIndexFromLongitude(resultSpeed.longitude) *
30,
},
latitude: resultSpeed.latitude,
rectAscension: resultEquatorial.rectAscension,
declination: resultEquatorial.declination,
};
result.speed = {
absolute: {
longitude: resultSpeed.longitudeSpeed,
latitude: resultSpeed.latitudeSpeed,
},
relative: {
longitude: 0,
},
};
if (name in _1.constant.SPEED.AVERAGE.DIRECT) {
result.speed.relative = {
longitude: resultSpeed.longitudeSpeed >= 0
? resultSpeed.longitudeSpeed /
_1.constant.SPEED.AVERAGE.DIRECT[(name)]
: resultSpeed.longitudeSpeed /
_1.constant.SPEED.AVERAGE.RETROGRADE[name],
};
}
if (dodecatemoria) {
return __assign(__assign({}, result), { dodecatemoria: _getDodecatemoria(result.position.longitude) });
}
}
return result;
};
/**
* Gets the position according to the lot 'name'.
* @param name Name of lot you want to know position of
* @param dodecatemoria Indication of dodecatemoria information
* @returns Constellation name and Position of longitude
*/
var getLot = function (name, dodecatemoria) {
var isDiurnal = _1.util.isDiurnal(tjdUT, geoLon, geoLat);
var asc = _1.util.getHouses(tjdUT, geoLon, geoLat, 'WHOLE_SIGN');
var acquisition = function () {
return fortune() + 10 * 30;
};
var basis = function () {
var lotOfFortune = fortune();
var lotOfSpirit = fortune(true);
var love = asc.ascendant +
(isDiurnal
? lotOfSpirit - lotOfFortune
: lotOfFortune - lotOfSpirit);
var necessity = asc.ascendant +
(isDiurnal
? lotOfFortune - lotOfSpirit
: lotOfSpirit - lotOfFortune);
return _1.util.isDiurnal(tjdUT, geoLon, geoLat, love)
? necessity
: love;
};
var exaltation = function () {
var sun = getPlanet('SUN');
var moon = getPlanet('MOON');
return (asc.ascendant +
(isDiurnal
? 19 - sun.position.longitude.absolute
: 33 - moon.position.longitude.absolute));
};
var fortune = function (inversion) {
if (inversion === void 0) { inversion = false; }
var sun = getPlanet('SUN');
var moon = getPlanet('MOON');
return (asc.ascendant +
((isDiurnal && !inversion) || (!isDiurnal && inversion)
? moon.position.longitude.absolute -
sun.position.longitude.absolute
: sun.position.longitude.absolute -
moon.position.longitude.absolute));
};
var result;
switch (name) {
case 'ACQUISITION': {
result = acquisition();
break;
}
case 'BASIS': {
result = basis();
break;
}
case 'EXALTATION': {
result = exaltation();
break;
}
case 'FORTUNE': {
result = fortune();
break;
}
case 'SPIRIT': {
result = fortune(true);
break;
}
}
result = _1.util.convertDegreeToPosition(result);
if (dodecatemoria) {
return __assign(__assign({}, result), { dodecatemoria: _getDodecatemoria(result.position.longitude) });
}
return result;
};
var _getDodecatemoria = function (longitude) {
var absolute = (_1.util.getConstellationIndexFromLongitude(longitude.absolute) * 30 +
longitude.relative * 12) %
360;
return {
constellation: {
name: _1.constant.CONSTELLATION[_1.util.getConstellationIndexFromLongitude(absolute)],
},
position: {
longitude: {
absolute: absolute,
relative: absolute -
_1.util.getConstellationIndexFromLongitude(absolute) * 30,
},
},
};
};
return {
getHouse: getHouse,
getHouses: getHouses,
getPlanet: getPlanet,
getLot: getLot,
};
};
exports.position = position;