#' Check whether the color is dark
#'
#' Functions to check if a color's perceived brightness is dark.
#'
#' @param x a any type color string or a javascript color object specifying.
#'
#' @return Return a boolean indicating whether the color's perceived brightness is dark.
#' @export
#' @examples
#' is_dark("#22DD33")
#' is_dark("RGB(120, 80, 65)")
#' is_dark("lightblue")
is_dark <- function(x) {
cmd <- ifelse(is_js_object(x),
paste0("tinycolor(", x, ").isDark()"),
paste0("tinycolor(\"", x, "\").isDark()"))
out <- ifelse(v8_eval(cmd) == "TRUE", TRUE, FALSE)
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.