@heliosgraphics/utils 6.0.0-alpha.16 → 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.
Files changed (3) hide show
  1. package/colors.ts +6 -0
  2. package/index.ts +1 -1
  3. package/package.json +1 -1
package/colors.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  type TypeRGB = [number, number, number]
2
2
 
3
+ const HEX_COLOR_REGEX: RegExp = /^#(?:[0-9a-fA-F]{3}){1,2}$/
4
+
3
5
  const toHex = (c: unknown): string => {
4
6
  if (c === null || c === undefined) return "ff"
5
7
 
@@ -35,6 +37,10 @@ export const hexToRgb = (hex?: string | null): TypeRGB | null => {
35
37
  return [r, g, b]
36
38
  }
37
39
 
40
+ export const isHexColor = (value?: string | null): boolean => {
41
+ return Boolean(value && HEX_COLOR_REGEX.test(value))
42
+ }
43
+
38
44
  export const rgbToHex = (r: number | string = 255, g: number | string = 255, b: number | string = 255): string => {
39
45
  return `#${toHex(r)}${toHex(g)}${toHex(b)}`
40
46
  }
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.16",
3
+ "version": "6.0.0-alpha.17",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "author": "Chris Puska <chris@puska.org>",