The logic above is correct if the color is 100% grayscale, however there are plenty of colors that are "almost" grayscale, e.g. #DEDED9
The function below measures the saturation level of a color, and if the results are less than 8%, it considers the color to be grayscale.
Example:
@debug color.saturation(#DEDED9); // returns => 7.0422535211%
@debug color.saturation(#E2E2D5); // returns => 18.3098591549%
Functions:
@function is-color-grayscale($color){
$saturation: color.saturation($color);
@if ($saturation < 8%) {
@return true;
} @else{
@return false;
}
}
Results:
@debug is-color-grayscale(#DEDED9); // returns => true
@debug is-color-grayscale(#E2E2D5); // returns => false