From ad9aab7417dfe9c94afa294c0db350195c2722af Mon Sep 17 00:00:00 2001 From: ly165334 Date: Mon, 20 Apr 2020 11:00:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/util.ts b/src/util.ts index 2ebd9db..c215256 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,6 +1,6 @@ export function randomColor() { - var letters = "0123456789ABCDEF"; - var color = "#"; + var letters = '0123456789ABCDEF'; + var color = '#'; for (var i = 0; i < 6; i += 1) { color += letters[Math.floor(Math.random() * 16)]; } @@ -8,7 +8,7 @@ export function randomColor() { } export function invertColor(hex: string, bw: boolean) { - if (hex.indexOf("#") === 0) { + if (hex.indexOf('#') === 0) { hex = hex.slice(1); } // convert 3-digit hex to 6-digits. @@ -17,7 +17,7 @@ export function invertColor(hex: string, bw: boolean) { } if (hex.length !== 6) { - throw new Error("Invalid HEX color."); + throw new Error('Invalid HEX color.'); } const r = parseInt(hex.slice(0, 2), 16); @@ -26,7 +26,7 @@ export function invertColor(hex: string, bw: boolean) { if (bw) { // http://stackoverflow.com/a/3943023/112731 - return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? "#000000" : "#FFFFFF"; + return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? '#000000' : '#FFFFFF'; } // invert color components @@ -35,10 +35,10 @@ export function invertColor(hex: string, bw: boolean) { const bb = (255 - b).toString(16); // pad each with zeros and return - return "#" + padZero(rr) + padZero(gg) + padZero(bb); + return '#' + padZero(rr) + padZero(gg) + padZero(bb); } function padZero(str: string, len: number = 2) { - var zeros = new Array(len).join("0"); + var zeros = new Array(len).join('0'); return (zeros + str).slice(-len); }