@hatijs/helper
Version:
Node.js library, which has increased usability in @hatijs/core library.
151 lines (150 loc) • 6.24 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.util = void 0;
var core_1 = __importDefault(require("@hatijs/core"));
var _1 = require(".");
var prefixDegree = function (funcA) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return funcA(((args[0] % 360) + 360) % 360);
};
};
var convertDegreeToDMS = prefixDegree(function (degree) { return ({
degree: Math.floor(degree % 30),
minute: Math.floor((degree * 60) % 60),
second: Math.floor((degree * 60 * 60) % 60),
}); });
var convertDegreeToPosition = prefixDegree(function (degree) { return ({
constellation: {
name: _1.constant.CONSTELLATION[getConstellationIndexFromLongitude(degree)],
},
position: {
longitude: {
absolute: degree,
relative: degree - getConstellationIndexFromLongitude(degree) * 30,
},
},
}); });
var convertUpperCaseToCapitalize = function (str) {
return str.toLowerCase().replace(/\b[a-z]/g, function (char) { return char.toUpperCase(); });
};
var createEnumObject = function (o) { return o; };
var prefixEnumObject = function (o, prefix) {
return Object.keys(o)
.map(function (key) {
var _a;
return (_a = {}, _a["".concat(prefix).concat(key)] = "".concat(prefix).concat(key), _a);
})
.reduce(function (json, cur) { return (__assign(__assign({}, json), cur)); }, {});
};
var getConstellationIndexFromLongitude = prefixDegree(function (longitude) { return Math.floor(longitude / 30) % 12; });
var getConstellationIndexFromConstellationName = function (name) { return Object.values(_1.constant.CONSTELLATION).indexOf(name); };
var getDuodecatemorion = prefixDegree(function (degree) {
return convertDegreeToPosition((degree % 30) * 12 + Math.floor(degree / 30) * 30);
});
var getHouses = function (tjdUT, geoLon, geoLat, hsys) {
var result = core_1.default.node_swe_houses(tjdUT, geoLat, geoLon, hsys);
if ('error' in result)
throw new Error(result.error);
return result;
};
var getVersion = function () { return core_1.default.node_swe_version(); };
var isDiurnal = function (tjdUT, geoLon, geoLat, posPoint) {
var posHouse = exports.util.getHouses(tjdUT, geoLon, geoLat, 'WHOLE_SIGN');
if (!posPoint) {
posPoint = (0, _1.position)(tjdUT, geoLon, geoLat).getPlanet('SUN').position
.longitude.absolute;
}
return !(posPoint > posHouse.ascendant && posHouse.ascendant + 180 >= posPoint);
};
exports.util = {
/**
* Converts the radian degree to the sexagesimal measure.
* @param degree Radian degree you want to convert
* @returns Sexagesimal measure (Degree, Minute, Second)
*/
convertDegreeToDMS: convertDegreeToDMS,
/**
* Converts the radian degree to the position.
* @param degree Radian degree you want to convert
* @returns Constellation name, Position of longitude (absolute, relative)
*/
convertDegreeToPosition: convertDegreeToPosition,
/**
* Converts only the first letter to uppercase.
* @param str The string you want to convert
* @returns Captilized string
*/
convertUpperCaseToCapitalize: convertUpperCaseToCapitalize,
/**
* An object suitable for a given type is input and a corresponding object is generated.
* @param o Objects for a given type T
* @returns Implemented objects with a given type T
*/
createEnumObject: createEnumObject,
/**
* A new object with a prefix is created by receiving an object suitable for a given type and a given type.
* @param o Objects for a given type T
* @param prefix Prefix to apply to the object's key, value
* @returns Implemented objects with a given type T
*/
prefixEnumObject: prefixEnumObject,
/**
* Gets the constellation index according to the order of Aries-Pieces constellation according to the given longitude.
* @param longitude
* @returns Constellation Index according to the order of Aries-Pieces constellation
*/
getConstellationIndexFromLongitude: getConstellationIndexFromLongitude,
/**
* Gets the constellation index according to the order of Aries-Pieces constellation according to the given constellation 'name'.
* @param name Constellation name
* @returns Constellation Index according to the order of Aries-Pieces constellation
*/
getConstellationIndexFromConstellationName: getConstellationIndexFromConstellationName,
/**
* Gets the position of the duodecatemorion according to the given degree.
* @param degree The radian degree you want to calculate
* @returns Duodecatemorion radian degree
*/
getDuodecatemorion: getDuodecatemorion,
/**
* Gets house information according to the given information.
* @param tjdUT Julian date based on UTC time zone
* @param geoLon Radian longitude
* @param geoLat Radian Latitude
* @param hsys House system name
* @returns House position information
*/
getHouses: getHouses,
/**
* Get node SWE version.
* @returns version
*/
getVersion: getVersion,
/**
* Gets whether a particular point is located in the upper half of the chart or whether the chart is a day chart.
* @param tjdUT Julian date based on UTC time zone
* @param geoLon Radian longitude
* @param geoLat Radian Latitude
* @param posPoint Position of the point to be calculated. If not given, the standard is sun
* @returns Whether it is located in the upper half of the chart
*/
isDiurnal: isDiurnal,
};