GithubHelp home page GithubHelp logo

dallegos / cococh Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 65 KB

Yet another simple color contrast validator based on the WCAG recommendations.

Home Page: https://www.npmjs.com/package/cococh

License: Apache License 2.0

JavaScript 100.00%
accessibility checker color contrast validator wcag wcag2

cococh's Introduction

Cococh (Color contrast checker)

GitHub package.json version (branch) GitHub Workflow Status (with event) Codecov GitHub npm bundle size

A set of tools for validating the color contrast based on WCAG 2.0 standard.

Installation

Using npm

npm i cococh@latest

Using yarn

yarn add cococh@latest

or installing it manually on package.json

{
    //...otherConfigs,
    "dependencies": {
        "cococh": "^1.2.0"
    }   
}

and then do npm install or yarn install

Usage

It is possible to use different color formats and combine them:

// With rgb()
const ratios = getContrastRatios("rgb(255, 0, 0)", "rgb(0, 0, 0)");

// with rgb() and 3-digit hexa
const ratios = getContrastRatios("rgb(255, 0, 0)", "#000");

// with hsl() and rgb()
const ratios = getContrastRatios("hsl(0, 100%, 50%)", "rgb(0, 0, 0)");

// with 3-digit hexa and 6-digit hexa
const ratios = getContrastRatios("#f00", "#000000");

Any combination is valid, and you will receive an object like this:

{
    "normal": {
        "AA": true,
        "AAA": false
    },
    "large": {
        "AA": true,
        "AAA": true
    }
}

You can validate like this:

if (ratios.large.AAA) {
    // Is valid to use as large text on an AAA level
}

if (ratios.large.AA) {
    // Is valid to use as large text on an AA level
}

if (ratios.normal.AAA) {
    // Is valid to use as normal text on an AAA level
}

if (ratios.normal.AA) {
    // Is valid to use as normal text on an AA level
}

Test

To test it use:

yarn test

or

npm test

cococh's People

Contributors

dallegos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.