R/is_light.R

#' Check whether the color is light
#'
#' Functions to check whether a color's perceived brightness is light.
#'
#' @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 light.
#' @export
#' @examples
#' is_light("#FFF")
#' is_light("#F1C")
#' is_light("not a color")
is_light <- function(x) {
  cmd <- ifelse(is_js_object(x),
                paste0("tinycolor(", x, ").isLight()"),
                paste0("tinycolor(\"", x, "\").isLight()"))
  out <- ifelse(v8_eval(cmd) == "TRUE", TRUE, FALSE)
  return(out)
}
houyunhuang/tinycolor documentation built on June 6, 2019, 7:43 p.m.