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

Function canonicalizeValue

packages/extension/utils/css.ts:1146–1168  ·  view source on GitHub ↗
(key: string, value: string)

Source from the content-addressed store, hash-verified

1144}
1145
1146export function canonicalizeValue(key: string, value: string): string {
1147 const trimmed = value.trim().toLowerCase()
1148
1149 if (/^0+(\.0+)?(px|%|rem|em)?$/.test(trimmed)) {
1150 return '0'
1151 }
1152
1153 if (key === 'color') {
1154 const hex = canonicalizeColor(trimmed)
1155 if (hex) return hex
1156 }
1157
1158 if (key === 'font-weight') {
1159 if (trimmed === 'normal') return '400'
1160 if (trimmed === 'bold') return '700'
1161 }
1162
1163 if (key === 'line-height' && trimmed === 'normal') {
1164 return 'normal'
1165 }
1166
1167 return trimmed.replace(ALL_WHITESPACE_RE, '')
1168}
1169
1170function formatHex(r: number, g: number, b: number): string {
1171 const toHex = (n: number) => n.toString(16).padStart(2, '0')

Callers 6

css.test.tsFile · 0.90
optimizeRunsFunction · 0.90
computeDominantStyleFunction · 0.90
omitCommonFunction · 0.90
stripDefaultTextStylesFunction · 0.85
pruneInheritedTextStylesFunction · 0.85

Calls 1

canonicalizeColorFunction · 0.85

Tested by

no test coverage detected