# Code coverage report for lib/utils/colour.js

## Statements: 100% (14 / 14) Branches: 50% (1 / 2) Functions: 100% (3 / 3) Lines: 100% (14 / 14)

All files » lib/utils/ » colour.js

    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

    1
    23

    1
    18
    18

    1
    1
    1
    1

    1
    4

    1

    1

    1/**
     * Encodes a string in a colour: red, yellow or green
     * @param  {String} c   colour to highlight in
     * @param  {String} str the string to encode
     * @return {String}     coloured string for terminal printing
     */
    function colour(c, str) {
      return (colour[c] || colour.black) + str + colour.black;
    }

    function strip(str) {
      re.lastIndex = 0; // reset position
      return str.replace(re, '');
    }

    colour.red = '\x1B[31m';
    colour.yellow = '\x1B[33m';
    colour.green = '\x1B[32m';
    colour.black = '\x1B[39m'

    var reStr = Object.keys(colour).map(function (key) {
      return colour[key];
    }).join('|');

    var re = new RegExp(('(' + reStr + ')').replace(/\[/g, '\\['), 'g');

    colour.strip = strip;

    module.exports = colour;