pax_global_header00006660000000000000000000000064127546503170014524gustar00rootroot0000000000000052 comment=af3d4124cea446d063c041b808e77553dbefb231 colormin-1.1.2/000077500000000000000000000000001275465031700133475ustar00rootroot00000000000000colormin-1.1.2/.babelrc000066400000000000000000000001221275465031700147350ustar00rootroot00000000000000{ "presets": ["es2015-loose", "stage-0"], "plugins": ["add-module-exports"] } colormin-1.1.2/.editorconfig000066400000000000000000000003171275465031700160250ustar00rootroot00000000000000# editorconfig.org root = true [*] indent_style = space indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false colormin-1.1.2/.gitignore000066400000000000000000000000401275465031700153310ustar00rootroot00000000000000dist node_modules npm-debug.log colormin-1.1.2/.travis.yml000066400000000000000000000003141275465031700154560ustar00rootroot00000000000000sudo: false language: node_js matrix: include: - node_js: '5' - node_js: '4' - node_js: '0.12' env: NO_ESLINT=true script: "[[ $NO_ESLINT == true ]] && npm run test-012 || npm test" colormin-1.1.2/CHANGELOG.md000066400000000000000000000011271275465031700151610ustar00rootroot00000000000000# 1.1.2 * Improved performance of `isKeyword` (thanks to @maxnordlund & @ljharb). # 1.1.1 * Bump css-color-names to 0.0.4. # 1.1.0 * Add a legacy option for old Internet Explorer versions. # 1.0.7 * Update color to 0.11.0. # 1.0.6 * Now passes through invalid colour functions. # 1.0.5 * Performance tweaks. * Update css-color-names to 0.0.3. # 1.0.4 * Fixes an issue with the last patch - module was not working correctly on Node 0.10. # 1.0.3 * Updated to ES6. # 1.0.2 * Improved regex for finding leading zeroes. # 1.0.1 * Update color to 0.8.0. # 1.0.0 * Initial release. colormin-1.1.2/LICENSE-MIT000066400000000000000000000021041275465031700150000ustar00rootroot00000000000000Copyright (c) Ben Briggs (http://beneb.info) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. colormin-1.1.2/README.md000066400000000000000000000024741275465031700146350ustar00rootroot00000000000000# colormin [![Build Status](https://travis-ci.org/ben-eb/colormin.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/colormin.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/colormin.svg)][deps] > Turn a CSS color into its smallest representation. ## Install With [npm](https://npmjs.org/package/colormin) do: ``` npm install colormin --save ``` ## Example ```js var colormin = require('colormin'); console.log(colormin('rgba(255, 0, 0, 1)')); // => 'red' ``` colormin works for rgb, rgba, hsl, hsla, hex & css color keywords. See more example output in the [tests](src/__tests__/index.js). Note that colormin does not convert invalid CSS colors, as it is not a color validator. ## API ### colormin(color, [options]) #### color Type: `string` The color to minify. #### options ##### legacy Type: `boolean` Default: `false` Set this to `true` to enable IE < 10 compatibility; the browser chokes on the `transparent` keyword, so in this mode the conversion from `rgba(0,0,0,0)` is turned off. ## Contributing Pull requests are welcome. If you add functionality, then please add unit tests to cover it. ## License MIT © [Ben Briggs](http://beneb.info) [ci]: https://travis-ci.org/ben-eb/colormin [deps]: https://gemnasium.com/ben-eb/colormin [npm]: http://badge.fury.io/js/colormin colormin-1.1.2/package.json000066400000000000000000000025371275465031700156440ustar00rootroot00000000000000{ "name": "colormin", "version": "1.1.2", "description": "Turn a CSS color into its smallest representation.", "main": "dist/index.js", "files": [ "LICENSE-MIT", "dist" ], "scripts": { "pretest": "eslint src", "prepublish": "del-cli dist && babel src --out-dir dist --ignore /__tests__/", "test": "ava src/__tests__", "test-012": "ava src/__tests__" }, "homepage": "https://github.com/ben-eb/colormin", "keywords": [ "color", "colors", "compression", "css", "minify" ], "author": { "name": "Ben Briggs", "email": "beneb.info@gmail.com", "url": "http://beneb.info" }, "license": "MIT", "dependencies": { "color": "^0.11.0", "css-color-names": "0.0.4", "has": "^1.0.1" }, "devDependencies": { "ava": "^0.16.0", "babel-cli": "^6.3.17", "babel-core": "^6.3.26", "babel-plugin-add-module-exports": "^0.2.0", "babel-preset-es2015": "^6.3.13", "babel-preset-es2015-loose": "^7.0.0", "babel-preset-stage-0": "^6.3.13", "babel-register": "^6.9.0", "del-cli": "^0.2.0", "eslint": "^3.0.0", "eslint-config-cssnano": "^3.0.0", "eslint-plugin-babel": "^3.3.0", "eslint-plugin-import": "^1.10.2" }, "repository": "ben-eb/colormin", "eslintConfig": { "extends": "cssnano" }, "ava": { "require": "babel-register" } } colormin-1.1.2/src/000077500000000000000000000000001275465031700141365ustar00rootroot00000000000000colormin-1.1.2/src/__tests__/000077500000000000000000000000001275465031700160745ustar00rootroot00000000000000colormin-1.1.2/src/__tests__/index.js000066400000000000000000000063461275465031700175520ustar00rootroot00000000000000import test from 'ava'; import min from '..'; function isEqual (t, input, output, options = {}) { t.deepEqual(min(input, options), output); } test('should lowercase keywords', isEqual, 'RED', 'red'); test('should convert shorthand hex to keyword', isEqual, '#f00', 'red'); test('should convert longhand hex to keyword', isEqual, '#ff0000', 'red'); test('should convert rgb to keyword', isEqual, 'rgb(255,0,0)', 'red'); test('should convert fully opaque rgb to keyword', isEqual, 'rgba(255, 0, 0, 1)', 'red'); test('should convert hsl to keyword', isEqual, 'hsl(0, 100%, 50%)', 'red'); test('should convert fully oqaque hsl to keyword', isEqual, 'hsla(0, 100%, 50%, 1)', 'red'); test('should convert translucent hsla to rgba', isEqual, 'hsla(0, 100%, 50%, .5)', 'rgba(255,0,0,.5)'); test('should convert longhand hex to shorthand, case insensitive', isEqual, '#FFFFFF', '#fff'); test('should convert keyword to hex, case insensitive', isEqual, 'WHiTE', '#fff'); test('should convert keyword to hex', isEqual, 'yellow', '#ff0'); test('should convert rgb to hex', isEqual, 'rgb(12, 134, 29)', '#0c861d'); test('should convert hsl to hex', isEqual, 'hsl(230, 50%, 40%)', '#349'); test('should convert another longhand hex to keyword', isEqual, '#000080', 'navy'); test('should convert rgba to hsla when shorter', isEqual, 'rgba(199, 190, 179, 0.8)', 'hsla(33,15%,74%,.8)'); test('should convert this specific rgba value to "transparent"', isEqual, 'rgba(0,0,0,0)', 'transparent'); test('should not convert this specific rgba value to "transparent" (legacy mode)', isEqual, 'rgba(0,0,0,0)', 'rgba(0,0,0,0)', {legacy: true}); test('should convert this specific hsla value to "transparent"', isEqual, 'hsla(0,0%,0%,0)', 'transparent'); test('should convert hsla values with 0 saturation & 0 lightness to "transparent"', isEqual, 'hsla(200,0%,0%,0)', 'transparent'); test('should leave transparent as it is', isEqual, 'transparent', 'transparent'); test('should prefer to output hex rather than keywords when they are the same length', isEqual, '#696969', '#696969'); test('should cap values at their maximum', isEqual, 'rgb(400,400,400)', '#fff'); test('should cap values at their maximum (2)', isEqual, 'hsl(400, 400%, 50%)', 'red'); test('should remove leading zeros', isEqual, 'hsla(0, 0%, 100%, 0.5)', 'hsla(0,0%,100%,.5)'); test('should convert signed numbers', isEqual, 'rgba(-100,0,-100,.5)', 'rgba(0,0,0,.5)'); test('should convert signed numbers (2)', isEqual, 'hsla(-400,50%,10%,.5)', 'rgba(38,13,13,.5)'); test('should convert percentage based rgb values', isEqual, 'rgb(100%,100%,100%)', '#fff'); test('should convert percentage based rgba values (2)', isEqual, 'rgba(50%,50%,50%,0.5)', 'hsla(0,0%,50%,.5)'); test('should convert percentage based rgba values (3)', isEqual, 'rgb(100%,100%,100%)', '#fff'); test('should convert percentage based rgba values (4)', isEqual, 'rgba(100%,100%,100%,0.5)', 'hsla(0,0%,100%,.5)'); test('should convert percentage based rgba values (5)', isEqual, 'rgba(100%,64.7%,0%,.5)', 'rgba(255,165,0,.5)'); test('should pass through on invalid rgb functions', isEqual, 'rgb(50%,23,54)', 'rgb(50%,23,54)'); test('should pass through if not recognised', t => { t.deepEqual(min('Unrecognised'), 'Unrecognised'); t.deepEqual(min('inherit'), 'inherit'); }); colormin-1.1.2/src/index.js000066400000000000000000000031171275465031700156050ustar00rootroot00000000000000import color from 'color'; import colourNames from './lib/colourNames'; import toShorthand from './lib/toShorthand'; import * as ctype from './lib/colourType'; import trim from './lib/stripWhitespace'; import zero from './lib/trimLeadingZero'; const filterColor = callback => Object.keys(colourNames).filter(callback); const shorter = (a, b) => (a && a.length < b.length ? a : b).toLowerCase(); export default (colour, opts = {}) => { if (ctype.isRGBorHSL(colour)) { let c; // Pass through invalid rgb/hsl functions try { c = color(colour); } catch (err) { return colour; } if (c.alpha() === 1) { // At full alpha, just use hex colour = c.hexString(); } else { let rgb = c.rgb(); if ( !opts.legacy && !rgb.r && !rgb.g && !rgb.b && !rgb.a ) { return 'transparent'; } let hsla = c.hslaString(); let rgba = c.rgbString(); return zero(trim(hsla.length < rgba.length ? hsla : rgba)); } } if (ctype.isHex(colour)) { colour = toShorthand(colour.toLowerCase()); let keyword = filterColor(key => colourNames[key] === colour)[0]; return shorter(keyword, colour); } else if (ctype.isKeyword(colour)) { let hex = colourNames[filterColor(k => k === colour.toLowerCase())[0]]; return shorter(hex, colour); } // Possibly malformed, just pass through return colour; }; colormin-1.1.2/src/lib/000077500000000000000000000000001275465031700147045ustar00rootroot00000000000000colormin-1.1.2/src/lib/colourNames.js000066400000000000000000000002641275465031700175330ustar00rootroot00000000000000import colours from 'css-color-names'; import toShorthand from './toShorthand'; Object.keys(colours).forEach(c => (colours[c] = toShorthand(colours[c]))); export default colours; colormin-1.1.2/src/lib/colourType.js000066400000000000000000000007021275465031700174060ustar00rootroot00000000000000import has from 'has'; import colourNames from './colourNames'; import toLonghand from './toLonghand'; export const isHex = colour => { if (colour[0] === '#') { let c = toLonghand(colour).substring(1); return c.length === 6 && ! isNaN(parseInt(c, 16)); } return false; }; export const isRGBorHSL = colour => /^(rgb|hsl)a?\(.*?\)/.test(colour); export const isKeyword = colour => has(colourNames, colour.toLowerCase()); colormin-1.1.2/src/lib/stripWhitespace.js000066400000000000000000000000561275465031700204210ustar00rootroot00000000000000export default str => str.replace(/\s/g, ''); colormin-1.1.2/src/lib/toLonghand.js000066400000000000000000000002741275465031700173420ustar00rootroot00000000000000export default hex => { if (hex.length !== 4) { return hex; } const r = hex[1]; const g = hex[2]; const b = hex[3]; return '#' + r + r + g + g + b + b; }; colormin-1.1.2/src/lib/toShorthand.js000066400000000000000000000003411275465031700175350ustar00rootroot00000000000000export default hex => { if ( hex.length === 7 && hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6] ) { return '#' + hex[2] + hex[4] + hex[6]; } return hex; }; colormin-1.1.2/src/lib/trimLeadingZero.js000066400000000000000000000000771275465031700203450ustar00rootroot00000000000000export default str => str.replace(/([^\d])0(\.\d*)/g, '$1$2');