lib/altshift/cli/style.js
function applyStyles(str, style) {
    //Check if not style
    if (! style) {
        return str;
    }

    //Check shortcut if string is empty
    //str = '' + str;
    if (!str || str.length === 0) {
        return str;
    }

    var output, i, rule, textdecoration;
    //style = style || {};

    output = str;

    //1. font-weight
    rule = style['font-weight'];
    if (rule) {
        output = applyStyle(output, 'font-weight', rule);
    }

    //2. font-style
    rule = style['font-style'];
    if (rule) {
        output = applyStyle(output, 'font-style', rule);
    }

    //3. color
    rule = style.color;
    if (style.color) {
        output = applyStyle(output, 'color', rule);
    }

    //4. background color
    rule = style['background-color'];
    if (rule) {
        output = applyStyle(output, 'background-color', rule);
    }

    //Normalize as array
    rule = style['text-decoration'];
    if (isArray(rule)) {
        //do all decoration
        i = rule.length - 1;
        while (i >= 0) {
            i -= 1;
            output = applyStyle(output, 'text-decoration', rule[i]);
        }
    } else {
        output = applyStyle(output, 'text-decoration', style['text-decoration']);
    }
}
function applyStyles(str, style) {
    //Check if not style
    if (! style) {
        return str;
    }

    //Check shortcut if string is empty
    //str = '' + str;
    if (!str || str.length === 0) {
        return str;
    }

    var output, i, rule, textdecoration;
    //style = style || {};

    output = str;

    //1. font-weight
    rule = style['font-weight'];
    if (rule) {
        output = applyStyle(output, 'font-weight', rule);
    }

    //2. font-style
    rule = style['font-style'];
    if (rule) {
        output = applyStyle(output, 'font-style', rule);
    }

    //3. color
    rule = style.color;
    if (style.color) {
        output = applyStyle(output, 'color', rule);
    }

    //4. background color
    rule = style['background-color'];
    if (rule) {
        output = applyStyle(output, 'background-color', rule);
    }

    //Normalize as array
    rule = style['text-decoration'];
    if (isArray(rule)) {
        //do all decoration
        i = rule.length - 1;
        while (i >= 0) {
            i -= 1;
            output = applyStyle(output, 'text-decoration', rule[i]);
        }
    } else {
        output = applyStyle(output, 'text-decoration', style['text-decoration']);
    }
}
function applyStyles ( str , style ) { //Check if not style if ( ! style ) { return str ; } //Check shortcut if string is empty //str = '' + str; if ( ! str || str . length === 0 ) { return str ; } var output , i , rule , textdecoration ; //style = style || {}; output = str ; //1. font-weight rule = style [ 'font-weight' ] ; if ( rule ) { output = applyStyle ( output , 'font-weight' , rule ) ; } //2. font-style rule = style [ 'font-style' ] ; if ( rule ) { output = applyStyle ( output , 'font-style' , rule ) ; } //3. color rule = style . color ; if ( style . color ) { output = applyStyle ( output , 'color' , rule ) ; } //4. background color rule = style [ 'background-color' ] ; if ( rule ) { output = applyStyle ( output , 'background-color' , rule ) ; } //Normalize as array rule = style [ 'text-decoration' ] ; if ( isArray ( rule ) ) { //do all decoration i = rule . length - 1 ; while ( i >= 0 ) { i -= 1 ; output = applyStyle ( output , 'text-decoration' , rule [ i ] ) ; } } else { output = applyStyle ( output , 'text-decoration' , style [ 'text-decoration' ] ) ; } }
Return a formatted str

@param {string} str
@param {Object} style
- font-weight : normal|bold
- font-style : normal|italic
- background-color : transparent|black|red|green|yellow|blue|magenta|cyan|white
- color : default|black|red|green|yellow|blue|magenta|cyan|white
- text-decoration : [underline|blink|reverse|invisible, ...]

@return {string}
Return a formatted str