UNPKG

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