SkillAgentSearch skills...

IsDark.js

isDark.js is the shortest (yet still fast) way to know if a color is dark or light. It supports most color formats. No dependencies, crossbrowser and no uses of the DOM.

Install / Use

/learn @JDMCreator/IsDark.js
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

isDark.js

isDark.js is the smallest code to know if any color is dark or light. 538 bytes gzipped // 727 bytes minified. No dependency and crossbrowser (IE9+). Will be adapted for Node.JS.

isDark.js supports every color :

  • HSL() and HSLA()
  • RGB() and RGBA() (including with percentage values)
  • Hexadecimal (#RGB, #RGBA, #RRGGBB and #RRGGBBAA)
  • Every keyname, including rebeccapurple and transparent (return both true)

isDark.js, however, don't detect illegal and deprecated values. It doesn't support currentColor.

Security

Security issues has been solved. Even if the code uses eval, it is safe.

How to use

Just call window.isDark("black") // true.

Examples

isDark("black");
isDark("white");
isDark("salmon");
isDark("rgb(200 24 37)");
isDark("rgba(200, 24, 37)");
isDark("rgb(0% 0% 0%)");
isDark("hsl(0 50% 100%)");
isDark("hsla(0, 50%, 100%, 1)");
isDark("#FFF");
isDark("FFF");
isDark("#FF0000");
isDark("FF000000");

isLight()

function isLight(color){
    return !isDark(color);
}

License

This code is under MIT License.

Ressources

About colors and brightness :

About conversion (all conversion functions were modified) :

Related Skills

View on GitHub
GitHub Stars7
CategoryCustomer
Updated1y ago
Forks1

Languages

JavaScript

Security Score

55/100

Audited on Dec 26, 2024

No findings