MCPcopy
hub / github.com/Lulzx/tinypdf / parseColor

Function parseColor

src/index.ts:63–73  ·  view source on GitHub ↗

* Parse hex color to RGB floats * @param hex - Hex color string (#rgb or #rrggbb) * @returns RGB values 0-1 or null

(hex: string | undefined)

Source from the content-addressed store, hash-verified

61 * @returns RGB values 0-1 or null
62 */
63function parseColor(hex: string | undefined): number[] | null {
64 if (!hex || hex === 'none') return null
65 hex = hex.replace('#', '')
66 if (hex.length === 3) {
67 hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
68 }
69 const r = parseInt(hex.slice(0, 2), 16) / 255
70 const g = parseInt(hex.slice(2, 4), 16) / 255
71 const b = parseInt(hex.slice(4, 6), 16) / 255
72 return [r, g, b]
73}
74
75/**
76 * Escape string for PDF

Callers 3

textFunction · 0.85
rectFunction · 0.85
lineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected