@mui/material
Version:
Material UI is an open-source React component library that implements Google's Material Design. It's comprehensive and can be used in production out of the box.
47 lines (45 loc) • 1.66 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createSimplePaletteValueFilter;
/**
* Type guard to check if the object has a "main" property of type string.
*
* @param obj - the object to check
* @returns boolean
*/
function hasCorrectMainProperty(obj) {
return typeof obj.main === 'string';
}
/**
* Checks if the object conforms to the SimplePaletteColorOptions type.
* The minimum requirement is that the object has a "main" property of type string, this is always checked.
* Optionally, you can pass additional properties to check.
*
* @param obj - The object to check
* @param additionalPropertiesToCheck - Array containing "light", "dark", and/or "contrastText"
* @returns boolean
*/
function checkSimplePaletteColorValues(obj, additionalPropertiesToCheck = []) {
if (!hasCorrectMainProperty(obj)) {
return false;
}
for (const value of additionalPropertiesToCheck) {
if (!obj.hasOwnProperty(value) || typeof obj[value] !== 'string') {
return false;
}
}
return true;
}
/**
* Creates a filter function used to filter simple palette color options.
* The minimum requirement is that the object has a "main" property of type string, this is always checked.
* Optionally, you can pass additional properties to check.
*
* @param additionalPropertiesToCheck - Array containing "light", "dark", and/or "contrastText"
* @returns ([, value]: [any, PaletteColorOptions]) => boolean
*/
function createSimplePaletteValueFilter(additionalPropertiesToCheck = []) {
return ([, value]) => value && checkSimplePaletteColorValues(value, additionalPropertiesToCheck);
}
;