nhb-toolbox 4.28.60 → 4.28.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
All notable changes to the package will be documented here.
|
|
6
6
|
|
|
7
|
+
## [4.28.64] - 2026-01-15
|
|
8
|
+
|
|
9
|
+
- **Added** new `zodiacPlugin` method: `getZodiacMeta` to retrieve zodiac *metadata* for a given *zodiac sign*.
|
|
10
|
+
|
|
7
11
|
## [4.28.60] - 2026-01-13
|
|
8
12
|
|
|
9
13
|
- **Fixed** `Chronos.getZodiacSign` boundary handling to correctly wrap across year transitions for *zodiac presets*.
|
|
@@ -2,9 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zodiacPlugin = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
|
+
const helpers_1 = require("../helpers");
|
|
5
6
|
const zodiacPlugin = ($Chronos) => {
|
|
7
|
+
function _toHundreds(range) {
|
|
8
|
+
return range[0] * 100 + range[1];
|
|
9
|
+
}
|
|
10
|
+
function _resolveSigns(options) {
|
|
11
|
+
const { preset = 'western', custom } = options ?? {};
|
|
12
|
+
const sorted = [...(custom ?? constants_1.ZODIAC_PRESETS[preset])].sort((a, b) => _toHundreds(a[1]) - _toHundreds(b[1]));
|
|
13
|
+
return sorted;
|
|
14
|
+
}
|
|
6
15
|
$Chronos.prototype.getZodiacSign = function (options) {
|
|
7
|
-
const { birthDate
|
|
16
|
+
const { birthDate } = options ?? {};
|
|
8
17
|
let month;
|
|
9
18
|
let date;
|
|
10
19
|
if (birthDate && birthDate?.includes('-')) {
|
|
@@ -14,23 +23,35 @@ const zodiacPlugin = ($Chronos) => {
|
|
|
14
23
|
month = this.isoMonth;
|
|
15
24
|
date = this.date;
|
|
16
25
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const signs = [...(custom ?? constants_1.ZODIAC_PRESETS[preset])].sort((a, b) => _toHundreds(a[1]) - _toHundreds(b[1]));
|
|
21
|
-
for (let i = signs.length - 1; i >= 0; i--) {
|
|
22
|
-
const [sign, [m, d]] = signs[i];
|
|
26
|
+
const sortedSigns = _resolveSigns(options);
|
|
27
|
+
for (let i = sortedSigns.length - 1; i >= 0; i--) {
|
|
28
|
+
const [sign, [m, d]] = sortedSigns[i];
|
|
23
29
|
if (month > m || (month === m && date >= d)) {
|
|
24
30
|
return sign;
|
|
25
31
|
}
|
|
26
32
|
if (i === 0) {
|
|
27
|
-
return
|
|
33
|
+
return sortedSigns.at(-1)[0];
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
|
-
return
|
|
36
|
+
return sortedSigns[0][0];
|
|
31
37
|
};
|
|
32
38
|
$Chronos.prototype.zodiac = function (options) {
|
|
33
39
|
return this.getZodiacSign(options);
|
|
34
40
|
};
|
|
41
|
+
$Chronos.prototype.getZodiacMeta = function (sign, options) {
|
|
42
|
+
const sortedSigns = _resolveSigns(options);
|
|
43
|
+
const index = sortedSigns.findIndex(([s]) => s === sign);
|
|
44
|
+
if (index === -1) {
|
|
45
|
+
throw new RangeError(`Invalid zodiac sign: "${sign}"`);
|
|
46
|
+
}
|
|
47
|
+
const [startMonth, startDate] = sortedSigns[index][1];
|
|
48
|
+
const [endMonth, endDate] = (sortedSigns[index + 1] ?? sortedSigns[0])[1];
|
|
49
|
+
return {
|
|
50
|
+
index,
|
|
51
|
+
sign,
|
|
52
|
+
start: `${(0, helpers_1._padZero)(startMonth)}-${(0, helpers_1._padZero)(startDate)}`,
|
|
53
|
+
end: `${(0, helpers_1._padZero)(endMonth)}-${(0, helpers_1._padZero)(endDate - 1)}`,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
35
56
|
};
|
|
36
57
|
exports.zodiacPlugin = zodiacPlugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { $Chronos, ZodiacOptions, ZodiacSign } from '../types';
|
|
1
|
+
import type { $Chronos, ZodiacMeta, ZodiacMetaOptions, ZodiacOptions, ZodiacSign } from '../types';
|
|
2
2
|
declare module '../Chronos' {
|
|
3
3
|
interface Chronos {
|
|
4
4
|
/**
|
|
@@ -15,6 +15,22 @@ declare module '../Chronos' {
|
|
|
15
15
|
* @returns The matching zodiac sign from preset/custom list.
|
|
16
16
|
*/
|
|
17
17
|
zodiac<Sign extends string = ZodiacSign>(options?: ZodiacOptions<Sign>): Sign;
|
|
18
|
+
/**
|
|
19
|
+
* @instance Returns detailed metadata for a given zodiac sign based on the selected `preset` or custom ranges.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* - The metadata includes the sign's `index` within the normalized zodiac order, its inclusive start and end dates.
|
|
23
|
+
* - **Note:** The returned `index` represents the chronological position of the zodiac sign based on Gregorian month–day ordering and may vary between different zodiac variants.
|
|
24
|
+
* - Handles year-boundary wrapping correctly (e.g. Capricorn, Sagittarius).
|
|
25
|
+
*
|
|
26
|
+
* @param sign The zodiac sign to retrieve metadata for.
|
|
27
|
+
* @param options Optional configuration to select a zodiac preset or provide custom ranges.
|
|
28
|
+
*
|
|
29
|
+
* @throws A {@link RangeError} if the provided sign does not exist in the resolved zodiac set.
|
|
30
|
+
*
|
|
31
|
+
* @returns A metadata object describing the zodiac sign's position and date range.
|
|
32
|
+
*/
|
|
33
|
+
getZodiacMeta<Sign extends string = ZodiacSign>(sign: Sign, options?: ZodiacMetaOptions<Sign>): ZodiacMeta<Sign>;
|
|
18
34
|
}
|
|
19
35
|
}
|
|
20
36
|
/** * Plugin to inject `zodiac` related methods */
|
package/dist/dts/date/types.d.ts
CHANGED
|
@@ -310,15 +310,38 @@ export type ZodiacSign = (typeof WESTERN_ZODIAC_SIGNS)[number][0];
|
|
|
310
310
|
export type ZodiacPreset = keyof typeof ZODIAC_PRESETS;
|
|
311
311
|
/** Shape of Zodiac signs array */
|
|
312
312
|
export type ZodiacArray<Sign extends string = ZodiacSign> = Array<[Sign, [NumberRange<1, 12>, NumberRange<1, 31>]] | Readonly<[Sign, Readonly<[NumberRange<1, 12>, NumberRange<1, 31>]>]>>;
|
|
313
|
-
/**
|
|
314
|
-
export interface
|
|
315
|
-
/**
|
|
316
|
-
|
|
317
|
-
|
|
313
|
+
/** Zodiac metadata options */
|
|
314
|
+
export interface ZodiacMetaOptions<Sign extends string = ZodiacSign> {
|
|
315
|
+
/**
|
|
316
|
+
* Optional Zodiac preset to use. Default is `western`.
|
|
317
|
+
* - **Note:** `western` and `tropical`, `vedic` and `sidereal` are same.
|
|
318
|
+
*/
|
|
318
319
|
preset?: ZodiacPreset;
|
|
319
|
-
/** Custom Zodiac date ranges
|
|
320
|
+
/** Custom Zodiac date ranges, overrides {@link preset presets}. */
|
|
320
321
|
custom?: ZodiacArray<Sign> | Readonly<ZodiacArray<Sign>>;
|
|
321
322
|
}
|
|
323
|
+
/** Options for configuring Zodiac sign getter */
|
|
324
|
+
export interface ZodiacOptions<Sign extends string = ZodiacSign> extends ZodiacMetaOptions<Sign> {
|
|
325
|
+
/** - Optional birthdate in `MM-DD` format (`1`-based month). */
|
|
326
|
+
birthDate?: MonthDateString;
|
|
327
|
+
}
|
|
328
|
+
/** Represents resolved metadata for a zodiac sign */
|
|
329
|
+
export interface ZodiacMeta<Sign extends string = ZodiacSign> {
|
|
330
|
+
/**
|
|
331
|
+
* Index (`0`-based) of the zodiac sign within the resolved and chronologically sorted zodiac list.
|
|
332
|
+
*
|
|
333
|
+
* ⚠️ **Notes:**
|
|
334
|
+
* - The `index` is determined by the Gregorian month–day order of zodiac start dates and may differ between variants (e.g. Western vs Vedic).
|
|
335
|
+
* - This `index` should not be interpreted as a traditional or mythological zodiac ordering.
|
|
336
|
+
*/
|
|
337
|
+
index: number;
|
|
338
|
+
/** The zodiac sign name. */
|
|
339
|
+
sign: Sign;
|
|
340
|
+
/** Inclusive start date of the zodiac sign in `MM-DD` format. */
|
|
341
|
+
start: MonthDateString;
|
|
342
|
+
/** Inclusive end date of the zodiac sign in `MM-DD` format. */
|
|
343
|
+
end: MonthDateString;
|
|
344
|
+
}
|
|
322
345
|
/** - Represents the full name of a weekday, e.g., 'Monday', 'Tuesday' etc. */
|
|
323
346
|
export type WeekDay = (typeof DAYS)[number];
|
|
324
347
|
/** - Represents the full name of a month, e.g., 'January', 'February' etc. */
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { ZODIAC_PRESETS } from '../constants.js';
|
|
2
|
+
import { _padZero } from '../helpers.js';
|
|
2
3
|
export const zodiacPlugin = ($Chronos) => {
|
|
4
|
+
function _toHundreds(range) {
|
|
5
|
+
return range[0] * 100 + range[1];
|
|
6
|
+
}
|
|
7
|
+
function _resolveSigns(options) {
|
|
8
|
+
const { preset = 'western', custom } = options ?? {};
|
|
9
|
+
const sorted = [...(custom ?? ZODIAC_PRESETS[preset])].sort((a, b) => _toHundreds(a[1]) - _toHundreds(b[1]));
|
|
10
|
+
return sorted;
|
|
11
|
+
}
|
|
3
12
|
$Chronos.prototype.getZodiacSign = function (options) {
|
|
4
|
-
const { birthDate
|
|
13
|
+
const { birthDate } = options ?? {};
|
|
5
14
|
let month;
|
|
6
15
|
let date;
|
|
7
16
|
if (birthDate && birthDate?.includes('-')) {
|
|
@@ -11,22 +20,34 @@ export const zodiacPlugin = ($Chronos) => {
|
|
|
11
20
|
month = this.isoMonth;
|
|
12
21
|
date = this.date;
|
|
13
22
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const signs = [...(custom ?? ZODIAC_PRESETS[preset])].sort((a, b) => _toHundreds(a[1]) - _toHundreds(b[1]));
|
|
18
|
-
for (let i = signs.length - 1; i >= 0; i--) {
|
|
19
|
-
const [sign, [m, d]] = signs[i];
|
|
23
|
+
const sortedSigns = _resolveSigns(options);
|
|
24
|
+
for (let i = sortedSigns.length - 1; i >= 0; i--) {
|
|
25
|
+
const [sign, [m, d]] = sortedSigns[i];
|
|
20
26
|
if (month > m || (month === m && date >= d)) {
|
|
21
27
|
return sign;
|
|
22
28
|
}
|
|
23
29
|
if (i === 0) {
|
|
24
|
-
return
|
|
30
|
+
return sortedSigns.at(-1)[0];
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
|
-
return
|
|
33
|
+
return sortedSigns[0][0];
|
|
28
34
|
};
|
|
29
35
|
$Chronos.prototype.zodiac = function (options) {
|
|
30
36
|
return this.getZodiacSign(options);
|
|
31
37
|
};
|
|
38
|
+
$Chronos.prototype.getZodiacMeta = function (sign, options) {
|
|
39
|
+
const sortedSigns = _resolveSigns(options);
|
|
40
|
+
const index = sortedSigns.findIndex(([s]) => s === sign);
|
|
41
|
+
if (index === -1) {
|
|
42
|
+
throw new RangeError(`Invalid zodiac sign: "${sign}"`);
|
|
43
|
+
}
|
|
44
|
+
const [startMonth, startDate] = sortedSigns[index][1];
|
|
45
|
+
const [endMonth, endDate] = (sortedSigns[index + 1] ?? sortedSigns[0])[1];
|
|
46
|
+
return {
|
|
47
|
+
index,
|
|
48
|
+
sign,
|
|
49
|
+
start: `${_padZero(startMonth)}-${_padZero(startDate)}`,
|
|
50
|
+
end: `${_padZero(endMonth)}-${_padZero(endDate - 1)}`,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
32
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "4.28.
|
|
3
|
+
"version": "4.28.64",
|
|
4
4
|
"description": "A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|