Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit 00589a1

Browse files
committed
feat: expose list of grey algorithms
Closes: #232
1 parent e3ce124 commit 00589a1

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/operations/grey.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,38 @@ import { getOutputImage } from '../utils/getOutputImage';
44

55
import * as greyAlgorithms from './greyAlgorithms';
66

7-
export type GreyAlgorithms = keyof typeof greyAlgorithms;
7+
export const GreyAlgorithm = {
8+
LUMA_709: 'luma709',
9+
LUMA_601: 'luma601',
10+
MAX: 'max',
11+
MIN: 'min',
12+
AVERAGE: 'average',
13+
MINMAX: 'minmax',
14+
RED: 'red',
15+
GREEN: 'green',
16+
BLUE: 'blue',
17+
BLACK: 'black',
18+
CYAN: 'cyan',
19+
MAGENTA: 'magenta',
20+
YELLOW: 'yellow',
21+
HUE: 'hue',
22+
SATURATION: 'saturation',
23+
LIGHTNESS: 'lightness',
24+
} as const satisfies Record<string, keyof typeof greyAlgorithms>;
25+
// eslint-disable-next-line @typescript-eslint/no-redeclare
26+
export type GreyAlgorithm = (typeof GreyAlgorithm)[keyof typeof GreyAlgorithm];
27+
28+
{
29+
// Check that all the algorithms are in the enum.
30+
const algos = new Set<string>(Object.values(GreyAlgorithm));
31+
for (const algo of Object.keys(greyAlgorithms)) {
32+
if (!algos.has(algo)) {
33+
throw new Error(
34+
`Grey algorithm ${algo} is missing in the GreyAlgorithm enum`,
35+
);
36+
}
37+
}
38+
}
839

940
/**
1041
* Call back that converts the RGB channels to grey. It is clamped afterwards.
@@ -28,7 +59,7 @@ export interface GreyOptions {
2859
*
2960
* @default 'luma709'
3061
*/
31-
algorithm?: GreyAlgorithms | GreyAlgorithmCallback;
62+
algorithm?: GreyAlgorithm | GreyAlgorithmCallback;
3263
/**
3364
* Specify wether to keep an alpha channel in the new image or not.
3465
*

0 commit comments

Comments
 (0)