nhb-toolbox 4.28.6 → 4.28.8

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,9 +6,18 @@ All notable changes to the package will be documented here.
6
6
 
7
7
  ---
8
8
 
9
+ ## [4.28.8] - 2025-12-03
10
+
11
+ - **Fixed** a *tree-shaking issue* affecting `Chronos` and other *date/time utilities* by removing a *pre-compiled* `RegExp` instance from **date/constants**.
12
+
13
+ ## [4.28.7] - 2025-12-02
14
+
15
+ - **Updated** *invalid links* in *tsdoc* of the *hash utilities*.
16
+ - **Implemented** input type *validation* for `sha256` utility.
17
+
9
18
  ## [4.28.6] - 2025-12-02
10
19
 
11
- - **Updated** *tsdoc* for `stableStringify` + *type augmentation* for `String` methods: `toLowerCase` and `toUpperCase`
20
+ - **Updated** *tsdoc* for `stableStringify` + *type augmentation* for `String` methods: `toLowerCase` and `toUpperCase`.
12
21
 
13
22
  ## [4.28.4] - 2025-12-02
14
23
 
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MS_MAP = exports.TIME_UNIT_REGEX = exports.TIME_UNIT_VARIANTS = exports.ZODIAC_PRESETS = exports.VEDIC_ZODIAC_SIGNS = exports.WESTERN_ZODIAC_SIGNS = exports.DATE_PART_RANGES = exports.SORTED_TIME_FORMATS = exports.TIME_FORMATS = exports.MILLISECOND_FORMATS = exports.ZONE_FORMATS = exports.SECOND_FORMATS = exports.MINUTE_FORMATS = exports.HOUR_FORMATS = exports.DAY_FORMATS = exports.DATE_FORMATS = exports.MONTH_FORMATS = exports.YEAR_FORMATS = exports.MONTHS = exports.DAYS = exports.INTERNALS = void 0;
3
+ exports.MS_MAP = exports.TIME_UNIT_VARIANTS = exports.ZODIAC_PRESETS = exports.VEDIC_ZODIAC_SIGNS = exports.WESTERN_ZODIAC_SIGNS = exports.DATE_PART_RANGES = exports.SORTED_TIME_FORMATS = exports.TIME_FORMATS = exports.MILLISECOND_FORMATS = exports.ZONE_FORMATS = exports.SECOND_FORMATS = exports.MINUTE_FORMATS = exports.HOUR_FORMATS = exports.DAY_FORMATS = exports.DATE_FORMATS = exports.MONTH_FORMATS = exports.YEAR_FORMATS = exports.MONTHS = exports.DAYS = exports.INTERNALS = void 0;
4
4
  exports.INTERNALS = Symbol('Internals');
