robosats/frontend/src/utils/hexToRgb.ts
KoalaSat 293c0b604d Refactor contexts and models (#921)
* Add SVG icons for map pins

* Add federation basis and new coordinator form (#793)

* Add new coordinator entry issue form

* Add Federation basis

* Fix eslint errors from F2F and fix languages

* Redo eslint @typescript-eslint/strict-boolean-expressions

* Robot Page working

* Contexts Working

* Garage Working

* CurrentOrder working

* Federation model working

---------

Co-authored-by: Reckless_Satoshi <reckless.satoshi@protonmail.com>
Co-authored-by: Reckless_Satoshi <90936742+Reckless-Satoshi@users.noreply.github.com>
2023-12-02 10:40:59 +00:00

14 lines
403 B
TypeScript

export default function hexToRgb(c: string): string[] | undefined {
if (c.includes('rgb')) {
const vals = c.split('(')[1].split(')')[0];
return vals.split(',');
}
if (/^#([a-f0-9]{3}){1,2}$/.test(c)) {
if (c.length === 4) {
c = '#' + [c[1], c[1], c[2], c[2], c[3], c[3]].join('');
}
c = '0x' + c.substring(1);
return [(c >> 16) & 255, (c >> 8) & 255, c & 255];
}
}