R/is_dark.R

#' 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)
}
houyunhuang/tinycolor documentation built on June 6, 2019, 7:43 p.m.