Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
erikyo committed Dec 29, 2023
1 parent 4a82dfe commit d835acb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
7 changes: 2 additions & 5 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ export function cleanDefinition(string: string): string {
*
* @param {string} value - The percentage value to be normalized.
* @param {number} multiplier - The number to multiply the normalized percentage by.
* @param {boolean} [limit=false] - Whether or not to limit the result within a range.
* @return {number} The normalized percentage value.
*/
export function normalizePercentage(value: string, multiplier: number, limit:boolean = false ): number {
export function normalizePercentage(value: string, multiplier: number): number {
return (parseFloat(value) / 100) * multiplier;
}

Expand All @@ -151,7 +150,6 @@ export function normalizePercentage(value: string, multiplier: number, limit:boo
* @return {number} - The calculated color value fallbacks.
*/
export function colorValueFallbacks(value: string, err?: string): number {

if (value === "infinity") {
console.warn(err || `Positive infinity value has been set to 255: ${value}`);
return 255;
Expand All @@ -165,7 +163,6 @@ export function colorValueFallbacks(value: string, err?: string): number {
return 0;
}


/**
* Takes a string with a css value that could be a number or percentage or an angle in degrees and returns the corresponding 8bit value
*
Expand All @@ -177,7 +174,7 @@ export function colorValueFallbacks(value: string, err?: string): number {
* @return {string} the corresponding value in 8-bit format
*/
export function convertToInt8(value: string, multiplier: number = 255): number {
value = value ? value?.trim() : "0"
value = value ? value?.trim() : "0";
if (isNumeric.test(value)) {
// limit the min and the max value
return limitValue(parseFloat(value) || 0, 0, multiplier);
Expand Down
2 changes: 1 addition & 1 deletion src/hex-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { COLORSTRING, HEX, RGBVALUE } from "./types";
import {fallbackRGB} from "./rgb-utils";
import { fallbackRGB } from "./rgb-utils";

/**
* It returns an object with the hex values of the 3 digit hex color
Expand Down
7 changes: 3 additions & 4 deletions src/hsl-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {cleanDefinition, colorValueFallbacks, convertToInt8, limitValue, normalizeDegrees, splitValues} from "./common";
import { cleanDefinition, colorValueFallbacks, convertToInt8, normalizeDegrees, splitValues } from "./common";
import { HSLVALUE, RGBVALUE } from "./types";

export function fallbackHSL(hsl: string[], err: string = `Invalid HSL color`): string[] {
Expand Down Expand Up @@ -26,15 +26,14 @@ export function parseHsl(hslAsString: string): string[] {

const angleError = (value: string): string => `Invalid angle: ${value} - The none keyword is invalid in legacy color syntax `;


/**
* This function takes an array of strings and returns and object with the hsl values converted into INT8 (0-255)
*
* @param {string[]} hsl - the hsl values to parse from string to int8 values
*
*/
export function getHslValues(hsl: string[]): HSLVALUE {
return {
return {
h: colorValueFallbacks(hsl[0], angleError(hsl[0])) || Math.round(normalizeDegrees(hsl[0])) || 0,
s: colorValueFallbacks(hsl[1]) || convertToInt8(hsl[1], 100) || 0,
l: colorValueFallbacks(hsl[2]) || convertToInt8(hsl[2], 100) || 0,
Expand Down Expand Up @@ -140,6 +139,6 @@ export function valuesToHsl({ r, g, b }: RGBVALUE): string {
* @param {number} hsl.l - The lightness value of the color.
* @return {string} The HSL color as a string.
*/
function HSL(hsl:{h: number, s: number, l: number}): string {
function HSL(hsl: { h: number; s: number; l: number }): string {
return `hsl(${hsl.h},${hsl.s}%,${hsl.l}%)`;
}
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function closest(color: string | COLORSTRING, set: RGBCOLORDEF[] | undefined = c
}
}


if (args?.info) {
const colorValue = getColor(closestColor.name, set);
return {
Expand Down
7 changes: 3 additions & 4 deletions src/rgb-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {cleanDefinition, convertToInt8, limitValue, splitValues} from "./common";
import { cleanDefinition, convertToInt8, limitValue, splitValues } from "./common";
import { RGBVALUE } from "./types";

export function fallbackRGB(rgb: string[], err: string = `Invalid RGB color`): string[] {
Expand All @@ -19,11 +19,10 @@ export function parseRgb(rgbAsString: string): string[] {
const rgb: string[] = splitValues(rgbvalue);

if (rgb.length !== 3 && rgb.length !== 4) {
return fallbackRGB(rgb, `Too few values to define rgb: ${rgbAsString} -> ${rgbvalue}`)
return fallbackRGB(rgb, `Too few values to define rgb: ${rgbAsString} -> ${rgbvalue}`);
} else {
return [rgb[0], rgb[1], rgb[2]];
}

}

/**
Expand All @@ -39,7 +38,7 @@ export function getRgbValues(rgb: string[]): RGBVALUE {
r: limitValue(Math.round(convertToInt8(rgb[0])), 0, 255) || 0,
g: limitValue(Math.round(convertToInt8(rgb[1])), 0, 255) || 0,
b: limitValue(Math.round(convertToInt8(rgb[2])), 0, 255) || 0,
}
};
}

/**
Expand Down

0 comments on commit d835acb

Please sign in to comment.