Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip warnings in test contexts. #441

Merged
merged 13 commits into from
Feb 27, 2024
Merged
6 changes: 6 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ export default {
gamut_mapping: "css",
precision: 5,
deltaE: "76", // Default deltaE method
verbose: globalThis?.process?.env?.NODE_ENV?.toLowerCase() !== "test",
warn: function warn (msg) {
if (this.verbose) {
globalThis?.console?.warn?.(msg);
}
},
};
3 changes: 2 additions & 1 deletion src/deltaE/deltaE2000.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import defaults from "../defaults.js";
import lab from "../spaces/lab.js";
import lch from "../spaces/lch.js";

Expand Down Expand Up @@ -107,7 +108,7 @@ export default function (color, sample, {kL = 1, kC = 1, kH = 1} = {}) {
Δh = hdiff + 360;
}
else {
console.log("the unthinkable has happened");
defaults.warn("the unthinkable has happened");
}

// weighted Hue difference, more for larger Chroma
Expand Down
9 changes: 5 additions & 4 deletions src/parse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as util from "./util.js";
import hooks from "./hooks.js";
import ColorSpace from "./space.js";
import defaults from "./defaults.js";

const noneTypes = new Set(["<number>", "<percentage>", "<angle>"]);

Expand Down Expand Up @@ -104,12 +105,12 @@ export default function parse (str, {meta} = {}) {
}

if (colorSpec.id.startsWith("--") && !id.startsWith("--")) {
console.warn(`${space.name} is a non-standard space and not currently supported in the CSS spec. ` +
`Use prefixed color(${colorSpec.id}) instead of color(${id}).`);
defaults.warn(`${space.name} is a non-standard space and not currently supported in the CSS spec. ` +
`Use prefixed color(${colorSpec.id}) instead of color(${id}).`);
}
if (id.startsWith("--") && !colorSpec.id.startsWith("--")) {
console.warn(`${space.name} is a standard space and supported in the CSS spec. ` +
`Use color(${colorSpec.id}) instead of prefixed color(${id}).`);
defaults.warn(`${space.name} is a standard space and supported in the CSS spec. ` +
`Use color(${colorSpec.id}) instead of prefixed color(${id}).`);
}

return {spaceId: space.id, coords, alpha};
Expand Down