1 | /**
|
2 | * Type guard to check if the object has a "main" property of type string.
|
3 | *
|
4 | * @param obj - the object to check
|
5 | * @returns boolean
|
6 | */
|
7 | function hasCorrectMainProperty(obj) {
|
8 | return typeof obj.main === 'string';
|
9 | }
|
10 | /**
|
11 | * Checks if the object conforms to the SimplePaletteColorOptions type.
|
12 | * The minimum requirement is that the object has a "main" property of type string, this is always checked.
|
13 | * Optionally, you can pass additional properties to check.
|
14 | *
|
15 | * @param obj - The object to check
|
16 | * @param additionalPropertiesToCheck - Array containing "light", "dark", and/or "contrastText"
|
17 | * @returns boolean
|
18 | */
|
19 | function checkSimplePaletteColorValues(obj, additionalPropertiesToCheck = []) {
|
20 | if (!hasCorrectMainProperty(obj)) {
|
21 | return false;
|
22 | }
|
23 | for (const value of additionalPropertiesToCheck) {
|
24 | if (!obj.hasOwnProperty(value) || typeof obj[value] !== 'string') {
|
25 | return false;
|
26 | }
|
27 | }
|
28 | return true;
|
29 | }
|
30 |
|
31 | /**
|
32 | * Creates a filter function used to filter simple palette color options.
|
33 | * The minimum requirement is that the object has a "main" property of type string, this is always checked.
|
34 | * Optionally, you can pass additional properties to check.
|
35 | *
|
36 | * @param additionalPropertiesToCheck - Array containing "light", "dark", and/or "contrastText"
|
37 | * @returns ([, value]: [any, PaletteColorOptions]) => boolean
|
38 | */
|
39 | export default function createSimplePaletteValueFilter(additionalPropertiesToCheck = []) {
|
40 | return ([, value]) => value && checkSimplePaletteColorValues(value, additionalPropertiesToCheck);
|
41 | } |
\ | No newline at end of file |