nhb-toolbox 4.30.24 → 4.31.0

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/array/helpers.js +3 -11
  3. package/dist/cjs/array/transform.js +1 -1
  4. package/dist/cjs/colors/Color.js +28 -12
  5. package/dist/cjs/colors/convert.js +1 -1
  6. package/dist/cjs/colors/helpers.js +1 -1
  7. package/dist/cjs/colors/initials.js +2 -4
  8. package/dist/cjs/date/BanglaCalendar.js +1 -1
  9. package/dist/cjs/date/Chronos.js +2 -2
  10. package/dist/cjs/date/plugins/banglaPlugin.js +2 -2
  11. package/dist/cjs/date/plugins/zodiacPlugin.js +3 -3
  12. package/dist/cjs/date/utils.js +3 -3
  13. package/dist/cjs/form/convert.js +6 -2
  14. package/dist/cjs/guards/specials.js +1 -1
  15. package/dist/cjs/hash/TextCodec.js +4 -4
  16. package/dist/cjs/hash/utils.js +2 -2
  17. package/dist/cjs/number/basics.js +1 -1
  18. package/dist/cjs/number/convert.js +2 -2
  19. package/dist/cjs/number/fibonacci.js +2 -1
  20. package/dist/cjs/number/percent.js +1 -1
  21. package/dist/cjs/object/sanitize.js +1 -1
  22. package/dist/cjs/string/basics.js +1 -1
  23. package/dist/cjs/string/case.js +3 -3
  24. package/dist/dts/colors/Color.d.ts +29 -0
  25. package/dist/dts/guards/specials.d.ts +1 -1
  26. package/dist/dts/string/case.d.ts +13 -13
  27. package/dist/dts/string/types.d.ts +2 -0
  28. package/dist/esm/array/helpers.js +3 -11
  29. package/dist/esm/array/transform.js +1 -1
  30. package/dist/esm/colors/Color.js +28 -12
  31. package/dist/esm/colors/convert.js +1 -1
  32. package/dist/esm/colors/helpers.js +1 -1
  33. package/dist/esm/colors/initials.js +2 -4
  34. package/dist/esm/date/BanglaCalendar.js +1 -1
  35. package/dist/esm/date/Chronos.js +2 -2
  36. package/dist/esm/date/plugins/banglaPlugin.js +2 -2
  37. package/dist/esm/date/plugins/zodiacPlugin.js +3 -3
  38. package/dist/esm/date/utils.js +3 -3
  39. package/dist/esm/form/convert.js +6 -2
  40. package/dist/esm/guards/specials.js +1 -1
  41. package/dist/esm/hash/TextCodec.js +4 -4
  42. package/dist/esm/hash/utils.js +2 -2
  43. package/dist/esm/number/basics.js +1 -1
  44. package/dist/esm/number/convert.js +2 -2
  45. package/dist/esm/number/fibonacci.js +2 -1
  46. package/dist/esm/number/percent.js +1 -1
  47. package/dist/esm/object/sanitize.js +1 -1
  48. package/dist/esm/string/basics.js +1 -1
  49. package/dist/esm/string/case.js +3 -3
  50. package/package.json +10 -9
package/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@
4
4
 
5
5
  All notable changes to the package will be documented here.
6
6
 
7
+ ## [4.31.0] - 2026-06-16
8
+
9
+ - **Added** new *methods* for `Color` class: `toString()`, `toJSON()`, `Symbol.toPrimitive`.
10
+ - **Fixed** multiple bugs and lint errors/warnings across the codebase.
11
+
12
+ ## [4.30.26] - 2026-06-09
13
+
14
+ - **Fixed** issues with *delimiter normalizer* and *updated return types* for *non-literal strings* in *string case converter* utilities.
15
+
7
16
  ## [4.30.20-24] - 2026-05-26
8
17
 
9
18
  - **Updated** `isValidUTCOffset`: Strict matching of offset format `+HH:MM` or `-HH:MM` (00-14h, 00/15/30/45m).
@@ -10,19 +10,11 @@ function _resolveNestedKey(obj, path) {
10
10
  if ((0, non_primitives_1.isNotEmptyObject)(acc)) {
11
11
  return acc[key];
12
12
  }
13
+ return undefined;
13
14
  }, obj);
14
15
  }
15
16
  }
16
17
  function _getNumericProp(obj, path) {
17
- if ((0, non_primitives_1.isNotEmptyObject)(obj)) {
18
- const value = path?.split('.').reduce((acc, key) => {
19
- if ((0, non_primitives_1.isNotEmptyObject)(acc)) {
20
- return acc[key];
21
- }
22
- }, obj);
23
- return (0, utilities_1.normalizeNumber)(value) ?? 0;
24
- }
25
- else {
26
- return 0;
27
- }
18
+ const value = _resolveNestedKey(obj, path);
19
+ return (0, utilities_1.normalizeNumber)(value) ?? 0;
28
20
  }
@@ -14,7 +14,7 @@ const index_1 = require("../utils/index");
14
14
  const helpers_1 = require("./helpers");
