Skip to content

Commit

Permalink
chore: apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Mar 28, 2024
1 parent 34667ed commit 4354b5a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/plugin/getLuminance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ const f = (x: number) => {
const channel = x / 255;
return channel <= 0.040_45
? channel / 12.92
: Math.pow(((channel + 0.055) / 1.055), 2.4);
}
: Math.pow((channel + 0.055) / 1.055, 2.4);
};

/**
* Returns a number (float) representing the luminance of a color.
*/
export const getLuminance: MyColorPlugin<OhColorFactory> = (_, c, cf) => {
const proto = c.prototype as OhColorClass;
const getRGB = proto.rgba;
proto.getLuminance = function() {
proto.getLuminance = function () {
const [r, g, b] = getRGB.bind(this)();
return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);
}
};

return cf as OhColorFactory;
}
};

export default getLuminance
export default getLuminance;
4 changes: 2 additions & 2 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { inputHex } from "./inputHex";
export { outputHex } from "./outputHex";
export { inputNamed } from './inputNamed';
export { getLuminance } from './getLuminance';
export { inputNamed } from "./inputNamed";
export { getLuminance } from "./getLuminance";
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("mycolor", () => {
const { inputHex, getLuminance } = await import("../src/plugin");
const mycolor2 = mycolor.extend(inputHex).extend(getLuminance);
expect(mycolor2("red").getLuminance()).toBe(0.2126);
})
});
});

describe("mycolor built-in plugins", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/get-luminance.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect, it, describe } from "vitest";
import { mycolor } from "../../src";
import { getLuminance } from "../../src/plugin"
import { getLuminance } from "../../src/plugin";

describe("mycolor plugin: getLuminance", () => {
it("should get luminance", () => {
const mycolor2 = mycolor.extend(getLuminance);

expect(mycolor2(255, 255, 0, 1).getLuminance()).toBe(0.9278);
});
})
});

0 comments on commit 4354b5a

Please sign in to comment.