Skip to content

Commit

Permalink
refactor: move rounding of color values to separate func
Browse files Browse the repository at this point in the history
  • Loading branch information
fpetrakov committed Nov 9, 2023
1 parent 0f5497a commit c1353d9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ const processDecl = (decl, precision) => {
});
};

const doesNotIncludeVar = (color) => !color.includes("var(--");
const doesNotIncludeVar = (str) => !str.includes("var(--");

const roundColorComponentsValues = (color) => [
color.coords[0].toFixed(3),
color.coords[1].toFixed(3),
color.coords[2].toFixed(1),
];

const getConvertedColor = (color, precision) => {
const clr = new Color(color).to("oklch");
const oklch = new Color(color).to("oklch");

if (precision) {
return clr.toString({ precision });
} else {
clr.coords[0] = Number(clr.coords[0]).toFixed(3);
clr.coords[1] = Number(clr.coords[1]).toFixed(3);
clr.coords[2] = Number(clr.coords[2]).toFixed(1);
return clr.toString();
return oklch.toString({ precision });
}

oklch.coords = roundColorComponentsValues(oklch);
return oklch.toString();
};

export default (precision) => ({
Expand Down

0 comments on commit c1353d9

Please sign in to comment.