nhb-toolbox 3.4.5 → 3.4.7

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.
@@ -55,7 +55,7 @@ export declare class Color {
55
55
  * @example
56
56
  * const alphaColor = new Color("#ff000080"); // Color with 50% opacity
57
57
  * const alpha75 = alphaColor.applyOpacity(75); // Change to 75% opacity
58
- * console.log(alpha75.hex8); // #ff0000bf
58
+ * console.log(alpha75.hex8); // #FF0000BF
59
59
  */
60
60
  applyOpacity(opacity: OpacityValue): SolidColors & AlphaColors;
61
61
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/colors/Color.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACX,WAAW,EACX,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,WAAW,EACX,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,KAAK;IACV,GAAG,EAAE,IAAI,CAAC;IACV,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IAElB,iEAAiE;IAChE,CAAC,MAAM,CAAC,QAAQ,CAAC;IASlB;;;;OAIG;gBACS,SAAS,CAAC,EAAE,SAAS;IAyCjC;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,GAAG,WAAW;IAgC9D;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAIlD;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAIlD;;;;;OAKG;WACW,KAAK,CAAC,KAAK,EAAE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AC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAMlD;;;;;OAKG;WACW,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG;IAIhD;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAMlD;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;CAuB7B"}
@@ -2,7 +2,7 @@ import { convertColorCode } from './convert';
2
2
  import { _convertOpacityToHex, _extractAlphaColorValues, _extractSolidColorValues, } from './helpers';
3
3
  import { generateRandomHSLColor } from './random';
4
4
  const hsl = generateRandomHSLColor();
5
- const hexRGB = convertColorCode(hsl);
5
+ const { hex, rgb } = convertColorCode(hsl);
6
6
  /**
7
7
  * * Class representing a color and its conversions among `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` and `HSLA` formats.
8
8
  * * It has 1 instance method `applyOpacity()` to apply opacity to `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` color.
@@ -56,8 +56,8 @@ export class Color {
56
56
  // Extract alpha color values (Hex8, RGBA, HSLA)
57
57
  const rgbaValues = _extractAlphaColorValues(colors.rgba);
58
58
  const hslaValues = _extractAlphaColorValues(colors.hsla);
59
- this.hex = colors.hex8.slice(0, 7);
60
- this.hex8 = colors.hex8;
59
+ this.hex = colors.hex8.toUpperCase().slice(0, 7);
60
+ this.hex8 = colors.hex8.toUpperCase();
61
61
  this.rgb = `rgb(${rgbaValues[0]}, ${rgbaValues[1]}, ${rgbaValues[2]})`;
62
62
  this.rgba = colors.rgba;
63
63
  this.hsl = `hsl(${hslaValues[0]}, ${hslaValues[1]}%, ${hslaValues[2]}%)`;
@@ -67,8 +67,9 @@ export class Color {
67
67
  // Extract solid color values (Hex, RGB, HSL)
68
68
  const rgbValues = _extractSolidColorValues(colors.rgb);
69
69
  const hslValues = _extractSolidColorValues(colors.hsl);
70
- this.hex = colors.hex;
71
- this.hex8 = `${colors.hex}${_convertOpacityToHex(100)}`;
70
+ this.hex = colors.hex.toUpperCase();
71
+ this.hex8 =
72
+ `${colors.hex.toUpperCase()}${_convertOpacityToHex(100)}`;
72
73
  this.rgb = colors.rgb;
73
74
  this.rgba = `rgba(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]}, 1)`;
74
75
  this.hsl = colors.hsl;
@@ -76,12 +77,13 @@ export class Color {
76
77
  }
77
78
  }
78
79
  else {
79
- const rgbValues = _extractSolidColorValues(hexRGB.rgb);
80
+ const rgbValues = _extractSolidColorValues(rgb);
80
81
  const hslValues = _extractSolidColorValues(hsl);
81
82
  // Generate random colors
82
- this.hex = hexRGB.hex;
83
- this.hex8 = `${hexRGB.hex}${_convertOpacityToHex(100)}`;
84
- this.rgb = hexRGB.rgb;
83
+ this.hex = hex.toUpperCase();
84
+ this.hex8 =
85
+ `${hex.toUpperCase()}${_convertOpacityToHex(100)}`;
86
+ this.rgb = rgb;
85
87
  this.rgba = `rgba(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]}, 1)`;
86
88
  this.hsl = hsl;
87
89
  this.hsla = `hsla(${hslValues[0]}, ${hslValues[1]}%, ${hslValues[2]}%, 1)`;
@@ -103,29 +105,17 @@ export class Color {
103
105
  * @example
104
106
  * const alphaColor = new Color("#ff000080"); // Color with 50% opacity
105
107
  * const alpha75 = alphaColor.applyOpacity(75); // Change to 75% opacity
106
- * console.log(alpha75.hex8); // #ff0000bf
108
+ * console.log(alpha75.hex8); // #FF0000BF
107
109
  */
108
110
  applyOpacity(opacity) {
109
111
  const validOpacity = Math.min(100, Math.max(0, opacity));
110
112
  const alphaHex = _convertOpacityToHex(opacity);
111
113
  const alphaDecimal = validOpacity / 100;
112
- if (Color.isHex8(this.hex8)) {
113
- const rgbaValues = _extractAlphaColorValues(this.rgba);
114
- const hslaValues = _extractAlphaColorValues(this.hsla);
115
- return {
116
- hex: this.hex8.slice(0, 7),
117
- hex8: `${this.hex8.slice(0, 7)}${alphaHex}`,
118
- rgb: `rgb(${rgbaValues[0]}, ${rgbaValues[1]}, ${rgbaValues[2]})`,
119
- rgba: `rgba(${rgbaValues[0]}, ${rgbaValues[1]}, ${rgbaValues[2]}, ${alphaDecimal})`,
120
- hsl: `hsl(${hslaValues[0]}, ${hslaValues[1]}%, ${hslaValues[2]}%)`,
121
- hsla: `hsla(${hslaValues[0]}, ${hslaValues[1]}%, ${hslaValues[2]}%, ${alphaDecimal})`,
122
- };
123
- }
124
114
  const rgbValues = _extractSolidColorValues(this.rgb);
125
115
  const hslValues = _extractSolidColorValues(this.hsl);
126
116
  return {
127
- hex: this.hex.slice(0, 7),
128
- hex8: `${this.hex.slice(0, 7)}${alphaHex}`,
117
+ hex: this.hex.slice(0, 7).toUpperCase(),
118
+ hex8: `${this.hex.slice(0, 7)}${alphaHex}`.toUpperCase(),
129
119
  rgb: `rgb(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]})`,
130
120
  rgba: `rgba(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]}, ${alphaDecimal})`,
131
121
  hsl: `hsl(${hslValues[0]}, ${hslValues[1]}%, ${hslValues[2]}%)`,
@@ -1,5 +1,5 @@
1
1
  export declare class Chronos {
2
- private readonly date;
2
+ #private;
3
3
  /**
4
4
  * * Creates a new immutable Chronos instance.
5
5
  * @param value - A date value (`timestamp`, `string`, `Date`, `Chronos`).
@@ -13,7 +13,29 @@ export declare class Chronos {
13
13
  toISOString(): string;
14
14
  /** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
15
15
  getTimeStamp(): number;
16
- /** * Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC). */
16
+ /** * Returns the date value as a `Date` object. */
17
+ get date(): Date;
18
+ /** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
19
+ get unix(): number;
20
+ /**
21
+ * @instance Returns the current date and time in a specified format.
22
+ *
23
+ * @param format - The desired format (Default format is `DD-MM-YYYY HH:mm:ss:mss` = `30-06-1995 15:55:58:775`).
24
+ * @returns Formatted date string in desired format.
25
+ */
26
+ today(format?: string): string;
27
+ /**
28
+ * @static Returns the current date and time in a specified format.
29
+ *
30
+ * @param format - The desired format (Default format is `DD-MM-YYYY HH:mm:ss:mss` = `30-06-1995 15:55:58:775`).
31
+ * @returns Formatted date string in desired format.
32
+ */
33
+ static today(format?: string): string;
34
+ /**
35
+ * * Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
36
+ * * It basically calls `Date.now()`.
37
+ * @returns The number of milliseconds elapsed since the Unix epoch.
38
+ */
17
39
  static now(): number;
18
40
  /**
19
41
  * * Formats the date into a custom string format.
@@ -1 +1 @@
1
- {"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AAGA,qBAAa,OAAO;IACnB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAO;IAE5B;;;OAGG;gBACS,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAcpD,qDAAqD;IACrD,MAAM,IAAI,IAAI;IAId,mGAAmG;IACnG,QAAQ,IAAI,MAAM;IAIlB,wDAAwD;IACxD,WAAW,IAAI,MAAM;IAIrB,oFAAoF;IACpF,YAAY,IAAI,MAAM;IAItB,qHAAqH;IACrH,MAAM,CAAC,GAAG,IAAI,MAAM;IAIpB;;;;OAIG;IACH,MAAM,CAAC,MAAM,GAAE,MAAqB,GAAG,MAAM;IA2E7C;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAM9B;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAInC;;;;;;;;OAQG;IACH,cAAc,IAAI,MAAM;IAexB;;;;;OAKG;IACH,UAAU,IAAI,OAAO;CAKrB"}
1
+ {"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AAGA,qBAAa,OAAO;;IAGnB;;;OAGG;gBACS,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAcpD,qDAAqD;IACrD,MAAM,IAAI,IAAI;IAId,mGAAmG;IACnG,QAAQ,IAAI,MAAM;IAIlB,wDAAwD;IACxD,WAAW,IAAI,MAAM;IAIrB,oFAAoF;IACpF,YAAY,IAAI,MAAM;IAItB,mDAAmD;IACnD,IAAI,IAAI,IAAI,IAAI,CAEf;IAED,oFAAoF;IACpF,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;OAKG;IACH,KAAK,CAAC,MAAM,SAA4B,GAAG,MAAM;IAKjD;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,SAA4B,GAAG,MAAM;IAKxD;;;;OAIG;IACH,MAAM,CAAC,GAAG,IAAI,MAAM;IAIpB;;;;OAIG;IACH,MAAM,CAAC,MAAM,GAAE,MAAqB,GAAG,MAAM;IA2E7C;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAM9B;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAInC;;;;;;;;OAQG;IACH,cAAc,IAAI,MAAM;IAexB;;;;;OAKG;IACH,UAAU,IAAI,OAAO;CAKrB"}
@@ -1,6 +1,6 @@
1
1
  import { DAYS, MONTHS, sortedFormats } from './constants';
2
2
  export class Chronos {
3
- date;
3
+ #date;
4
4
  /**
5
5
  * * Creates a new immutable Chronos instance.
6
6
  * @param value - A date value (`timestamp`, `string`, `Date`, `Chronos`).
@@ -13,25 +13,57 @@ export class Chronos {
13
13
  if (isNaN(date.getTime())) {
14
14
  throw new Error('Invalid date provided!');
15
15
  }
16
- this.date = date;
16
+ this.#date = date;
17
17
  }
18
18
  /** * Gets the native `Date` instance (read-only). */
19
19
  toDate() {
20
- return new Date(this.date);
20
+ return new Date(this.#date);
21
21
  }
22
22
  /** * Returns a string representation of a date. The format of the string depends on the locale. */
23
23
  toString() {
24
- return this.date.toString();
24
+ return this.#date.toString();
25
25
  }
26
26
  /** * Returns a date as a string value in ISO format. */
27
27
  toISOString() {
28
- return this.date.toISOString();
28
+ return this.#date.toISOString();
29
29
  }
30
30
  /** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
31
31
  getTimeStamp() {
32
- return this.date.getTime();
32
+ return this.#date.getTime();
33
33
  }
34
- /** * Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC). */
34
+ /** * Returns the date value as a `Date` object. */
35
+ get date() {
36
+ return this.#date;
37
+ }
38
+ /** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
39
+ get unix() {
40
+ return this.#date.getTime();
41
+ }
42
+ /**
43
+ * @instance Returns the current date and time in a specified format.
44
+ *
45
+ * @param format - The desired format (Default format is `DD-MM-YYYY HH:mm:ss:mss` = `30-06-1995 15:55:58:775`).
46
+ * @returns Formatted date string in desired format.
47
+ */
48
+ today(format = 'DD-MM-YYYY HH:mm:ss:mss') {
49
+ const today = new Date();
50
+ return new Chronos(today).format(format);
51
+ }
52
+ /**
53
+ * @static Returns the current date and time in a specified format.
54
+ *
55
+ * @param format - The desired format (Default format is `DD-MM-YYYY HH:mm:ss:mss` = `30-06-1995 15:55:58:775`).
56
+ * @returns Formatted date string in desired format.
57
+ */
58
+ static today(format = 'DD-MM-YYYY HH:mm:ss:mss') {
59
+ const today = new Date();
60
+ return new Chronos(today).format(format);
61
+ }
62
+ /**
63
+ * * Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
64
+ * * It basically calls `Date.now()`.
65
+ * @returns The number of milliseconds elapsed since the Unix epoch.
66
+ */
35
67
  static now() {
36
68
  return Date.now();
37
69
  }
@@ -41,14 +73,14 @@ export class Chronos {
41
73
  * @returns Formatted date string in desired format.
42
74
  */
43
75
  format(format = 'DD-MM-YYYY') {
44
- const year = this.date.getFullYear();
45
- const month = this.date.getMonth();
46
- const day = this.date.getDay();
47
- const date = this.date.getDate();
48
- const hours = this.date.getHours();
49
- const minutes = this.date.getMinutes();
50
- const seconds = this.date.getSeconds();
51
- const milliseconds = this.date.getMilliseconds();
76
+ const year = this.#date.getFullYear();
77
+ const month = this.#date.getMonth();
78
+ const day = this.#date.getDay();
79
+ const date = this.#date.getDate();
80
+ const hours = this.#date.getHours();
81
+ const minutes = this.#date.getMinutes();
82
+ const seconds = this.#date.getSeconds();
83
+ const milliseconds = this.#date.getMilliseconds();
52
84
  const dateComponents = {
53
85
  YYYY: String(year),
54
86
  YY: String(year).slice(-2),
@@ -111,7 +143,7 @@ export class Chronos {
111
143
  * @returns A new `Chronos` instance with the updated date.
112
144
  */
113
145
  addDays(days) {
114
- const newDate = new Date(this.date);
146
+ const newDate = new Date(this.#date);
115
147
  newDate.setDate(newDate.getDate() + days);
116
148
  return new Chronos(newDate);
117
149
  }
@@ -137,7 +169,7 @@ export class Chronos {
137
169
  // Set the time of today to 00:00:00 for comparison purposes
138
170
  today.setHours(0, 0, 0, 0);
139
171
  // Normalize the input date to 00:00:00
140
- const inputDate = new Date(this.date);
172
+ const inputDate = new Date(this.#date);
141
173
  inputDate.setHours(0, 0, 0, 0);
142
174
  const diffTime = inputDate.getTime() - today.getTime();
143
175
  const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
@@ -150,7 +182,7 @@ export class Chronos {
150
182
  * @returns `true` if the year is a leap year, `false` otherwise.
151
183
  */
152
184
  isLeapYear() {
153
- const year = this.date.getFullYear();
185
+ const year = this.#date.getFullYear();
154
186
  return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
155
187
  }
156
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "3.4.5",
3
+ "version": "3.4.7",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions for everyday development needs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",