style: Unified spacing to 2 and add editor config

This commit is contained in:
Wessel Tip
2021-03-17 14:01:53 +01:00
parent aec47d9d0b
commit 9981a28638
98 changed files with 2931 additions and 2902 deletions

View File

@@ -6,30 +6,30 @@ const hexRegexp = /(^#{0,1}[0-9A-F]{6}$)|(^#{0,1}[0-9A-F]{3}$)|(^#{0,1}[0-9A-F]{
const regexp = /([0-9A-F])([0-9A-F])([0-9A-F])/i;
export default function hexToRgb(value) {
const valid = hexRegexp.test(value);
const valid = hexRegexp.test(value);
if (valid) {
if (value[0] === '#') {
value = value.slice(1, value.length);
}
if (value.length === 3){
value = value.replace(regexp, '$1$1$2$2$3$3');
}
const red = parseInt(value.substr(0, 2), 16);
const green = parseInt(value.substr(2, 2), 16);
const blue = parseInt(value.substr(4, 2), 16);
const alpha = parseInt(value.substr(6, 2), 16) / 255;
const color = setRgba(red, green, blue, alpha);
const hsv = rgbToHsv({ ...color });
return {
...color,
...hsv,
};
if (valid) {
if (value[0] === '#') {
value = value.slice(1, value.length);
}
return false;
if (value.length === 3){
value = value.replace(regexp, '$1$1$2$2$3$3');
}
const red = parseInt(value.substr(0, 2), 16);
const green = parseInt(value.substr(2, 2), 16);
const blue = parseInt(value.substr(4, 2), 16);
const alpha = parseInt(value.substr(6, 2), 16) / 255;
const color = setRgba(red, green, blue, alpha);
const hsv = rgbToHsv({ ...color });
return {
...color,
...hsv,
};
}
return false;
}

View File

@@ -1,19 +1,19 @@
export default function rgbToHex(red, green, blue) {
let r16 = red.toString(16);
let g16 = green.toString(16);
let b16 = blue.toString(16);
let r16 = red.toString(16);
let g16 = green.toString(16);
let b16 = blue.toString(16);
if (red < 16) {
r16 = `0${r16}`;
}
if (red < 16) {
r16 = `0${r16}`;
}
if (green < 16) {
g16 = `0${g16}`;
}
if (blue < 16) {
b16 = `0${b16}`;
}
if (green < 16) {
g16 = `0${g16}`;
}
return r16 + g16 + b16;
if (blue < 16) {
b16 = `0${b16}`;
}
return r16 + g16 + b16;
}

View File

@@ -1,41 +1,41 @@
export default function rgbToHSv({ red, green, blue }) {
let rr, gg, bb, h, s;
let rr, gg, bb, h, s;
const rabs = red / 255;
const gabs = green / 255;
const babs = blue / 255;
const rabs = red / 255;
const gabs = green / 255;
const babs = blue / 255;
const v = Math.max(rabs, gabs, babs);
const diff = v - Math.min(rabs, gabs, babs);
const diffc = c => (v - c) / 6 / diff + 1 / 2;
const v = Math.max(rabs, gabs, babs);
const diff = v - Math.min(rabs, gabs, babs);
const diffc = c => (v - c) / 6 / diff + 1 / 2;
if (diff === 0) {
h = 0;
s = 0;
} else {
s = diff / v;
rr = diffc(rabs);
gg = diffc(gabs);
bb = diffc(babs);
if (diff === 0) {
h = 0;
s = 0;
} else {
s = diff / v;
rr = diffc(rabs);
gg = diffc(gabs);
bb = diffc(babs);
if (rabs === v){
h = bb - gg;
} else if (gabs === v) {
h = (1 / 3) + rr - bb;
} else if (babs === v) {
h = (2 / 3) + gg - rr;
}
if (h < 0) {
h += 1;
} else if (h > 1) {
h -= 1;
}
if (rabs === v){
h = bb - gg;
} else if (gabs === v) {
h = (1 / 3) + rr - bb;
} else if (babs === v) {
h = (2 / 3) + gg - rr;
}
return {
hue: Math.round(h * 360),
saturation: Math.round(s * 100),
value: Math.round(v * 100),
};
if (h < 0) {
h += 1;
} else if (h > 1) {
h -= 1;
}
}
return {
hue: Math.round(h * 360),
saturation: Math.round(s * 100),
value: Math.round(v * 100),
};
}

View File

@@ -1,19 +1,19 @@
const isValidRGBValue = (value) => {
return (typeof (value) === 'number' && Number.isNaN(value) === false && value >= 0 && value <= 255);
return (typeof (value) === 'number' && Number.isNaN(value) === false && value >= 0 && value <= 255);
}
export default function setRGBA(red, green, blue, alpha) {
if (isValidRGBValue(red) && isValidRGBValue(green) && isValidRGBValue(blue)) {
const color = {
red: red | 0,
green: green | 0,
blue: blue | 0,
};
if (isValidRGBValue(red) && isValidRGBValue(green) && isValidRGBValue(blue)) {
const color = {
red: red | 0,
green: green | 0,
blue: blue | 0,
};
if (isValidRGBValue(alpha) === true) {
color.alpha = alpha | 0;
}
return color;
if (isValidRGBValue(alpha) === true) {
color.alpha = alpha | 0;
}
return color;
}
}