UNPKG

@yookue/ts-lang-utils

Version:

Common lang utilities for typescript

17 lines 636 B
export function reverseHex(hex) { if (!hex) { return undefined; } var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; var rep = hex.replace(rgx, function (m, r, g, b) { return r + r + g + g + b + b; }); var arr = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(rep); if (!arr || arr.length !== 4) { return undefined; } var hexR = (255 - Number.parseInt(arr[1], 16)).toString(16).padStart(2, '0'); var hexG = (255 - Number.parseInt(arr[2], 16)).toString(16).padStart(2, '0'); var hexB = (255 - Number.parseInt(arr[3], 16)).toString(16).padStart(2, '0'); return "#".concat(hexR).concat(hexG).concat(hexB); }