MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / parseHexColor

Function parseHexColor

packages/extension/utils/css.ts:375–392  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

373}
374
375function parseHexColor(input: string): { r: number; g: number; b: number; a: number } | null {
376 let hex = input.trim().replace(/^#/, '')
377 if (![3, 4, 6, 8].includes(hex.length)) return null
378
379 if (hex.length === 3 || hex.length === 4) {
380 hex = hex
381 .split('')
382 .map((c) => c + c)
383 .join('')
384 }
385
386 const r = parseInt(hex.slice(0, 2), 16)
387 const g = parseInt(hex.slice(2, 4), 16)
388 const b = parseInt(hex.slice(4, 6), 16)
389 const a = hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1
390
391 return { r, g, b, a }
392}
393
394function parseBorderShorthand(normalized: string): {
395 width?: string

Callers 2

simplifyColorMixToRgbaFunction · 0.85
simplifyHexAlphaToRgbaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected