UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.

29 lines (28 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zodiacPlugin = void 0; const constants_1 = require("../constants"); /** * Plugin to inject `getZodiacSign` method */ const zodiacPlugin = (ChronosClass) => { ChronosClass.prototype.getZodiacSign = function (options) { const { birthDate, preset = 'western', custom } = options ?? {}; let month; let date; if (birthDate && birthDate?.includes('-')) { [month, date] = birthDate.split('-').map(Number); } else { month = this.isoMonth; date = this.date; } const signs = [...(custom ?? constants_1.ZODIAC_PRESETS[preset])].sort((a, b) => a[1][0] * 100 + a[1][1] - (b[1][0] * 100 + b[1][1])); for (let i = signs.length - 1; i >= 0; i--) { const [sign, [m, d]] = signs[i]; if (month > m || (month === m && date >= d)) { return sign; } } return signs[0][0]; }; }; exports.zodiacPlugin = zodiacPlugin;