nhb-toolbox 4.23.23 → 4.23.25

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
@@ -6,10 +6,18 @@ All notable changes to the package will be documented here.
6
6
 
7
7
  ---
8
8
 
9
+ ## [4.23.25] - 2025-10-27
10
+
11
+ - **Updated** tsdoc for `Chronos` *constructor* and **optimized** *internal logic* for some *checker methods*.
12
+
13
+ ## [4.23.24] - 2025-10-26
14
+
15
+ - **Fixed** *pluralization issue* with ***suffixed*** `'-foot' --> '-feet'` for *format methods* in *converter classes*.
16
+
9
17
  ## [4.23.23] - 2025-10-26
10
18
 
11
19
  - **Fixed** *pluralization issue* with `'foot' --> 'feet'` for *format methods* in *converter classes*.
12
- - **Renamed** the export of `GENERAL_UNITS` (used in `Unit` class) and `CATEGORIZED_UNITS` (used in `Converter` classes) from `'nhb-toolbox/constants'`.
20
+ - **Exported** `GENERAL_UNITS` (used in `Unit` class) and `CATEGORIZED_UNITS` (used in `Converter` classes) from `'nhb-toolbox/constants'`.
13
21
 
14
22
  ## [4.23.21] - 2025-10-25
15
23
 