5
5
  exports.DAYS = /* @__PURE__ */ Object.freeze([
6
6
  'Sunday',
@@ -106,11 +106,6 @@ exports.TIME_UNIT_VARIANTS = /* @__PURE__ */ Object.freeze({
106
106
  second: ['s', 'sec', 'secs', 'second', 'seconds'],
107
107
  millisecond: ['ms', 'msec', 'msecs', 'millisecond', 'milliseconds'],
108
108
  });
109
- const TIME_UNIT_REGEX_STR = /* @__PURE__ */ Object.freeze(Object.values(exports.TIME_UNIT_VARIANTS)
110
- .flat()
111
- .sort((a, b) => b.length - a.length)
112
- .join('|'));
113
- exports.TIME_UNIT_REGEX = /* @__PURE__ */ Object.freeze(new RegExp(`^(?<value>-?\\d*\\.?\\d+) *(?<unit>${TIME_UNIT_REGEX_STR})?$`, 'i'));
114
109
  exports.MS_MAP = /* @__PURE__ */ Object.freeze((() => {
115
110
  const s = 1000;
116
111
  const m = s * 60;
@@ -10,7 +10,6 @@ exports.isTimeWithUnit = isTimeWithUnit;
10
10
  const primitives_1 = require("../guards/primitives");
11
11
  const specials_1 = require("../guards/specials");
12
12
  const utilities_1 = require("../number/utilities");
13
- const constants_1 = require("./constants");
14
13
  const timezone_1 = require("./timezone");
15
14
  function isValidTime(value) {
16
15
  if (!(0, primitives_1.isNonEmptyString)(value))
@@ -67,5 +66,6 @@ function isDateLike(value) {
67
66
  return false;
68
67
  }
69
68
  function isTimeWithUnit(value) {
70
- return (0, primitives_1.isNonEmptyString)(value) && constants_1.TIME_UNIT_REGEX.test(value);
69
+ return ((0, primitives_1.isNonEmptyString)(value) &&
70
+ /^-?\d*\.?\d+ *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.test(value));
71
71
  }
@@ -21,7 +21,7 @@ function _parse(str, sec = false) {
21
21
  if (!(0, primitives_1.isNonEmptyString)(str) || str.length > 100) {
22
22
  throw new RangeError(`Value must be a string with length between 1 and 99!`);
23
23
  }
24
- const match = constants_1.TIME_UNIT_REGEX.exec(str);
24
+ const match = /^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(str);
25
25
  if (!match?.groups)
26
26
  return NaN;
27
27
  const unit = (match.groups.unit ?? 'ms').toLowerCase();
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.md5 = md5;
4
4
  exports.sha1 = sha1;
5
5
  exports.sha256 = sha256;
6
+ const primitives_1 = require("../guards/primitives");
6
7
  const helpers_1 = require("./helpers");
7
8
  const utils_1 = require("./utils");
8
9
  function md5(str) {
@@ -85,5 +86,7 @@ function sha1(msg) {
85
86
  return h.map(toHex).join('');
86
87
  }
87
88
  function sha256(msg) {
89
+ if (!(0, primitives_1.isString)(msg))
90
+ throw new TypeError('Input must be of type string!');
88
91
  return (0, utils_1.bytesToHex)((0, utils_1.sha256Bytes)((0, utils_1.utf8ToBytes)(msg)));
89
92
  }
@@ -40,7 +40,5 @@ export declare const TIME_UNIT_VARIANTS: Readonly<{
40
40
  readonly second: readonly ["s", "sec", "secs", "second", "seconds"];
41
41
  readonly millisecond: readonly ["ms", "msec", "msecs", "millisecond", "milliseconds"];
42
42
  }>;
43
- /** `RegExp` for time unit variants */
44
- export declare const TIME_UNIT_REGEX: Readonly<RegExp>;
45
43
  /** Map to different time units to milliseconds */
46
44
  export declare const MS_MAP: Readonly<Record<"year" | "y" | "yr" | "yrs" | "years" | "month" | "mo" | "months" | "week" | "w" | "weeks" | "day" | "d" | "days" | "hour" | "h" | "hr" | "hrs" | "hours" | "minute" | "m" | "min" | "mins" | "minutes" | "second" | "s" | "sec" | "secs" | "seconds" | "millisecond" | "ms" | "msec" | "msecs" | "milliseconds", number>>;
@@ -486,8 +486,12 @@ export type ChronosWithOptions = Partial<{
486
486
  /** Milliseconds of the second, from 0 to 999. */
487
487
  millisecond: Milliseconds;
488
488
  }>;
489
+ /** Mapped type to {@link TIME_UNIT_VARIANTS} */
490
+ export type $TimeUnitVarMap = typeof TIME_UNIT_VARIANTS;
491
+ /** Key of {@link TIME_UNIT_VARIANTS} */
492
+ export type $TimeUnitKey = keyof typeof TIME_UNIT_VARIANTS;
489
493
  /** Variants of different time units in lowercase */
490
- export type $TimeUnitVar = (typeof TIME_UNIT_VARIANTS)[keyof typeof TIME_UNIT_VARIANTS][number];
494
+ export type $TimeUnitVar<U extends $TimeUnitKey = $TimeUnitKey> = $TimeUnitVarMap[U][number];
491
495
  /** Variants of different time units in lowercase, uppercase and capitalized */
492
496
  export type $UnitAnyCase = Capitalize<$TimeUnitVar> | Uppercase<$TimeUnitVar> | $TimeUnitVar;
493
497
  /** Number (time value) with variants of different time units */
@@ -59,8 +59,8 @@ export declare function sha1(msg: string): string;
59
59
  * // Returns: '7037e204b825b83553ba336a6ec35b796d505599286ae864729ed6cb33ae9fe1'
60
60
  * ```
61
61
  *
62
- * @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/sha256Bytes sha256Bytes} for hashing raw bytes
62
+ * @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#sha256bytes sha256Bytes} for hashing raw bytes
63
63
  * @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#utf8tobytes utf8ToBytes} for converting string to bytes
64
- * @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#bytestotex bytesToHex} for converting bytes to a hexadecimal string
64
+ * @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#bytestohex bytesToHex} for converting bytes to a hexadecimal string
65
65
  */
66
66
  export declare function sha256(msg: string): string;
@@ -124,7 +124,6 @@ export declare function getClassDetails(cls: Constructor): ClassDetails;
124
124
  * * Create a deterministic JSON string representation of any value.
125
125
  * - The output format matches standard JSON but with guaranteed sorted keys.
126
126
  *
127
- *
128
127
  * @remarks
129
128
  * - This function guarantees **stable, repeatable output** by:
130
129
  * - Sorting all object keys alphabetically.
@@ -103,11 +103,6 @@ export const TIME_UNIT_VARIANTS = /* @__PURE__ */ Object.freeze({
103
103
  second: ['s', 'sec', 'secs', 'second', 'seconds'],
104
104
  millisecond: ['ms', 'msec', 'msecs', 'millisecond', 'milliseconds'],
105
105
  });
106
- const TIME_UNIT_REGEX_STR = /* @__PURE__ */ Object.freeze(Object.values(TIME_UNIT_VARIANTS)
107
- .flat()
108
- .sort((a, b) => b.length - a.length)
109
- .join('|'));
110
- export const TIME_UNIT_REGEX = /* @__PURE__ */ Object.freeze(new RegExp(`^(?<value>-?\\d*\\.?\\d+) *(?<unit>${TIME_UNIT_REGEX_STR})?$`, 'i'));
111
106
  export const MS_MAP = /* @__PURE__ */ Object.freeze((() => {
112
107
  const s = 1000;
113
108
  const m = s * 60;
@@ -1,7 +1,6 @@
1
1
  import { isNonEmptyString, isString } from '../guards/primitives.js';
2
2
  import { isNumericString } from '../guards/specials.js';
3
3
  import { normalizeNumber } from '../number/utilities.js';
4
- import { TIME_UNIT_REGEX } from './constants.js';
5
4
  import { IANA_TZ_IDS } from './timezone.js';
6
5
  export function isValidTime(value) {
7
6
  if (!isNonEmptyString(value))
@@ -58,5 +57,6 @@ export function isDateLike(value) {
58
57
  return false;
59
58
  }
60
59
  export function isTimeWithUnit(value) {
61
- return isNonEmptyString(value) && TIME_UNIT_REGEX.test(value);
60
+ return (isNonEmptyString(value) &&
61
+ /^-?\d*\.?\d+ *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.test(value));
62
62
  }
@@ -1,6 +1,6 @@
1
1
  import { isNonEmptyString, isNumber } from '../guards/primitives.js';
2
2
  import { isNumericString } from '../guards/specials.js';
3
- import { MS_MAP, TIME_UNIT_REGEX } from './constants.js';
3
+ import { MS_MAP } from './constants.js';
4
4
  import { isTimeWithUnit } from './guards.js';
5
5
  export function parseMSec(value, sec = false) {
6
6
  if (isNumericString(value)) {
@@ -18,7 +18,7 @@ function _parse(str, sec = false) {
18
18
  if (!isNonEmptyString(str) || str.length > 100) {
19
19
  throw new RangeError(`Value must be a string with length between 1 and 99!`);
20
20
  }
21
- const match = TIME_UNIT_REGEX.exec(str);
21
+ const match = /^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(str);
22
22
  if (!match?.groups)
23
23
  return NaN;
24
24
  const unit = (match.groups.unit ?? 'ms').toLowerCase();
@@ -1,3 +1,4 @@
1
+ import { isString } from '../guards/primitives.js';
1
2
  import { _md5cycle, _numToHex, _stringToNumbers } from './helpers.js';
2
3
  import { bytesToHex, sha256Bytes, utf8ToBytes } from './utils.js';
3
4
  export function md5(str) {
@@ -80,5 +81,7 @@ export function sha1(msg) {
80
81
  return h.map(toHex).join('');
81
82
  }
82
83
  export function sha256(msg) {
84
+ if (!isString(msg))
85
+ throw new TypeError('Input must be of type string!');
83
86
  return bytesToHex(sha256Bytes(utf8ToBytes(msg)));
84
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.28.6",
3
+ "version": "4.28.8",
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",