MCPcopy Create free account
hub / github.com/adobe/react-spectrum / isHexColorSearch

Function isHexColorSearch

packages/dev/s2-docs/src/searchUtils.tsx:54–63  ·  view source on GitHub ↗

* Checks if a search string looks like a hex color code.

(searchValue: string)

Source from the content-addressed store, hash-verified

52 * Checks if a search string looks like a hex color code.
53 */
54function isHexColorSearch(searchValue: string): boolean {
55 const trimmed = searchValue.trim();
56 // Must start with # or be a valid 3 or 6 character hex string
57 if (trimmed.startsWith('#')) {
58 const hex = trimmed.slice(1);
59 return /^[0-9A-Fa-f]{3}$/.test(hex) || /^[0-9A-Fa-f]{6}$/.test(hex);
60 }
61 // Also match without # if it's exactly 3 or 6 hex characters
62 return /^[0-9A-Fa-f]{6}$/.test(trimmed);
63}
64
65/**
66 * Calculates the color distance between two RGB colors using weighted Euclidean distance.

Callers 1

useFilteredColorsFunction · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected