diff --git a/index.js b/index.js index 088f558..89ed7e2 100644 --- a/index.js +++ b/index.js @@ -1,58 +1,58 @@ -var rgb = require('rgb'); -var wcag = require('wcag-contrast'); -var isBlank = require('is-blank'); -var isNamedCssColor = require('is-named-css-color'); -var cssColorNames = require('css-color-names'); +var rgb = require('rgb') +var wcag = require('wcag-contrast') +var isBlank = require('is-blank') +var isNamedCssColor = require('is-named-css-color') +var cssColorNames = require('css-color-names') -module.exports.ratio = ratio; -module.exports.score = score; -module.exports.isAccessible = isAccessible; -module.exports.isNotTransparent = isNotTransparent; +module.exports.ratio = ratio +module.exports.score = score +module.exports.isAccessible = isAccessible +module.exports.isNotTransparent = isNotTransparent function ratio(colorOne, colorTwo, options) { - colorOne = getRgbTriplet(colorOne, options); - colorTwo = getRgbTriplet(colorTwo, options); + colorOne = getRgbTriplet(colorOne, options) + colorTwo = getRgbTriplet(colorTwo, options) - return wcag.rgb(colorOne, colorTwo); + return wcag.rgb(colorOne, colorTwo) } function score(colorOne, colorTwo, options) { - var wcagScore = wcag.score(ratio(colorOne, colorTwo, options)); + var wcagScore = wcag.score(ratio(colorOne, colorTwo, options)) if (isBlank(wcagScore)) { - return 'F'; + return 'F' } else { - return wcagScore; + return wcagScore } } function isAccessible(colorOne, colorTwo, options) { - return ratio(colorOne, colorTwo, options) > 4.5; + return ratio(colorOne, colorTwo, options) > 4.5 } function getRgbTriplet(color, options) { if (typeof color !== 'string') { - throw new TypeError('get-contrast expects colors as strings'); + throw new TypeError('get-contrast expects colors as strings') } if (isNamedCssColor(color)) { - color = cssColorNames[color]; + color = cssColorNames[color] } - color = isNotTransparent(color, options); - return color.match(/\((.*)\)/)[1].split(',').slice(0, 3); + color = isNotTransparent(color, options) + return color.match(/\((.*)\)/)[1].split(',').slice(0, 3) } function isNotTransparent(color, options) { - options = options || {}; + options = options || {} // Convert to RGB. - color = rgb(color); + color = rgb(color) // Check if the rgb returned color is rgba and if the 'a' value is 0. - var cArray = color.match(/\((.*)\)/)[1].split(','); + var cArray = color.match(/\((.*)\)/)[1].split(',') if (cArray.length == 4 && cArray[3] == '0' && !options.ignoreAlpha) { - throw new TypeError('get-contrast cannot contrast transparent colors'); + throw new TypeError('get-contrast cannot contrast transparent colors') } else { - return color; + return color } } diff --git a/LICENSE b/license similarity index 96% rename from LICENSE rename to license index 74e4d78..e501481 100644 --- a/LICENSE +++ b/license @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2015 John Otander +Copyright (c) 2014-2016 John Otander Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json index 4163507..f9e4065 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,10 @@ "version": "1.1.1", "description": "Get the contrast ratio and WCAG score between common CSS color types.", "main": "index.js", + "files": [ + "cli.js", + "index.js" + ], "directories": { "test": "test" }, @@ -12,10 +16,7 @@ "scripts": { "test": "mocha test" }, - "repository": { - "type": "git", - "url": "https://github.com/johnotander/get-contrast.git" - }, + "repository": "johnotander/get-contrast", "keywords": [ "wcag", "color", @@ -24,10 +25,6 @@ ], "author": "John Otander (http://johnotander.com/)", "license": "MIT", - "bugs": { - "url": "https://github.com/johnotander/get-contrast/issues" - }, - "homepage": "https://github.com/johnotander/get-contrast", "dependencies": { "css-color-names": "0.0.1", "is-blank": "0.0.1", diff --git a/README.md b/readme.md similarity index 97% rename from README.md rename to readme.md index 282970f..bd25f4c 100644 --- a/README.md +++ b/readme.md @@ -15,7 +15,7 @@ npm i --save get-contrast ## Usage ```javascript -var contrast = require('get-contrast'); +var contrast = require('get-contrast') contrast.ratio('#fafafa', 'rgba(0,0,0,.75)') // => 10 contrast.score('#fafafa', 'rgba(0,0,0,.75)') // => 'AAA' diff --git a/test/test.js b/test.js similarity index 98% rename from test/test.js rename to test.js index 28a652f..cf70c9a 100644 --- a/test/test.js +++ b/test.js @@ -1,5 +1,5 @@ var assert = require('assert'); -var contrast = require('..'); +var contrast = require('./'); describe('ratio', function() {