nhb-toolbox 4.31.0 → 4.31.2

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,14 @@
4
4
 
5
5
  All notable changes to the package will be documented here.
6
6
 
7
+ ## [4.31.2] - 2026-06-28
8
+
9
+ - **Updated** tsdoc for `relativeTimePlugin` `Chronos` instance methods.
10
+
11
+ ## [4.31.1] - 2026-06-28
12
+
13
+ - **Fixed** immutability issue with conversion to `Date` object for all the *date utilities* including `Chronos` constructor and plugins.
14
+
7
15
  ## [4.31.0] - 2026-06-16
8
16
 
9
17
  - **Added** new *methods* for `Color` class: `toString()`, `toJSON()`, `Symbol.toPrimitive`.
@@ -105,7 +105,7 @@ class Chronos {
105
105
  #toNewDate(value) {
106
106
  const date = value instanceof _a ? value.toDate() : (0, helpers_1._dateArgsToDate)(value);
107
107
  if (Number.isNaN(date.getTime())) {
108
- throw new Error('Provided date is invalid!');
108
+ throw new TypeError('Provided date is invalid!');
109
109
  }
110
110
  return date;
111
111
  }
@@ -156,9 +156,11 @@ function _padShunno(str, length = 2) {
156
156
  return str.padStart(length, '০');
157
157
  }
