All files index.js

91.67% Statements 22/24
80% Branches 12/15
100% Functions 5/5
91.67% Lines 22/24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x 1x   1x 17x 17x 17x 17x     17x   17x     17x 1x   17x 1x     17x   14x 14x 14x       14x   3x 3x   3x              
let postcss = require('postcss');
let helpers = require('postcss-message-helpers');
let color = require('color');
 
module.exports = postcss.plugin('postcss-make-it-bright', function (opts) {
    opts = opts || {};
    return function (style) {
        style.walkDecls(function (decl) {
            Iif (!decl.value) {
                return;
            }
            let inputColor = color(decl.value);
 
            let lighter = Number.isInteger(opts.lighter) ?
                Number(opts.lighter) / 100 :
                0.5;
            if (lighter > 1) {
                lighter = 1;
            }
            if (lighter < 0) {
                lighter = 0;
            }
 
            switch (inputColor.model) {
            case 'rgb':
                decl.value = helpers.try(() => {
                    const output = inputColor.lighten(lighter);
                    return decl.value.includes('rgb') ?
                        output.rgb() :
                        output.hex();
                }, decl.source);
                break;
            case 'hsl':
                decl.value = helpers.try(() => {
                    return inputColor.lighten(lighter);
                }, decl.source);
                break;
            default:
                return;
            }
        });
    };
});