@heliosgraphics/utils 6.0.0-alpha.15 → 6.0.0-alpha.17

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/colors.ts CHANGED
@@ -1,5 +1,20 @@
1
1
  type TypeRGB = [number, number, number]
2
2
 
3
+ const HEX_COLOR_REGEX: RegExp = /^#(?:[0-9a-fA-F]{3}){1,2}$/
4
+
5
+ const toHex = (c: unknown): string => {
6
+ if (c === null || c === undefined) return "ff"
7
+
8
+ const value: number = Math.round(Number(c))
9
+ const isInvalid: boolean = isNaN(value) || value < 0 || value > 255
10
+
11
+ if (isInvalid) return "ff"
12
+
13
+ const hex: string = value.toString(16)
14
+
15
+ return hex.length === 1 ? `0${hex}` : hex
16
+ }
17
+
3
18
  export const hexToRgb = (hex?: string | null): TypeRGB | null => {
4
19
  const isValid: boolean = !!hex && typeof hex === "string"
5
20
 
@@ -22,19 +37,10 @@ export const hexToRgb = (hex?: string | null): TypeRGB | null => {
22
37
  return [r, g, b]
23
38
  }
24
39
 
25
- export const rgbToHex = (r: number | string = 255, g: number | string = 255, b: number | string = 255): string => {
26
- const _toHex = (c: unknown): string => {
27
- if (c === null || c === undefined) return "ff"
28
-
29
- const value: number = Math.round(Number(c))
30
- const isInvalid: boolean = isNaN(value) || value < 0 || value > 255
31
-
32
- if (isInvalid) return "ff"
33
-
34
- const hex: string = value.toString(16)
35
-
36
- return hex.length === 1 ? `0${hex}` : hex
37
- }
40
+ export const isHexColor = (value?: string | null): boolean => {
41
+ return Boolean(value && HEX_COLOR_REGEX.test(value))
42
+ }
38
43
 
39
- return `#${_toHex(r)}${_toHex(g)}${_toHex(b)}`
44
+ export const rgbToHex = (r: number | string = 255, g: number | string = 255, b: number | string = 255): string => {
45
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`
40
46
  }
package/equals.ts CHANGED
@@ -27,7 +27,7 @@ export const getAreSetsEqual = <T>(setA: Set<T>, setB: Set<T>): boolean => {
27
27
 
28
28
  const arrA: Array<T> = Array.from(setA)
29
29
  const arrB: Array<T> = Array.from(setB)
30
- const matched: Array<boolean> = new Array(arrB.length).fill(false)
30
+ const matched: Array<boolean> = Array.from({ length: arrB.length }, () => false)
31
31
 
32
32
  for (let i: number = 0; i < arrA.length; i++) {
33
33
  let foundMatch: boolean = false
package/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { getClasses } from "./classnames"
2
2
  export { copyValue } from "./clipboard"
3
- export { hexToRgb, rgbToHex } from "./colors"
3
+ export { hexToRgb, isHexColor, rgbToHex } from "./colors"
4
4
  export { debounce } from "./debounce"
5
5
  export {
6
6
  getIsEqual,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliosgraphics/utils",
3
- "version": "6.0.0-alpha.15",
3
+ "version": "6.0.0-alpha.17",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "author": "Chris Puska <chris@puska.org>",