Skip to content

Commit

Permalink
Add types to function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jq1836 committed Sep 25, 2023
1 parent 075d34d commit 090edb6
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function getRandomHex() {
return `#${Math.round(randomGenerator() * maxHexColorValue + 1).toString(16).padStart(6, '0')}`;
}

function rgb2lab(rgb) {
function rgb2lab(rgb: number[]) {
let r = rgb[0] / 255;
let g = rgb[1] / 255;
let b = rgb[2] / 255;
Expand All @@ -29,7 +29,7 @@ function rgb2lab(rgb) {

// this delta E (perceptual color distance) implementation taken from @antimatter15 from
// github: https://github.com/antimatter15/rgb-lab
function deltaE(rgbA, rgbB) {
function deltaE(rgbA: number[], rgbB: number[]) {
const labA = rgb2lab(rgbA);
const labB = rgb2lab(rgbB);
const deltaL = labA[0] - labB[0];
Expand All @@ -49,7 +49,7 @@ function deltaE(rgbA, rgbB) {
return distance < 0 ? 0 : Math.sqrt(distance);
}

function hasSimilarExistingColors(existingColors, newHex) {
function hasSimilarExistingColors(existingColors: string[], newHex: string) {
const deltaEThreshold = 11;
// the lower limit of delta E to be similar, more info at http://zschuessler.github.io/DeltaE/learn/
return existingColors.some((existingHex) => {
Expand All @@ -59,7 +59,7 @@ function hasSimilarExistingColors(existingColors, newHex) {
});
}

function getNonRepeatingColor(existingColors) {
function getNonRepeatingColor(existingColors: string[]) {
let generatedHex = getRandomHex();
while (hasSimilarExistingColors(existingColors, generatedHex)) {
generatedHex = getRandomHex();
Expand Down

0 comments on commit 090edb6

Please sign in to comment.