hex2rgb.js (931B)
1 /** 2 { 3 "api":1, 4 "name":"HEX2RGB", 5 "description":"Convert colors in hexadecimal to RGB.", 6 "author":"Yohanes Bandung Bondowoso", 7 "icon":"table", 8 "tags":"flip" 9 } 10 **/ 11 12 function main(input) { 13 const items = input.text.split("\n"); 14 const convertedItems = items.map((item) => { 15 if (item) { 16 return makin(item); 17 } else { 18 return item; 19 } 20 }); 21 input.text = String(convertedItems.join("\n")); 22 } 23 24 function makin(input) { 25 R = hexToR(input); 26 G = hexToG(input); 27 B = hexToB(input); 28 29 return `rgb(${R.toString()}, ${G.toString()}, ${B.toString()})`; 30 } 31 32 function hexToR(h) { 33 return parseInt(cutHex(h).substring(0, 2), 16); 34 } 35 function hexToG(h) { 36 return parseInt(cutHex(h).substring(2, 4), 16); 37 } 38 function hexToB(h) { 39 return parseInt(cutHex(h).substring(4, 6), 16); 40 } 41 function cutHex(h) { 42 return h.charAt(0) == "#" ? h.substring(1, 7) : h; 43 } 44