nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.
25 lines (24 loc) • 841 B
JavaScript
import { ZODIAC_PRESETS } from '../constants.js';
/** * Plugin to inject `getZodiacSign` method */
export 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 ?? ZODIAC_PRESETS[preset];
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];
};
};