158
158
  function _dateArgsToDate(value) {
159
- return (0, non_primitives_1.isDate)(value)
159
+ return new Date((0, non_primitives_1.isDate)(value)
160
160
  ? value
161
- : new Date((0, primitives_1.isString)(value) ? value.replace(/['"]/g, '') : (value ?? Date.now()));
161
+ : (0, primitives_1.isString)(value)
162
+ ? value.replace(/['"]/g, '')
163
+ : (value ?? Date.now()));
162
164
  }
163
165
  function _hasChronosProperties(value) {
164
166
  return ((0, non_primitives_1.isObjectWithKeys)(value, [
@@ -2,60 +2,55 @@ import type { $Chronos, ChronosInput, TimeUnit } from '../types';
2
2
  declare module '../Chronos' {
3
3
  interface Chronos {
4
4
  /**
5
- * @instance Returns the number of full years between the input date and now.
5
+ * @instance Returns the number of full years between the input date and the current instance.
6
6
  * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time.
7
- * @returns The difference in number, negative when `Chronos` time is a past time else positive.
7
+ * @returns The difference in number, negative if past, positive if future.
8
8
  */
9
9
  getRelativeYear(time?: ChronosInput): number;
10
10
  /**
11
- * @instance Returns the number of full months between the input date and now.
11
+ * @instance Returns the number of full months between the input date and the current instance.
12
12
  * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time.
13
- * @returns The difference in number, negative when `Chronos` time is a past time else positive.
13
+ * @returns The difference in number, negative if past, positive if future.
14
14
  */
15
15
  getRelativeMonth(time?: ChronosInput): number;
16
16
  /**
17
- * @instance Determines if the given date is today, tomorrow, yesterday or any relative day.
18
- * @param date - The date to compare (Date object).
17
+ * @instance Determines how many full weeks apart the input date is from the `Chronos` instance.
19
18
  * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time.
20
- * @returns
21
- * - `-1` if the date is yesterday.
22
- * - `0` if the date is today.
23
- * - `1` if the date is tomorrow.
24
- * - Other positive or negative numbers for other relative days (e.g., `-2` for two days ago, `2` for two days ahead).
19
+ * @returns The difference in number, negative if past, positive if future.
25
20
  */
26
21
  getRelativeWeek(time?: ChronosInput): number;
27
22
  /**
28
- * @instance Returns the number of full hours between the input date and now.
23
+ * @instance Returns the number of full days between the input date and the current instance.
29
24
  * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time.
30
- * @returns The difference in number, negative when `Chronos` time is a past time else positive.
25
+ * @returns The difference in number, negative if past, positive if future.
31
26
  */
32
27
  getRelativeDay(time?: ChronosInput): number;
33
28
  /**
34
- * @instance Determines how many full weeks apart the input date is from the `Chronos` instance.
29
+ * @instance Determines how many full hours apart the input date is from the `Chronos` instance.
35
30
  * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time.
36
- * @returns Difference in weeks; negative if past, positive if future.
31
+ * @returns The difference in number, negative if past, positive if future.
37
32
  */
38
33
  getRelativeHour(time?: ChronosInput): number;
39
34
  /**
40
- * @instance Returns the number of full minutes between the input date and now.
35
+ * @instance Returns the number of full minutes between the input date and the current instance.
41
36
  * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time.
42
- * @returns The difference in number, negative when `Chronos` time is a past time else positive.
37
+ * @returns The difference in number, negative if past, positive if future.
43
38
  */
44
39
  getRelativeMinute(time?: ChronosInput): number;
45
40
  /**
46
- * @instance Returns the number of full seconds between the input date and now.
41
+ * @instance Returns the number of full seconds between the input date and the current instance.
47
42
  * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time.
48
- * @returns The difference in number, negative when `Chronos` time is a past time else positive.
43
+ * @returns The difference in number, negative if past, positive if future.
49
44
  */
50
45
  getRelativeSecond(time?: ChronosInput): number;
51
46
  /**
52
- * @instance Returns the number of milliseconds between the input date and now.
47
+ * @instance Returns the number of milliseconds between the input date and the current instance.
53
48
  * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time.
54
- * @returns The difference in number, negative when `Chronos` time is a past time else positive.
49
+ * @returns The difference in number, negative if past, positive if future.
55
50
  */
56
51
  getRelativeMilliSecond(time?: ChronosInput): number;
57
52
  /**
58
- * @instance Compares the stored date with now, returning the relative difference in the specified unit.
53
+ * @instance Compares the stored date with the current instance, returning the relative difference in the specified unit.
59
54
  *
60
55
  * @remarks
61
56
  * - Internally uses {@link getRelativeYear}, {@link getRelativeMonth}, {@link getRelativeWeek}, {@link getRelativeDay}, {@link getRelativeHour}, {@link getRelativeMinute}, {@link getRelativeSecond} and {@link getRelativeMilliSecond} and rounds the result.
@@ -63,7 +58,7 @@ declare module '../Chronos' {
63
58
  *
64
59
  * @param unit The time unit to compare by. Defaults to `'minute'`.
65
60
  * @param time Optional time to compare with the `Chronos` date/time. Defaults to current time.
66
- * @returns The difference in number, negative when `Chronos` time is a past time else positive.
61
+ * @returns The difference in number, negative if past, positive if future.
67
62
  */
68
63
  compare(unit?: TimeUnit, time?: ChronosInput): number;
69
64
  /** @instance Checks if the current date is today. */
@@ -102,7 +102,7 @@ export class Chronos {
102
102
  #toNewDate(value) {
103
103
  const date = value instanceof _a ? value.toDate() : _dateArgsToDate(value);
104
104
  if (Number.isNaN(date.getTime())) {
105
- throw new Error('Provided date is invalid!');
105
+ throw new TypeError('Provided date is invalid!');
106
106
  }
107
107
  return date;
108
108
  }
@@ -134,9 +134,11 @@ export function _padShunno(str, length = 2) {
134
134
  return str.padStart(length, '০');
135
135
  }
136
136
  export function _dateArgsToDate(value) {
137
- return isDate(value)
137
+ return new Date(isDate(value)
138
138
  ? value
139
- : new Date(isString(value) ? value.replace(/['"]/g, '') : (value ?? Date.now()));
139
+ : isString(value)
140
+ ? value.replace(/['"]/g, '')
141
+ : (value ?? Date.now()));
140
142
  }
141
143
  export function _hasChronosProperties(value) {
142
144
  return (isObjectWithKeys(value, [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.31.0",
3
+ "version": "4.31.2",
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",
@@ -44,12 +44,12 @@
44
44
  },
45
45
  "license": "Apache-2.0",
46
46
  "devDependencies": {
47
- "@biomejs/biome": "^2.5.0",
47
+ "@biomejs/biome": "^2.5.1",
48
48
  "@types/jest": "^30.0.0",
49
- "@types/node": "^25.9.3",
49
+ "@types/node": "^26.0.1",
50
50
  "husky": "^9.1.7",
51
51
  "jest": "^30.4.2",
52
- "lint-staged": "^17.0.7",
52
+ "lint-staged": "^17.0.8",
53
53
  "nhb-scripts": "^1.9.2",
54
54
  "ts-jest": "^29.4.11",
55
55
  "typescript": "^6.0.3"