@@ -15,7 +15,7 @@ class $BaseConverter {
15
15
  const pluralized = abs <= 1 ? u
16
16
  : u ?
17
17
  u?.endsWith('foot') ?
18
- 'feet'
18
+ u.replace(/foot$/, 'feet')
19
19
  : `${u}s`
20
20
  : '';
21
21
  return `${abs} ${pluralized}`.trim();
@@ -393,18 +393,18 @@ class Chronos {
393
393
  }
394
394
  isSame(other, unit, weekStartsOn = 0) {
395
395
  const time = other instanceof _a ? other : new _a(other);
396
- return (this.startOf(unit, weekStartsOn).toDate().getTime() ===
397
- time.startOf(unit, weekStartsOn).toDate().getTime());
396
+ return (this.startOf(unit, weekStartsOn).timestamp ===
397
+ time.startOf(unit, weekStartsOn).timestamp);
398
398
  }
399
399
  isBefore(other, unit, weekStartsOn = 0) {
400
400
  const time = other instanceof _a ? other : new _a(other);
401
- return (this.startOf(unit, weekStartsOn).toDate().getTime() <
402
- time.startOf(unit, weekStartsOn).toDate().getTime());
401
+ return (this.startOf(unit, weekStartsOn).timestamp <
402
+ time.startOf(unit, weekStartsOn).timestamp);
403
403
  }
404
404
  isAfter(other, unit, weekStartsOn = 0) {
405
405
  const time = other instanceof _a ? other : new _a(other);
406
- return (this.startOf(unit, weekStartsOn).toDate().getTime() >
407
- time.startOf(unit, weekStartsOn).toDate().getTime());
406
+ return (this.startOf(unit, weekStartsOn).timestamp >
407
+ time.startOf(unit, weekStartsOn).timestamp);
408
408
  }
409
409
  isSameOrBefore(other, unit, weekStartsOn = 0) {
410
410
  return (this.isSame(other, unit, weekStartsOn) || this.isBefore(other, unit, weekStartsOn));
@@ -8,7 +8,7 @@ import { $Time } from './time';
8
8
  import type { $Unit, Converted } from './types';
9
9
  import { $Volume } from './volume';
10
10
  /**
11
- * @function Converter : This is a unit converter function that creates instances of specific converter classes based on the provided unit.
11
+ * @function Converter - This is a unit converter function that creates instances of specific converter class based on the provided unit.
12
12
  *
13
13
  * @description Converts values between compatible units (time, length, data, temperature, mass, area, volume).
14
14
  * The returned instance exposes only methods relevant to the provided unit type.
@@ -87,7 +87,7 @@ export declare class $BaseConverter<Unit extends $Unit> {
87
87
  divide(n: Numeric): this;
88
88
  /**
89
89
  * @instance Rounds to given decimal places.
90
- * @param decimals Number of decimal places to round.
90
+ * @param decimals Number of decimal places to round. Default is `0`.
91
91
  * @returns A new instance with rounded value.
92
92
  */
93
93
  round(decimals?: number): this;
@@ -31,9 +31,9 @@ export declare class Chronos {
31
31
  /** Use `readonly and/or private` methods outside `Chronos`. Purpose: Plugin creation. */
32
32
  protected static [INTERNALS]: ChronosInternals;
33
33
  /**
34
- * * `Chronos` date/time in Native JS `Date` format.
34
+ * * `Chronos` date/time as Native JS `Date` object.
35
35
  *
36
- * - **NOTE**: It is **HIGHLY** advised *not to rely* on this public property to access native JS `Date`. It's not reliable when timezone and/or UTC related operations are performed. If you really need to use native `Date`, use `toDate` method. THis property is purely for developer convenience and sugar.
36
+ * - **NOTE**: It is **HIGHLY** advised *not to rely* on this public property to access native JS `Date`. It's not reliable when timezone and/or UTC related operations are performed. If you really need to use native `Date`, use `toDate` method. This property is purely for developer convenience and sugar.
37
37
  */
38
38
  native: Date;
39
39
  /** Origin of the `Chronos` instance (Method that created `new Chronos`), useful fo tracking instance. */
@@ -68,9 +68,6 @@ export declare class Chronos {
68
68
  /**
69
69
  * * Creates a new immutable `Chronos` instance.
70
70
  *
71
- * **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
72
- * and convert it to the **equivalent local time** using the current environment's UTC offset.*
73
- *
74
71
  * @param value - A date value as `Date` object, it will be used as is.
75
72
  *
76
73
  * @returns Instance of `Chronos` with all methods and properties.
@@ -79,9 +76,6 @@ export declare class Chronos {
79
76
  /**
80
77
  * * Creates a new immutable `Chronos` instance.
81
78
  *
82
- * **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
83
- * and convert it to the **equivalent local time** using the current environment's UTC offset.*
84
- *
85
79
  * @param value - A date value as `Chronos` object.
86
80
  *
87
81
  * @returns Instance of `Chronos` with all methods and properties.
@@ -175,7 +169,7 @@ export declare class Chronos {
175
169
  /** @instance Returns a date as a string value in ISO format. */
176
170
  toISOString(): string;
177
171
  /**
178
- * @instance Wrapper over native `toLocaleString`
172
+ * @instance Wrapper over native `toLocaleString`.
179
173
  * @description Converts a date and time to a string by using the current or specified locale.
180
174
  *
181
175
  * @param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
@@ -212,9 +206,9 @@ export declare class Chronos {
212
206
  * (e.g., `'Sun, Apr 06, 2025 16:11:55'`).
213
207
  * - Please refer to {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos/format#format-tokens format tokens} for detailed usage.
214
208
  *
215
- * @param useUTC - If `true`, formats the date in UTC (equivalent to `formatUTC()`);
209
+ * @param useUTC - If `true`, formats the date in UTC (equivalent to `formatUTC()`).
216
210
  * Defaults to `false` (local time).
217
- * @returns A formatted date string in the specified format
211
+ * @returns A formatted date string in the specified format.
218
212
  */
219
213
  formatStrict(format?: StrictFormat, useUTC?: boolean): string;
220
214
  /**
@@ -12,7 +12,7 @@ export class $BaseConverter {
12
12
  const pluralized = abs <= 1 ? u
13
13
  : u ?
14
14
  u?.endsWith('foot') ?
15
- 'feet'
15
+ u.replace(/foot$/, 'feet')
16
16
  : `${u}s`
17
17
  : '';
18
18
  return `${abs} ${pluralized}`.trim();
@@ -390,18 +390,18 @@ export class Chronos {
390
390
  }
391
391
  isSame(other, unit, weekStartsOn = 0) {
392
392
  const time = other instanceof _a ? other : new _a(other);
393
- return (this.startOf(unit, weekStartsOn).toDate().getTime() ===
394
- time.startOf(unit, weekStartsOn).toDate().getTime());
393
+ return (this.startOf(unit, weekStartsOn).timestamp ===
394
+ time.startOf(unit, weekStartsOn).timestamp);
395
395
  }
396
396
  isBefore(other, unit, weekStartsOn = 0) {
397
397
  const time = other instanceof _a ? other : new _a(other);
398
- return (this.startOf(unit, weekStartsOn).toDate().getTime() <
399
- time.startOf(unit, weekStartsOn).toDate().getTime());
398
+ return (this.startOf(unit, weekStartsOn).timestamp <
399
+ time.startOf(unit, weekStartsOn).timestamp);
400
400
  }
401
401
  isAfter(other, unit, weekStartsOn = 0) {
402
402
  const time = other instanceof _a ? other : new _a(other);
403
- return (this.startOf(unit, weekStartsOn).toDate().getTime() >
404
- time.startOf(unit, weekStartsOn).toDate().getTime());
403
+ return (this.startOf(unit, weekStartsOn).timestamp >
404
+ time.startOf(unit, weekStartsOn).timestamp);
405
405
  }
406
406
  isSameOrBefore(other, unit, weekStartsOn = 0) {
407
407
  return (this.isSame(other, unit, weekStartsOn) || this.isBefore(other, unit, weekStartsOn));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.23.23",
3
+ "version": "4.23.25",
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",