wadjet
Version:
The your birth date is based on statistical psychology and will expose your personality. This package as a mocule does its calculations.
115 lines (93 loc) • 3.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _isNan = require('babel-runtime/core-js/number/is-nan');
var _isNan2 = _interopRequireDefault(_isNan);
var _coefMonthly = require('../master/coefMonthly');
var _coefMonthly2 = _interopRequireDefault(_coefMonthly);
var _lifeBase = require('../master/lifeBase');
var _lifeBase2 = _interopRequireDefault(_lifeBase);
var _lifeBaseCoef = require('../master/lifeBaseCoef');
var _lifeBaseCoef2 = _interopRequireDefault(_lifeBaseCoef);
var _natures = require('../master/natures');
var _natures2 = _interopRequireDefault(_natures);
var _potential = require('../master/potential');
var _potential2 = _interopRequireDefault(_potential);
require('../type');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Create to year, month, date and coefficient of date from input.
* @param {Date|string} birth Birthday.
* @return {Wadjet.CoefMonthly & {date: number}}
* @throws {Error} When birthday was out of range.
*/
var ymd = function ymd(birth) {
var ld = typeof birth === 'string' ? new Date(birth) : birth;
var dcoef = (0, _coefMonthly2.default)(ld);
if ((0, _isNan2.default)(dcoef)) {
throw new Error();
}
return {
year: Math.floor(ld.getFullYear()),
month: Math.floor(ld.getMonth() + 1),
date: Math.floor(ld.getDate()),
dcoef: dcoef
};
};
/**
* Generate the calculation function of the nature and the potential.
* @param {number} cycle cycle coef.
*/
var naturePotential = function naturePotential(cycle) {
var code = function code(func, limit) {
return (
/**
* @param {number} v
* @returns {string}
*/
function (v) {
return func({ x: (v % limit || limit) - 1, y: cycle });
}
);
};
return { mn: code(_natures2.default, 12), mp: code(_potential2.default, 10) };
};
/**
* Get personality from birthday.
* @param {Date|string} birth Birthday.
*
* It can be set from 1873-02-01 to 2050-12-31.
* @returns {Wadjet.Personality} Personality.
* @throws {Error} When birthday specified invalid value.
*/
var personality = function personality(birth) {
var _ymd = ymd(birth),
year = _ymd.year,
month = _ymd.month,
date = _ymd.date,
dcoef = _ymd.dcoef;
var yh = Math.floor(year * 0.01);
var early = Math.floor(month <= 2);
var icoef = month + early * 12;
var inner = [5.25 * (year % 100 - early), 0.6 * (icoef + 1), 4.25 * yh].reduce(function (p, c) {
return p + Math.floor(c);
}, date + 1);
var ge = date >= dcoef;
var outer = (month - Math.floor(!ge) || 12) + 1;
var ymb = year - (month === 2 && ge ? early : 0);
var lbc = (0, _lifeBaseCoef2.default)(month, date - dcoef) - 1;
var cycle = (inner + 6) % 10;
var _naturePotential = naturePotential(cycle),
mn = _naturePotential.mn,
mp = _naturePotential.mp;
return {
inner: mn(inner + yh * 4 + icoef * 6),
outer: mn(outer),
cycle: cycle || 10,
lifeBase: (0, _lifeBase2.default)({ x: lbc, y: cycle }),
potential: mp(ymb + 7) + '-' + mp(year * 2 + outer + 2),
workstyle: mn(ymb + 9)
};
};
exports.default = personality;