### Install Color Contrast Checker via npm Source: https://github.com/bbc/color-contrast-checker/blob/master/README.md Installs the color-contrast-checker package using npm. This can be done directly via the command line or by adding it as a devDependency in your project's package.json file. ```bash npm install color-contrast-checker ``` ```json { "name": "my-app", .., "devDependencies": { .., "color-contrast-checker": "2.1.0" } } ``` -------------------------------- ### Test Color Contrast Checker via npm Source: https://github.com/bbc/color-contrast-checker/blob/master/README.md Runs the test suite for the color-contrast-checker package using npm. This command ensures that the installed package functions as expected and meets the defined test cases. ```bash npm test ``` -------------------------------- ### Apache License 2.0 Boilerplate for Projects Source: https://github.com/bbc/color-contrast-checker/wiki/Home This snippet provides the standard boilerplate text for the Apache License, Version 2.0. It includes the copyright notice and the license terms that must be included when distributing the work or derivative works. ```plaintext Copyright 2019 BBC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` -------------------------------- ### Initialize and Use Color Contrast Checker with RequireJS and jQuery Source: https://github.com/bbc/color-contrast-checker/blob/master/example/index.html This script initializes the ColorContrastChecker module using RequireJS, sets up event listeners for input changes, and updates the contrast level results (Level AA and AAA) based on user input. ```javascript requirejs.config({ "baseUrl": "../", "paths": { "ColorContrastChecker": "src/color-contrast-checker", "jquery": "https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min" } }); require(['jquery','ColorContrastChecker'], function ($, ColorContrastChecker) { var ccc = new ColorContrastChecker(); $('#color1, #color2, #fontsize').on('change', function() { updateResult(ccc); }); updateResult(ccc); }); function updateResult(ccc) { var color1 = $('#color1').val(); var color2 = $('#color2').val(); var fontSize = $('#fontsize').val(); var resultAA = ccc.isLevelAA(color1, color2, fontSize) ? "Valid" : "Not Valid"; var resultAAA = ccc.isLevelAAA(color1, color2, fontSize) ? "Valid" : "Not Valid"; $('#result-AA').text(resultAA); $('#result-AAA').text(resultAAA); }; ``` -------------------------------- ### Check Multiple Color Pairs in JavaScript Source: https://github.com/bbc/color-contrast-checker/blob/master/README.md Processes an array of color pairs, each with associated font sizes, to determine their WCAG AA and AAA contrast compliance. The results are returned as an array of objects indicating the pass/fail status for each level. ```javascript var pairs = [ { 'colorA': '#000000', 'colorB': '#000000', 'fontSize': 14 }, { 'colorA': '#000000', 'colorB': '#FFFFFF', 'fontSize': 14 }, { 'colorA': '#000000', 'colorB': '#848484', 'fontSize': 14 }, { 'colorA': '#000000', 'colorB': '#848484', 'fontSize': 19 }, { 'colorA': '#000000', 'colorB': '#757575', 'fontSize': 14 }, { 'colorA': '#000000', 'colorB': '#656565', 'fontSize': 14 } ]; var results = ccc.checkPairs(pairs); ``` -------------------------------- ### Check WCAG AA Color Contrast in JavaScript Source: https://github.com/bbc/color-contrast-checker/blob/master/README.md Checks if two colors meet the WCAG Level AA contrast requirements for a given font size. It initializes the ColorContrastChecker and then calls the isLevelAA method with the two color codes and font size. ```javascript var ccc = new ColorContrastChecker(); var color1 = "#FFFFFF"; var color2 = "#000000; if (ccc.isLevelAA(color1, color2, 14)) { alert("Valid Level AA"); } else { alert("Invalid Contrast"); } ``` -------------------------------- ### Check Custom Color Contrast Ratio in JavaScript Source: https://github.com/bbc/color-contrast-checker/blob/master/README.md Checks if the contrast ratio between two colors meets a specified custom ratio. This method does not consider font size or WCAG standards, only the provided ratio. ```javascript var ccc = new ColorContrastChecker(); var color1 = "#FFFFFF"; var color2 = "#000000; var customRatio = 5.7; // No need for font size, now that we are using a custom ratio. // This is because we are no longer checking against WCAG requirements. if (ccc.isLevelCustom(color1, color2, customRatio)) { alert("Above given ratio"); } else { alert("Invalid Contrast"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.