@heliosgraphics/utils 6.0.0-alpha.15 → 6.0.0-alpha.16
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 +14 -14
- package/equals.ts +1 -1
- package/package.json +1 -1
package/colors.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
type TypeRGB = [number, number, number]
|
|
2
2
|
|
|
3
|
+
const toHex = (c: unknown): string => {
|
|
4
|
+
if (c === null || c === undefined) return "ff"
|
|
5
|
+
|
|
6
|
+
const value: number = Math.round(Number(c))
|
|
7
|
+
const isInvalid: boolean = isNaN(value) || value < 0 || value > 255
|
|
8
|
+
|
|
9
|
+
if (isInvalid) return "ff"
|
|
10
|
+
|
|
11
|
+
const hex: string = value.toString(16)
|
|
12
|
+
|
|
13
|
+
return hex.length === 1 ? `0${hex}` : hex
|
|
14
|
+
}
|
|
15
|
+
|
|
3
16
|
export const hexToRgb = (hex?: string | null): TypeRGB | null => {
|
|
4
17
|
const isValid: boolean = !!hex && typeof hex === "string"
|
|
5
18
|
|
|
@@ -23,18 +36,5 @@ export const hexToRgb = (hex?: string | null): TypeRGB | null => {
|
|
|
23
36
|
}
|
|
24
37
|
|
|
25
38
|
export const rgbToHex = (r: number | string = 255, g: number | string = 255, b: number | string = 255): string => {
|
|
26
|
-
|
|
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
|
-
}
|
|
38
|
-
|
|
39
|
-
return `#${_toHex(r)}${_toHex(g)}${_toHex(b)}`
|
|
39
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
|
|
40
40
|
}
|
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> =
|
|
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
|