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

Function simplifyHexAlphaToRgba

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

Source from the content-addressed store, hash-verified

362}
363
364export function simplifyHexAlphaToRgba(input: string): string {
365 if (!input || !input.includes('#')) return input
366
367 return input.replace(/#(?:[0-9a-fA-F]{4}|[0-9a-fA-F]{8})(?![0-9a-fA-F])/g, (match) => {
368 const parsed = parseHexColor(match)
369 if (!parsed || parsed.a >= 0.999) return match
370 const alpha = toDecimalPlace(Math.min(1, Math.max(0, parsed.a)), 2)
371 return `rgba(${parsed.r}, ${parsed.g}, ${parsed.b}, ${alpha})`
372 })
373}
374
375function parseHexColor(input: string): { r: number; g: number; b: number; a: number } | null {
376 let hex = input.trim().replace(/^#/, '')

Callers 2

css.test.tsFile · 0.90
processValueFunction · 0.85

Calls 2

toDecimalPlaceFunction · 0.90
parseHexColorFunction · 0.85

Tested by

no test coverage detected