UNPKG

nhb-toolbox

Version:

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

25 lines (24 loc) 916 B
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])].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]; }; };