15
15
  function createOptionsArray(data, config) {
16
16
  const { firstFieldKey, secondFieldKey, firstFieldName = 'value', secondFieldName = 'label', retainNumberValue = false, } = config || {};
17
- if (data && data?.length) {
17
+ if (data?.length) {
18
18
  return data?.map((datum) => {
19
19
  const firstValue = retainNumberValue && (0, primitives_1.isNumber)(datum[firstFieldKey])
20
20
  ? datum[firstFieldKey]
@@ -68,6 +68,16 @@ class Color {
68
68
  yield this.hsl;
69
69
  yield this.hsla;
70
70
  }
71
+ [Symbol.toPrimitive](hint) {
72
+ if (hint === 'string') {
73
+ return this.hex8;
74
+ }
75
+ else if (hint === 'number') {
76
+ const hex = this.hex8.endsWith('FF') ? this.hex : this.hex8;
77
+ return parseInt(hex.replace('#', '0x'), 16);
78
+ }
79
+ return this;
80
+ }
71
81
  #hex6ToHex8(hex) {
72
82
  return `${hex.toUpperCase()}${(0, utils_1.percentToHex)(100)}`;
73
83
  }
@@ -79,6 +89,12 @@ class Color {
79
89
  const [h, s, l] = (0, utils_1.extractSolidColorValues)(hsl);
80
90
  return `hsla(${h}, ${s}%, ${l}%, 1)`;
81
91
  }
92
+ toString() {
93
+ return this.hex8;
94
+ }
95
+ toJSON() {
96
+ return this.hex8;
97
+ }
82
98
  applyOpacity(opacity) {
83
99
  const hex8 = `${this.hex.slice(0, 7)}${(0, utils_1.percentToHex)(opacity)}`.toUpperCase();
84
100
  return new _a(hex8);
@@ -110,30 +126,30 @@ class Color {
110
126
  }
111
127
  blendWith(other, weight = 0.5) {
112
128
  const w = Math.max(0, Math.min(1, weight));
113
- const converted = _a.isCSSColor(other) ? new _a(other) : new _a(other);
114
- const [r1, b1, g1, a1] = (0, utils_1.extractAlphaColorValues)(this.rgba);
115
- const [r2, b2, g2, a2] = (0, utils_1.extractAlphaColorValues)(converted.rgba);
129
+ const otherColor = new _a(other);
130
+ const [r1, g1, b1, a1] = (0, utils_1.extractAlphaColorValues)(this.rgba);
131
+ const [r2, g2, b2, a2] = (0, utils_1.extractAlphaColorValues)(otherColor.rgba);
116
132
  const alpha = Math.round((a1 * (1 - w) + a2 * w) * 100) / 100;
117
- const blendChannel = (c1, c2) => {
133
+ const _blendChannel = (c1, c2) => {
118
134
  return Math.round((c1 * a1 * (1 - w) + c2 * a2 * w) / alpha);
119
135
  };
120
- const r = blendChannel(r1, r2);
121
- const g = blendChannel(g1, g2);
122
- const b = blendChannel(b1, b2);
136
+ const r = _blendChannel(r1, r2);
137
+ const g = _blendChannel(g1, g2);
138
+ const b = _blendChannel(b1, b2);
123
139
  const blended = `rgba(${r}, ${g}, ${b}, ${alpha})`;
124
140
  return new _a(blended);
125
141
  }
126
142
  contrastRatio(other) {
127
- const newColor = _a.isCSSColor(other) ? new _a(other) : new _a(other);
128
- const luminance = (rgb) => {
143
+ const otherColor = new _a(other);
144
+ const _luminance = (rgb) => {
129
145
  const [r, g, b] = (0, utils_1.extractSolidColorValues)(rgb).map((v) => {
130
146
  const c = v / 255;
131
- return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
147
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
132
148
  });
133
149
  return 0.2126 * r + 0.7152 * g + 0.0722 * b;
134
150
  };
135
- const lum1 = luminance(this.rgb);
136
- const lum2 = luminance(newColor.rgb);
151
+ const lum1 = _luminance(this.rgb);
152
+ const lum2 = _luminance(otherColor.rgb);
137
153
  const brighter = Math.max(lum1, lum2);
138
154
  const darker = Math.min(lum1, lum2);
139
155
  const ratio = (brighter + 0.05) / (darker + 0.05);
@@ -58,7 +58,7 @@ const convertRgbToHsl = (r, g, b) => {
58
58
  };
59
59
  exports.convertRgbToHsl = convertRgbToHsl;
60
60
  const convertHslToHex = (h, s, l) => {
61
- const rgb = (0, exports.convertHslToRgb)(h, s, l).match(/\d+/g).map(Number);
61
+ const rgb = (0, exports.convertHslToRgb)(h, s, l).match(/\d+/g)?.map(Number) ?? [0, 0, 0];
62
62
  return (0, exports.convertRgbToHex)(rgb[0], rgb[1], rgb[2]);
63
63
  };
64
64
  exports.convertHslToHex = convertHslToHex;
@@ -36,7 +36,7 @@ const _isSimilarToLast = (recentColors, newColor) => {
36
36
  };
37
37
  exports._isSimilarToLast = _isSimilarToLast;
38
38
  function _isValidAlpha(value) {
39
- return value >= 0 && value <= 1 && !isNaN(value);
39
+ return value >= 0 && value <= 1 && !Number.isNaN(value);
40
40
  }
41
41
  function _isValidRGBComponent(value) {
42
42
  return value >= 0 && value <= 255;
@@ -34,14 +34,12 @@ function getColorForInitial(input = '', opacity = 100) {
34
34
  else if (Array.isArray(input)) {
35
35
  if (input?.length < 1)
36
36
  return [...constants_1.ALPHABET_COLOR_PALETTE, ...constants_1.NUMBER_COLOR_PALETTE].map((color) => (0, helpers_1._applyOpacity)(color, hexOpacity));
37
- return input
38
- .map((el) => {
37
+ return input.flatMap((el) => {
39
38
  if (Array.isArray(el)) {
40
39
  return getColorForInitial(el, opacity);
41
40
  }
42
41
  return getColorForInitial(el, opacity);
43
- })
44
- .flat();
42
+ });
45
43
  }
46
44
  return (0, helpers_1._applyOpacity)(DEFAULT, hexOpacity);
47
45
  }
@@ -27,7 +27,7 @@ class BanglaCalendar {
27
27
  !_a.isBanglaYearEn(dateBnYrOrCfg)
28
28
  ? dateBnYrOrCfg
29
29
  : Date.now());
30
- if (isNaN(date.getTime())) {
30
+ if (Number.isNaN(date.getTime())) {
31
31
  date = new Date();
32
32
  }
33
33
  const { year, month, monthDate } = this.#processDate(date);
@@ -104,7 +104,7 @@ class Chronos {
104
104
  }
105
105
  #toNewDate(value) {
106
106
  const date = value instanceof _a ? value.toDate() : (0, helpers_1._dateArgsToDate)(value);
107
- if (isNaN(date.getTime())) {
107
+ if (Number.isNaN(date.getTime())) {
108
108
  throw new Error('Provided date is invalid!');
109
109
  }
110
110
  return date;
@@ -763,7 +763,7 @@ class Chronos {
763
763
  return value instanceof Date;
764
764
  }
765
765
  static isDateString(value) {
766
- return (0, primitives_1.isString)(value) && !isNaN(Date.parse(value));
766
+ return (0, primitives_1.isString)(value) && !Number.isNaN(Date.parse(value));
767
767
  }
768
768
  static isValidChronos(value) {
769
769
  return value instanceof _a;
@@ -10,7 +10,7 @@ const banglaPlugin = ($Chronos) => {
10
10
  function $bnDaysMonthIdx(date, variant) {
11
11
  return (0, helpers_1._bnDaysMonthIdx)(date, variant ?? DEFAULT_CONFIG.get('config')?.variant);
12
12
  }
13
- $Chronos.prototype.configureBanglaCalendar = function (configs) {
13
+ $Chronos.prototype.configureBanglaCalendar = (configs) => {
14
14
  DEFAULT_CONFIG.set('config', configs);
15
15
  };
16
16
  $Chronos.prototype.getBanglaYear = function (locale = 'bn') {
@@ -94,7 +94,7 @@ const banglaPlugin = ($Chronos) => {
94
94
  Z: offset,
95
95
  ZZ: offset,
96
96
  S: seasonName,
97
- SS: seasonName + 'কাল',
97
+ SS: `${seasonName}কাল`,
98
98
  };
99
99
  return (0, helpers_1._formatDateCore)(fmt || 'ddd, DD mmmm (SS), YYYY বঙ্গাব্দ - hh:mm:ss (A)', dateComponents);
100
100
  };
@@ -16,7 +16,7 @@ const zodiacPlugin = ($Chronos) => {
16
16
  const { birthDate } = options ?? {};
17
17
  let month;
18
18
  let date;
19
- if (birthDate && birthDate?.includes('-')) {
19
+ if (birthDate?.includes('-')) {
20
20
  [month, date] = birthDate.split('-').map(Number);
21
21
  }
22
22
  else {
@@ -30,7 +30,7 @@ const zodiacPlugin = ($Chronos) => {
30
30
  return sign;
31
31
  }
32
32
  if (i === 0) {
33
- return sortedSigns.at(-1)[0];
33
+ return sortedSigns.at(-1)?.[0];
34
34
  }
35
35
  }
36
36
  return sortedSigns[0][0];
@@ -38,7 +38,7 @@ const zodiacPlugin = ($Chronos) => {
38
38
  $Chronos.prototype.zodiac = function (options) {
39
39
  return this.getZodiacSign(options);
40
40
  };
41
- $Chronos.prototype.getZodiacMeta = function (sign, options) {
41
+ $Chronos.prototype.getZodiacMeta = (sign, options) => {
42
42
  const sortedSigns = _resolveSigns(options);
43
43
  const index = sortedSigns.findIndex(([s]) => s === sign);
44
44
  if (index === -1) {
@@ -92,7 +92,7 @@ function getTimeZoneIds(offset) {
92
92
  function formatDate(options) {
93
93
  const { date = new Date(), format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false, } = options ?? {};
94
94
  const $date = (0, helpers_1._dateArgsToDate)(date);
95
- if (isNaN($date.getTime())) {
95
+ if (Number.isNaN($date.getTime())) {
96
96
  return 'Invalid Date!';
97
97
  }
98
98
  const _getUnitValue = (suffix) => {
@@ -108,7 +108,7 @@ function formatTimePart(time, format) {
108
108
  }
109
109
  function formatDateRelative(date, format) {
110
110
  const $date = (0, helpers_1._dateArgsToDate)(date);
111
- if (isNaN($date.getTime())) {
111
+ if (Number.isNaN($date.getTime())) {
112
112
  return 'Invalid Date!';
113
113
  }
114
114
  const now = Date.now();
@@ -143,7 +143,7 @@ function getTimestamp(args, format) {
143
143
  $format = format || 'utc';
144
144
  }
145
145
  let date = (0, helpers_1._dateArgsToDate)($value);
146
- if (isNaN(date.getTime())) {
146
+ if (Number.isNaN(date.getTime())) {
147
147
  date = new Date();
148
148
  }
149
149
  if ($format === 'local') {
@@ -122,11 +122,15 @@ const createControlledFormData = (data, configs) => {
122
122
  return;
123
123
  }
124
124
  if ((0, guards_2.isCustomFileArray)(value)) {
125
- value?.forEach((file) => formData.append(transformedKey, file?.originFileObj));
125
+ for (const file of value) {
126
+ formData.append(transformedKey, file?.originFileObj);
127
+ }
126
128
  }
127
129
  else if ((0, guards_2.isFileUpload)(value)) {
128
130
  if (value?.fileList) {
129
- value?.fileList.forEach((file) => formData.append(transformedKey, file?.originFileObj));
131
+ for (const file of value.fileList) {
132
+ formData.append(transformedKey, file?.originFileObj);
133
+ }
130
134
  }
131
135
  else if (value?.file) {
132
136
  if ((0, guards_2.isCustomFile)(value?.file)) {
@@ -23,7 +23,7 @@ function isEmailArray(value) {
23
23
  return (0, non_primitives_1.isArray)(value) && value?.every(isEmail);
24
24
  }
25
25
  function isDateString(value) {
26
- return (0, primitives_1.isString)(value) && !isNaN(Date.parse(value));
26
+ return (0, primitives_1.isString)(value) && !Number.isNaN(Date.parse(value));
27
27
  }
28
28
  function isUUID(value) {
29
29
  const h = '[0-9a-f]';
@@ -60,16 +60,16 @@ class TextCodec {
60
60
  return (0, utils_1.bytesToBase64)((0, utils_1.utf8ToBytes)(text));
61
61
  }
62
62
  static base64ToHex(b64, spaced = true) {
63
- return this.utf8ToHex(this.base64ToUtf8(b64), spaced);
63
+ return TextCodec.utf8ToHex(TextCodec.base64ToUtf8(b64), spaced);
64
64
  }
65
65
  static base64ToBinary(b64, spaced = true) {
66
- return this.utf8ToBinary(this.base64ToUtf8(b64), spaced);
66
+ return TextCodec.utf8ToBinary(TextCodec.base64ToUtf8(b64), spaced);
67
67
  }
68
68
  static hexToBase64(hex) {
69
- return this.utf8ToBase64(this.hexToUtf8(hex));
69
+ return TextCodec.utf8ToBase64(TextCodec.hexToUtf8(hex));
70
70
  }
71
71
  static binaryToBase64(binary) {
72
- return this.utf8ToBase64(this.binaryToUtf8(binary));
72
+ return TextCodec.utf8ToBase64(TextCodec.binaryToUtf8(binary));
73
73
  }
74
74
  }
75
75
  exports.TextCodec = TextCodec;
@@ -106,8 +106,8 @@ function bytesToBase64(bytes) {
106
106
  out +=
107
107
  _b64chars[h1] +
108
108
  _b64chars[h2] +
109
- _b64chars[isNaN(o2) ? 64 : h3] +
110
- _b64chars[isNaN(o3) ? 64 : h4];
109
+ _b64chars[Number.isNaN(o2) ? 64 : h3] +
110
+ _b64chars[Number.isNaN(o3) ? 64 : h4];
111
111
  }
112
112
  return out;
113
113
  }
@@ -128,7 +128,7 @@ function getAverage(...numbers) {
128
128
  return count === 0 ? NaN : Math.round((sum / count) * 1000) / 1000;
129
129
  }
130
130
  function roundNumber(number, roundTo = 2) {
131
- const factor = Math.pow(10, roundTo);
131
+ const factor = 10 ** roundTo;
132
132
  const num = (0, primitives_1.isNumber)(number) ? number : Number(number);
133
133
  return Math.round(num * factor) / factor;
134
134
  }
@@ -13,7 +13,7 @@ const helpers_1 = require("./helpers");
13
13
  const utilities_1 = require("./utilities");
14
14
  function numberToWords(num) {
15
15
  let number = Math.trunc(Number(num));
16
- if (!Number.isFinite(number) || isNaN(number)) {
16
+ if (!Number.isFinite(number) || Number.isNaN(number)) {
17
17
  return 'Invalid Number!';
18
18
  }
19
19
  const isNegative = number < 0;
@@ -217,7 +217,7 @@ function banglaToDigit(bnDigit, forceNumber = true) {
217
217
  if (forceNumber) {
218
218
  return Number(digitStr
219
219
  .split('')
220
- .filter((dig) => !isNaN(Number(dig)))
220
+ .filter((dig) => !Number.isNaN(Number(dig)))
221
221
  .join(''));
222
222
  }
223
223
  return digitStr;
@@ -28,8 +28,9 @@ function getFibonacciSeriesMemo(limit) {
28
28
  [1, 1],
29
29
  ]);
30
30
  const fib = (n) => {
31
- if (memo.has(n))
31
+ if (memo.has(n)) {
32
32
  return memo.get(n);
33
+ }
33
34
  const val = fib(n - 1) + fib(n - 2);
34
35
  memo.set(n, val);
35
36
  return val;
@@ -6,7 +6,7 @@ const guards_1 = require("./guards");
6
6
  function calculatePercentage(options) {
7
7
  const { roundTo = 3 } = options;
8
8
  const _roundNumber = (num) => {
9
- const factor = Math.pow(10, roundTo);
9
+ const factor = 10 ** roundTo;
10
10
  return Math.round(num * factor) / factor;
11
11
  };
12
12
  switch (options?.mode) {
@@ -143,7 +143,7 @@ function parseObjectValues(object, parseNested = true) {
143
143
  else if (data === 'undefined') {
144
144
  return undefined;
145
145
  }
146
- else if (!isNaN(Number(data))) {
146
+ else if (!Number.isNaN(Number(data))) {
147
147
  return Number(data);
148
148
  }
149
149
  else
@@ -18,7 +18,7 @@ function generateRandomID(options) {
18
18
  const { prefix = '', suffix = '', timeStamp = false, length = 16, separator = '', caseOption = null, } = options || {};
19
19
  const date = timeStamp ? Date.now() : '';
20
20
  const randomString = Array.from({ length }, () => Math.random().toString(36).slice(2, 3)).join('');
21
- const ID = [prefix && prefix.trim(), date, randomString, suffix && suffix.trim()]
21
+ const ID = [prefix?.trim(), date, randomString, suffix?.trim()]
22
22
  .filter(Boolean)
23
23
  .join(separator);
24
24
  switch (caseOption) {
@@ -70,11 +70,11 @@ function convertStringCase(value, format, options) {
70
70
  return start.concat(body, end);
71
71
  }
72
72
  case 'snake_case': {
73
- const body = tokens.map((token) => lowerCase(token)).join('_');
73
+ const body = tokens.map(lowerCase).join('_');
74
74
  return start.concat(body, end);
75
75
  }
76
76
  case 'kebab-case': {
77
- const body = tokens.map((token) => lowerCase(token)).join('-');
77
+ const body = tokens.map(lowerCase).join('-');
78
78
  return start.concat(body, end);
79
79
  }
80
80
  case 'Title Case': {
@@ -169,7 +169,7 @@ function _getDelimiterRegex(delims) {
169
169
  function _normalizeDelimiters(str, delims) {
170
170
  const delRegExp = _getDelimiterRegex(delims);
171
171
  return str
172
- .replace(/(\p{Ll}?\d+|(?<=\p{Lu}))(\p{Lu})/gu, '$1 $2')
172
+ .replace(/(\p{Ll}?\d+|(?<=\p{Lu}|\p{Ll}))(\p{Lu})/gu, '$1 $2')
173
173
  .replace(delRegExp, ' ')
174
174
  .replace(/\s+/g, ' ')
175
175
  .trim()
@@ -16,11 +16,17 @@ import type { Analogous, ColorType, CSSColor, Hex6, Hex8, HSL, HSLA, RGB, RGBA,
16
16
  */
17
17
  export declare class Color {
18
18
  #private;
19
+ /** {@link Hex6 Hex} color representation (without alpha). */
19
20
  readonly hex: Hex6;
21
+ /** {@link Hex8} color representation including alpha. */
20
22
  readonly hex8: Hex8;
23
+ /** {@link RGB} color representation (without alpha). */
21
24
  readonly rgb: RGB;
25
+ /** {@link RGBA} color representation including alpha. */
22
26
  readonly rgba: RGBA;
27
+ /** {@link HSL} color representation (without alpha). */
23
28
  readonly hsl: HSL;
29
+ /** {@link HSLA} color representation including alpha. */
24
30
  readonly hsla: HSLA;
25
31
  /**
26
32
  * * Creates a new `Color` instance with a random color and automatically converts the generated color to all other supported formats: {@link Hex6 Hex}, {@link Hex8}, {@link RGB}, {@link RGBA}, {@link HSL}, and {@link HSLA}.
@@ -157,6 +163,29 @@ export declare class Color {
157
163
  constructor(color?: ColorType | CSSColor);
158
164
  /** Iterates over the color representations (`Hex`, `RGB`, `HSL`). */
159
165
  [Symbol.iterator](): Generator<Hex8 | HSL | Hex6 | RGB | RGBA | HSLA, void, unknown>;
166
+ /**
167
+ * Allows the color to be used in string and number contexts.
168
+ * @param hint The hint to determine the conversion type.
169
+ */
170
+ [Symbol.toPrimitive](hint: string): number | Hex8 | this;
171
+ /**
172
+ * @instance Convert the color to string.
173
+ * @returns The `Hex8` representation of the color.
174
+ *
175
+ * @remarks
176
+ * - Called by `String()`, `Object.prototype.toString()` or in template literals.
177
+ * - Uses the same implementation as `toJSON()`.
178
+ */
179
+ toString(): Hex8;
180
+ /**
181
+ * @instance Convert the color to JSON.
182
+ * @returns The `Hex8` representation of the color.
183
+ *
184
+ * @remarks
185
+ * - Called by `JSON.stringify()`.
186
+ * - It uses the same implementation as `toString()`.
187
+ */
188
+ toJSON(): Hex8;
160
189
  /**
161
190
  * @instance Applies or modifies the opacity of a color and returns a new instance.
162
191
  *
@@ -72,7 +72,7 @@ export declare function isIPAddress(value: unknown): value is string;
72
72
  /**
73
73
  * * Type guard to check if the current environment matches a given string.
74
74
  * @param env - The expected environment (e.g., "production", "development").
75
- * @returns `true` if the value is a numeric string parsable by `Number()`, otherwise `false`.
75
+ * @returns `true` if the value equals to `process.env.NODE_ENV`, otherwise `false`.
76
76
  */
77
77
  export declare function isEnvironment(env: string): boolean;
78
78
  /**
@@ -1,4 +1,4 @@
1
- import type { CamelCase, CapitalizeOptions, CaseFormat, ConstantCase, DotCase, KebabCase, PascalCase, PascalSnakeCase, PathCase, SentenceCase, SnakeCase, StringCaseOptions, TitleCase, TrainCase } from './types';
1
+ import type { $WidenEmpty, CamelCase, CapitalizeOptions, CaseFormat, ConstantCase, DotCase, KebabCase, PascalCase, PascalSnakeCase, PathCase, SentenceCase, SnakeCase, StringCaseOptions, TitleCase, TrainCase } from './types';
2
2
  /**
3
3
  * * Converts a string to a specified case format with advanced handling for word boundaries, punctuation, acronyms, and Unicode characters.
4
4
  *
@@ -83,7 +83,7 @@ export declare function convertStringCase(value: string, format: CaseFormat, opt
83
83
  *
84
84
  * @param string String to be capitalized.
85
85
  * @param options Options to customize the capitalization.
86
- * @returns Capitalized string or fully uppercased string depending on `capitalizeAll` option.
86
+ * @returns Capitalized string or fully upper-cased string depending on `capitalizeAll` option.
87
87
  */
88
88
  export declare function capitalizeString(string: string, options?: CapitalizeOptions): string;
89
89
  /**
@@ -106,7 +106,7 @@ export declare function capitalizeString(string: string, options?: CapitalizeOpt
106
106
  * @param del Additional delimiter characters to recognize.
107
107
  * @returns The `camelCase` formatted string.
108
108
  */
109
- export declare function toCamelCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): CamelCase<Str, Del>;
109
+ export declare function toCamelCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<CamelCase<Str, Del>>;
110
110
  /**
111
111
  * * Converts a string into `PascalCase`, using the optional custom delimiters in addition to the default delimiters.
112
112
  *
@@ -127,7 +127,7 @@ export declare function toCamelCase<Str extends string, Del extends string = ''>
127
127
  * @param del Additional delimiter characters to recognize.
128
128
  * @returns The `PascalCase` formatted string.
129
129
  */
130
- export declare function toPascalCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): PascalCase<Str, Del>;
130
+ export declare function toPascalCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<PascalCase<Str, Del>>;
131
131
  /**
132
132
  * * Converts a string into `snake_case`, using the optional custom delimiters in addition to the default delimiters.
133
133
  *
@@ -147,7 +147,7 @@ export declare function toPascalCase<Str extends string, Del extends string = ''
147
147
  * @param del Additional delimiter characters to recognize.
148
148
  * @returns The `snake_case` formatted string.
149
149
  */
150
- export declare function toSnakeCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): SnakeCase<Str, Del>;
150
+ export declare function toSnakeCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<SnakeCase<Str, Del>>;
151
151
  /**
152
152
  * * Converts a string into `kebab-case`, using the optional custom delimiters in addition to the default delimiters.
153
153
  *
@@ -167,7 +167,7 @@ export declare function toSnakeCase<Str extends string, Del extends string = ''>
167
167
  * @param del Additional delimiter characters to recognize.
168
168
  * @returns The `kebab-case` formatted string.
169
169
  */
170
- export declare function toKebabCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): KebabCase<Str, Del>;
170
+ export declare function toKebabCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<KebabCase<Str, Del>>;
171
171
  /**
172
172
  * * Converts a string into `Train-Case`, using the optional custom delimiters in addition to the default delimiters.
173
173
  *
@@ -186,7 +186,7 @@ export declare function toKebabCase<Str extends string, Del extends string = ''>
186
186
  * @param del Additional delimiter characters to recognize.
187
187
  * @returns The `Train-Case` formatted string.
188
188
  */
189
- export declare function toTrainCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): TrainCase<Str, Del>;
189
+ export declare function toTrainCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<TrainCase<Str, Del>>;
190
190
  /**
191
191
  * * Converts a string into `dot.case`, using the optional custom delimiters in addition to the default delimiters.
192
192
  *
@@ -205,7 +205,7 @@ export declare function toTrainCase<Str extends string, Del extends string = ''>
205
205
  * @param del Additional delimiter characters to recognize.
206
206
  * @returns The `dot.case` formatted string.
207
207
  */
208
- export declare function toDotCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): DotCase<Str, Del>;
208
+ export declare function toDotCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<DotCase<Str, Del>>;
209
209
  /**
210
210
  * * Converts a string into `path/case`, using the optional custom delimiters in addition to the default delimiters.
211
211
  *
@@ -224,7 +224,7 @@ export declare function toDotCase<Str extends string, Del extends string = ''>(s
224
224
  * @param del Additional delimiter characters to recognize.
225
225
  * @returns The `path/case` formatted string.
226
226
  */
227
- export declare function toPathCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): PathCase<Str, Del>;
227
+ export declare function toPathCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<PathCase<Str, Del>>;
228
228
  /**
229
229
  * * Converts a string into `CONSTANT_CASE`, using the optional custom delimiters in addition to the default delimiters.
230
230
  *
@@ -243,7 +243,7 @@ export declare function toPathCase<Str extends string, Del extends string = ''>(
243
243
  * @param del Additional delimiter characters to recognize.
244
244
  * @returns The `CONSTANT_CASE` formatted string.
245
245
  */
246
- export declare function toConstantCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): ConstantCase<Str, Del>;
246
+ export declare function toConstantCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<ConstantCase<Str, Del>>;
247
247
  /**
248
248
  * * Converts a string into `Pascal_Snake_Case`, using the optional custom delimiters in addition to the default delimiters.
249
249
  *
@@ -262,7 +262,7 @@ export declare function toConstantCase<Str extends string, Del extends string =
262
262
  * @param del Additional delimiter characters to recognize.
263
263
  * @returns The `Pascal_Snake_Case` formatted string.
264
264
  */
265
- export declare function toPascalSnakeCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): PascalSnakeCase<Str, Del>;
265
+ export declare function toPascalSnakeCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<PascalSnakeCase<Str, Del>>;
266
266
  /**
267
267
  * * Converts a string into `Title Case`, using the optional custom delimiters in addition to the default delimiters.
268
268
  *
@@ -283,7 +283,7 @@ export declare function toPascalSnakeCase<Str extends string, Del extends string
283
283
  * @param del Additional delimiter characters to recognize.
284
284
  * @returns The `Title Case` formatted string.
285
285
  */
286
- export declare function toTitleCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): TitleCase<Str, Del>;
286
+ export declare function toTitleCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<TitleCase<Str, Del>>;
287
287
  /**
288
288
  * * Converts a string into `Sentence case`, using the optional custom delimiters in addition to the default delimiters.
289
289
  *
@@ -304,4 +304,4 @@ export declare function toTitleCase<Str extends string, Del extends string = ''>
304
304
  * @param del Additional delimiter characters to recognize.
305
305
  * @returns The `Sentence case` formatted string.
306
306
  */
307
- export declare function toSentenceCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): SentenceCase<Str, Del>;
307
+ export declare function toSentenceCase<Str extends string, Del extends string = ''>(str: Str, ...del: Del[]): $WidenEmpty<SentenceCase<Str, Del>>;
@@ -218,6 +218,8 @@ export type SentenceCase<Str extends string, Del extends string = ''> = Split<$N
218
218
  infer F extends string,
219
219
  ...infer R extends string[]
220
220
  ] ? `${Capitalize<Lowercase<F>>} ${Join<$LowercaseWords<R>, ' '>}` : ' ';
221
+ /** Helper type to convert an empty string to `string` while maintaining the literal type otherwise. */
222
+ export type $WidenEmpty<T extends string> = T extends '' ? string : T;
221
223
  /** Matches any non-Latin character. */
222
224
  export type SpecialCharacter = Lowercase<string> & Uppercase<string>;
223
225
  /** Evaluates whether a string consists only of Latin alphabet characters. */
@@ -6,19 +6,11 @@ export function _resolveNestedKey(obj, path) {
6
6
  if (isNotEmptyObject(acc)) {
7
7
  return acc[key];
8
8
  }
9
+ return undefined;
9
10
  }, obj);
10
11
  }
11
12
  }
12
13
  export function _getNumericProp(obj, path) {
13
- if (isNotEmptyObject(obj)) {
14
- const value = path?.split('.').reduce((acc, key) => {
15
- if (isNotEmptyObject(acc)) {
16
- return acc[key];
17
- }
18
- }, obj);
19
- return normalizeNumber(value) ?? 0;
20
- }
21
- else {
22
- return 0;
23
- }
14
+ const value = _resolveNestedKey(obj, path);
15
+ return normalizeNumber(value) ?? 0;
24
16
  }
@@ -4,7 +4,7 @@ import { isDeepEqual } from '../utils/index.js';
4
4
  import { _resolveNestedKey } from './helpers.js';
5
5
  export function createOptionsArray(data, config) {
6
6
  const { firstFieldKey, secondFieldKey, firstFieldName = 'value', secondFieldName = 'label', retainNumberValue = false, } = config || {};
7
- if (data && data?.length) {
7
+ if (data?.length) {
8
8
  return data?.map((datum) => {
9
9
  const firstValue = retainNumberValue && isNumber(datum[firstFieldKey])
10
10
  ? datum[firstFieldKey]
@@ -65,6 +65,16 @@ export class Color {
65
65
  yield this.hsl;
66
66
  yield this.hsla;
67
67
  }
68
+ [Symbol.toPrimitive](hint) {
69
+ if (hint === 'string') {
70
+ return this.hex8;
71
+ }
72
+ else if (hint === 'number') {
73
+ const hex = this.hex8.endsWith('FF') ? this.hex : this.hex8;
74
+ return parseInt(hex.replace('#', '0x'), 16);
75
+ }
76
+ return this;
77
+ }
68
78
  #hex6ToHex8(hex) {
69
79
  return `${hex.toUpperCase()}${percentToHex(100)}`;
70
80
  }
@@ -76,6 +86,12 @@ export class Color {
76
86
  const [h, s, l] = extractSolidColorValues(hsl);
77
87
  return `hsla(${h}, ${s}%, ${l}%, 1)`;
78
88
  }
89
+ toString() {
90
+ return this.hex8;
91
+ }
92
+ toJSON() {
93
+ return this.hex8;
94
+ }
79
95
  applyOpacity(opacity) {
80
96
  const hex8 = `${this.hex.slice(0, 7)}${percentToHex(opacity)}`.toUpperCase();
81
97
  return new _a(hex8);
@@ -107,30 +123,30 @@ export class Color {
107
123
  }
108
124
  blendWith(other, weight = 0.5) {
109
125
  const w = Math.max(0, Math.min(1, weight));
110
- const converted = _a.isCSSColor(other) ? new _a(other) : new _a(other);
111
- const [r1, b1, g1, a1] = extractAlphaColorValues(this.rgba);
112
- const [r2, b2, g2, a2] = extractAlphaColorValues(converted.rgba);
126
+ const otherColor = new _a(other);
127
+ const [r1, g1, b1, a1] = extractAlphaColorValues(this.rgba);
128
+ const [r2, g2, b2, a2] = extractAlphaColorValues(otherColor.rgba);
113
129
  const alpha = Math.round((a1 * (1 - w) + a2 * w) * 100) / 100;
114
- const blendChannel = (c1, c2) => {
130
+ const _blendChannel = (c1, c2) => {
115
131
  return Math.round((c1 * a1 * (1 - w) + c2 * a2 * w) / alpha);
116
132
  };
117
- const r = blendChannel(r1, r2);
118
- const g = blendChannel(g1, g2);
119
- const b = blendChannel(b1, b2);
133
+ const r = _blendChannel(r1, r2);
134
+ const g = _blendChannel(g1, g2);
135
+ const b = _blendChannel(b1, b2);
120
136
  const blended = `rgba(${r}, ${g}, ${b}, ${alpha})`;
121
137
  return new _a(blended);
122
138
  }
123
139
  contrastRatio(other) {
124
- const newColor = _a.isCSSColor(other) ? new _a(other) : new _a(other);
125
- const luminance = (rgb) => {
140
+ const otherColor = new _a(other);
141
+ const _luminance = (rgb) => {
126
142
  const [r, g, b] = extractSolidColorValues(rgb).map((v) => {
127
143
  const c = v / 255;
128
- return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
144
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
129
145
  });
130
146
  return 0.2126 * r + 0.7152 * g + 0.0722 * b;
131
147
  };
132
- const lum1 = luminance(this.rgb);
133
- const lum2 = luminance(newColor.rgb);
148
+ const lum1 = _luminance(this.rgb);
149
+ const lum2 = _luminance(otherColor.rgb);
134
150
  const brighter = Math.max(lum1, lum2);
135
151
  const darker = Math.min(lum1, lum2);
136
152
  const ratio = (brighter + 0.05) / (darker + 0.05);
@@ -52,7 +52,7 @@ export const convertRgbToHsl = (r, g, b) => {
52
52
  return `hsl(${Math.round(h)}, ${Number((s * 100).toFixed(2))}%, ${Number((l * 100).toFixed(2))}%)`;
53
53
  };
54
54
  export const convertHslToHex = (h, s, l) => {
55
- const rgb = convertHslToRgb(h, s, l).match(/\d+/g).map(Number);
55
+ const rgb = convertHslToRgb(h, s, l).match(/\d+/g)?.map(Number) ?? [0, 0, 0];
56
56
  return convertRgbToHex(rgb[0], rgb[1], rgb[2]);
57
57
  };
58
58
  export const convertHexToHsl = (hex) => {
@@ -26,7 +26,7 @@ export const _isSimilarToLast = (recentColors, newColor) => {
26
26
  return hueDifference < 48 && saturationDifference < 24 && lightnessDifference < 16;
27
27
  };
28
28
  export function _isValidAlpha(value) {
29
- return value >= 0 && value <= 1 && !isNaN(value);
29
+ return value >= 0 && value <= 1 && !Number.isNaN(value);
30
30
  }
31
31
  export function _isValidRGBComponent(value) {
32
32
  return value >= 0 && value <= 255;
@@ -31,14 +31,12 @@ export function getColorForInitial(input = '', opacity = 100) {
31
31
  else if (Array.isArray(input)) {
32
32
  if (input?.length < 1)
33
33
  return [...ALPHABET_COLOR_PALETTE, ...NUMBER_COLOR_PALETTE].map((color) => _applyOpacity(color, hexOpacity));
34
- return input
35
- .map((el) => {
34
+ return input.flatMap((el) => {
36
35
  if (Array.isArray(el)) {
37
36
  return getColorForInitial(el, opacity);
38
37
  }
39
38
  return getColorForInitial(el, opacity);
40
- })
41
- .flat();
39
+ });
42
40
  }
43
41
  return _applyOpacity(DEFAULT, hexOpacity);
44
42
  }
@@ -24,7 +24,7 @@ export class BanglaCalendar {
24
24
  !_a.isBanglaYearEn(dateBnYrOrCfg)
25
25
  ? dateBnYrOrCfg
26
26
  : Date.now());
27
- if (isNaN(date.getTime())) {
27
+ if (Number.isNaN(date.getTime())) {
28
28
  date = new Date();
29
29
  }
30
30
  const { year, month, monthDate } = this.#processDate(date);
@@ -101,7 +101,7 @@ export class Chronos {
101
101
  }
102
102
  #toNewDate(value) {
103
103
  const date = value instanceof _a ? value.toDate() : _dateArgsToDate(value);
104
- if (isNaN(date.getTime())) {
104
+ if (Number.isNaN(date.getTime())) {
105
105
  throw new Error('Provided date is invalid!');
106
106
  }
107
107
  return date;
@@ -760,7 +760,7 @@ export class Chronos {
760
760
  return value instanceof Date;
761
761
  }
762
762
  static isDateString(value) {
763
- return isString(value) && !isNaN(Date.parse(value));
763
+ return isString(value) && !Number.isNaN(Date.parse(value));
764
764
  }
765
765
  static isValidChronos(value) {
766
766
  return value instanceof _a;
@@ -7,7 +7,7 @@ export const banglaPlugin = ($Chronos) => {
7
7
  function $bnDaysMonthIdx(date, variant) {
8
8
  return _bnDaysMonthIdx(date, variant ?? DEFAULT_CONFIG.get('config')?.variant);
9
9
  }
10
- $Chronos.prototype.configureBanglaCalendar = function (configs) {
10
+ $Chronos.prototype.configureBanglaCalendar = (configs) => {
11
11
  DEFAULT_CONFIG.set('config', configs);
12
12
  };
13
13
  $Chronos.prototype.getBanglaYear = function (locale = 'bn') {
@@ -91,7 +91,7 @@ export const banglaPlugin = ($Chronos) => {
91
91
  Z: offset,
92
92
  ZZ: offset,
93
93
  S: seasonName,
94
- SS: seasonName + 'কাল',
94
+ SS: `${seasonName}কাল`,
95
95
  };
96
96
  return _formatDateCore(fmt || 'ddd, DD mmmm (SS), YYYY বঙ্গাব্দ - hh:mm:ss (A)', dateComponents);
97
97
  };
@@ -13,7 +13,7 @@ export const zodiacPlugin = ($Chronos) => {
13
13
  const { birthDate } = options ?? {};
14
14
  let month;
15
15
  let date;
16
- if (birthDate && birthDate?.includes('-')) {
16
+ if (birthDate?.includes('-')) {
17
17
  [month, date] = birthDate.split('-').map(Number);
18
18
  }
19
19
  else {
@@ -27,7 +27,7 @@ export const zodiacPlugin = ($Chronos) => {
27
27
  return sign;
28
28
  }
29
29
  if (i === 0) {
30
- return sortedSigns.at(-1)[0];
30
+ return sortedSigns.at(-1)?.[0];
31
31
  }
32
32
  }
33
33
  return sortedSigns[0][0];
@@ -35,7 +35,7 @@ export const zodiacPlugin = ($Chronos) => {
35
35
  $Chronos.prototype.zodiac = function (options) {
36
36
  return this.getZodiacSign(options);
37
37
  };
38
- $Chronos.prototype.getZodiacMeta = function (sign, options) {
38
+ $Chronos.prototype.getZodiacMeta = (sign, options) => {
39
39
  const sortedSigns = _resolveSigns(options);
40
40
  const index = sortedSigns.findIndex(([s]) => s === sign);
41
41
  if (index === -1) {
@@ -76,7 +76,7 @@ export function getTimeZoneIds(offset) {
76
76
  export function formatDate(options) {
77
77
  const { date = new Date(), format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false, } = options ?? {};
78
78
  const $date = _dateArgsToDate(date);
79
- if (isNaN($date.getTime())) {
79
+ if (Number.isNaN($date.getTime())) {
80
80
  return 'Invalid Date!';
81
81
  }
82
82
  const _getUnitValue = (suffix) => {
@@ -92,7 +92,7 @@ export function formatTimePart(time, format) {
92
92
  }
93
93
  export function formatDateRelative(date, format) {
94
94
  const $date = _dateArgsToDate(date);
95
- if (isNaN($date.getTime())) {
95
+ if (Number.isNaN($date.getTime())) {
96
96
  return 'Invalid Date!';
97
97
  }
98
98
  const now = Date.now();
@@ -127,7 +127,7 @@ export function getTimestamp(args, format) {
127
127
  $format = format || 'utc';
128
128
  }
129
129
  let date = _dateArgsToDate($value);
130
- if (isNaN(date.getTime())) {
130
+ if (Number.isNaN(date.getTime())) {
131
131
  date = new Date();
132
132
  }
133
133
  if ($format === 'local') {
@@ -119,11 +119,15 @@ export const createControlledFormData = (data, configs) => {
119
119
  return;
120
120
  }
121
121
  if (isCustomFileArray(value)) {
122
- value?.forEach((file) => formData.append(transformedKey, file?.originFileObj));
122
+ for (const file of value) {
123
+ formData.append(transformedKey, file?.originFileObj);
124
+ }
123
125
  }
124
126
  else if (isFileUpload(value)) {
125
127
  if (value?.fileList) {
126
- value?.fileList.forEach((file) => formData.append(transformedKey, file?.originFileObj));
128
+ for (const file of value.fileList) {
129
+ formData.append(transformedKey, file?.originFileObj);
130
+ }
127
131
  }
128
132
  else if (value?.file) {
129
133
  if (isCustomFile(value?.file)) {
@@ -7,7 +7,7 @@ export function isEmailArray(value) {
7
7
  return isArray(value) && value?.every(isEmail);
8
8
  }
9
9
  export function isDateString(value) {
10
- return isString(value) && !isNaN(Date.parse(value));
10
+ return isString(value) && !Number.isNaN(Date.parse(value));
11
11
  }
12
12
  export function isUUID(value) {
13
13
  const h = '[0-9a-f]';
@@ -57,15 +57,15 @@ export class TextCodec {
57
57
  return bytesToBase64(utf8ToBytes(text));
58
58
  }
59
59
  static base64ToHex(b64, spaced = true) {
60
- return this.utf8ToHex(this.base64ToUtf8(b64), spaced);
60
+ return TextCodec.utf8ToHex(TextCodec.base64ToUtf8(b64), spaced);
61
61
  }
62
62
  static base64ToBinary(b64, spaced = true) {
63
- return this.utf8ToBinary(this.base64ToUtf8(b64), spaced);
63
+ return TextCodec.utf8ToBinary(TextCodec.base64ToUtf8(b64), spaced);
64
64
  }
65
65
  static hexToBase64(hex) {
66
- return this.utf8ToBase64(this.hexToUtf8(hex));
66
+ return TextCodec.utf8ToBase64(TextCodec.hexToUtf8(hex));
67
67
  }
68
68
  static binaryToBase64(binary) {
69
- return this.utf8ToBase64(this.binaryToUtf8(binary));
69
+ return TextCodec.utf8ToBase64(TextCodec.binaryToUtf8(binary));
70
70
  }
71
71
  }
@@ -92,8 +92,8 @@ export function bytesToBase64(bytes) {
92
92
  out +=
93
93
  _b64chars[h1] +
94
94
  _b64chars[h2] +
95
- _b64chars[isNaN(o2) ? 64 : h3] +
96
- _b64chars[isNaN(o3) ? 64 : h4];
95
+ _b64chars[Number.isNaN(o2) ? 64 : h3] +
96
+ _b64chars[Number.isNaN(o3) ? 64 : h4];
97
97
  }
98
98
  return out;
99
99
  }
@@ -114,7 +114,7 @@ export function getAverage(...numbers) {
114
114
  return count === 0 ? NaN : Math.round((sum / count) * 1000) / 1000;
115
115
  }
116
116
  export function roundNumber(number, roundTo = 2) {
117
- const factor = Math.pow(10, roundTo);
117
+ const factor = 10 ** roundTo;
118
118
  const num = isNumber(number) ? number : Number(number);
119
119
  return Math.round(num * factor) / factor;
120
120
  }
@@ -5,7 +5,7 @@ import { _convertLessThanThousand } from './helpers.js';
5
5
  import { normalizeNumber } from './utilities.js';
6
6
  export function numberToWords(num) {
7
7
  let number = Math.trunc(Number(num));
8
- if (!Number.isFinite(number) || isNaN(number)) {
8
+ if (!Number.isFinite(number) || Number.isNaN(number)) {
9
9
  return 'Invalid Number!';
10
10
  }
11
11
  const isNegative = number < 0;
@@ -207,7 +207,7 @@ export function banglaToDigit(bnDigit, forceNumber = true) {
207
207
  if (forceNumber) {
208
208
  return Number(digitStr
209
209
  .split('')
210
- .filter((dig) => !isNaN(Number(dig)))
210
+ .filter((dig) => !Number.isNaN(Number(dig)))
211
211
  .join(''));
212
212
  }
213
213
  return digitStr;
@@ -22,8 +22,9 @@ export function getFibonacciSeriesMemo(limit) {
22
22
  [1, 1],
23
23
  ]);
24
24
  const fib = (n) => {
25
- if (memo.has(n))
25
+ if (memo.has(n)) {
26
26
  return memo.get(n);
27
+ }
27
28
  const val = fib(n - 1) + fib(n - 2);
28
29
  memo.set(n, val);
29
30
  return val;
@@ -3,7 +3,7 @@ import { areInvalidNumbers } from './guards.js';
3
3
  export function calculatePercentage(options) {
4
4
  const { roundTo = 3 } = options;
5
5
  const _roundNumber = (num) => {
6
- const factor = Math.pow(10, roundTo);
6
+ const factor = 10 ** roundTo;
7
7
  return Math.round(num * factor) / factor;
8
8
  };
9
9
  switch (options?.mode) {
@@ -139,7 +139,7 @@ export function parseObjectValues(object, parseNested = true) {
139
139
  else if (data === 'undefined') {
140
140
  return undefined;
141
141
  }
142
- else if (!isNaN(Number(data))) {
142
+ else if (!Number.isNaN(Number(data))) {
143
143
  return Number(data);
144
144
  }
145
145
  else
@@ -13,7 +13,7 @@ export function generateRandomID(options) {
13
13
  const { prefix = '', suffix = '', timeStamp = false, length = 16, separator = '', caseOption = null, } = options || {};
14
14
  const date = timeStamp ? Date.now() : '';
15
15
  const randomString = Array.from({ length }, () => Math.random().toString(36).slice(2, 3)).join('');
16
- const ID = [prefix && prefix.trim(), date, randomString, suffix && suffix.trim()]
16
+ const ID = [prefix?.trim(), date, randomString, suffix?.trim()]
17
17
  .filter(Boolean)
18
18
  .join(separator);
19
19
  switch (caseOption) {
@@ -55,11 +55,11 @@ export function convertStringCase(value, format, options) {
55
55
  return start.concat(body, end);
56
56
  }
57
57
  case 'snake_case': {
58
- const body = tokens.map((token) => lowerCase(token)).join('_');
58
+ const body = tokens.map(lowerCase).join('_');
59
59
  return start.concat(body, end);
60
60
  }
61
61
  case 'kebab-case': {
62
- const body = tokens.map((token) => lowerCase(token)).join('-');
62
+ const body = tokens.map(lowerCase).join('-');
63
63
  return start.concat(body, end);
64
64
  }
65
65
  case 'Title Case': {
@@ -154,7 +154,7 @@ function _getDelimiterRegex(delims) {
154
154
  function _normalizeDelimiters(str, delims) {
155
155
  const delRegExp = _getDelimiterRegex(delims);
156
156
  return str
157
- .replace(/(\p{Ll}?\d+|(?<=\p{Lu}))(\p{Lu})/gu, '$1 $2')
157
+ .replace(/(\p{Ll}?\d+|(?<=\p{Lu}|\p{Ll}))(\p{Lu})/gu, '$1 $2')
158
158
  .replace(delRegExp, ' ')
159
159
  .replace(/\s+/g, ' ')
160
160
  .trim()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.30.24",
3
+ "version": "4.31.0",
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.4.15",
47
+ "@biomejs/biome": "^2.5.0",
48
48
  "@types/jest": "^30.0.0",
49
- "@types/node": "^25.9.1",
49
+ "@types/node": "^25.9.3",
50
50
  "husky": "^9.1.7",
51
51
  "jest": "^30.4.2",
52
- "lint-staged": "^17.0.5",
52
+ "lint-staged": "^17.0.7",
53
53
  "nhb-scripts": "^1.9.2",
54
54
  "ts-jest": "^29.4.11",
55
55
  "typescript": "^6.0.3"
@@ -119,8 +119,8 @@
119
119
  ],
120
120
  "lint-staged": {
121
121
  "*.+((c|m)?js(x)?|(c|m)?ts(x)?)": [
122
- "biome format --write --diagnostic-level=error",
123
- "biome lint --diagnostic-level=error"
122
+ "biome format --write --diagnostic-level=warn",
123
+ "biome lint --diagnostic-level=warn"
124
124
  ]
125
125
  },
126
126
  "exports": {
@@ -437,9 +437,10 @@
437
437
  "test": "jest --coverage --verbose",
438
438
  "test:watch": "jest --onlyChanged --verbose --watch",
439
439
  "start": "start coverage/lcov-report/index.html",
440
- "lint": "biome lint --diagnostic-level=error",
441
- "fix": "biome check --write --diagnostic-level=error",
442
- "format": "biome format --write --diagnostic-level=error",
440
+ "typecheck": "tsc --noEmit",
441
+ "lint": "biome lint --diagnostic-level=warn",
442
+ "fix": "biome check --write --diagnostic-level=warn",
443
+ "format": "biome format --write --diagnostic-level=warn",
443
444
  "build": "nhb-build",
444
445
  "commit": "nhb-commit",
445
446
  "module": "nhb-module",