index.js
function colorInit( oldValue ) {
        var color, percentage, colorArgs, colorValue, cssString;
        var balanced = require( 'balanced-match' );

        //
        cssString  = balanced( '(', ')', oldValue );
        colorArgs  = balanced( '(', ')', cssString.body );
        colorValue = balanced( '(', ')', colorArgs.body );

        // If colorValue is undefined, the value is an rbg or similar color.
        if ( undefined !== colorValue ) {
            color      =  colorValue.pre + '( ' + colorValue.body + ' )';
            percentage = colorValue.post;

        } else {
            // The value is an hexadecimal sting or html color
            var hexColor = colorArgs.body.split( ',' );
            color = hexColor[0].trim();

            if (  undefined === hexColor[1] ) {
                percentage = '';
            } else {
                percentage = hexColor[1].trim();
            }
        }

        // Cleans the variable
        if ( percentage ) {
            percentage = percentage.replace( ',', '' ).trim();
            percentage = percentage.replace( '%', '' ) / 100;

        } else {
            // Check if the percentage is undefine or empty and set it to 0
            percentage = '0';
        }

        return colorConvert( percentage, colorArgs.pre, color );
    }
function colorInit( oldValue ) {
        var color, percentage, colorArgs, colorValue, cssString;
        var balanced = require( 'balanced-match' );

        //
        cssString  = balanced( '(', ')', oldValue );
        colorArgs  = balanced( '(', ')', cssString.body );
        colorValue = balanced( '(', ')', colorArgs.body );

        // If colorValue is undefined, the value is an rbg or similar color.
        if ( undefined !== colorValue ) {
            color      =  colorValue.pre + '( ' + colorValue.body + ' )';
            percentage = colorValue.post;

        } else {
            // The value is an hexadecimal sting or html color
            var hexColor = colorArgs.body.split( ',' );
            color = hexColor[0].trim();

            if (  undefined === hexColor[1] ) {
                percentage = '';
            } else {
                percentage = hexColor[1].trim();
            }
        }

        // Cleans the variable
        if ( percentage ) {
            percentage = percentage.replace( ',', '' ).trim();
            percentage = percentage.replace( '%', '' ) / 100;

        } else {
            // Check if the percentage is undefine or empty and set it to 0
            percentage = '0';
        }

        return colorConvert( percentage, colorArgs.pre, color );
    }
function colorInit ( oldValue ) { var color , percentage , colorArgs , colorValue , cssString ; var balanced = require ( 'balanced-match' ) ; // cssString = balanced ( '(' , ')' , oldValue ) ; colorArgs = balanced ( '(' , ')' , cssString . body ) ; colorValue = balanced ( '(' , ')' , colorArgs . body ) ; // If colorValue is undefined, the value is an rbg or similar color. if ( undefined !== colorValue ) { color = colorValue . pre + '( ' + colorValue . body + ' )' ; percentage = colorValue . post ; } else { // The value is an hexadecimal sting or html color var hexColor = colorArgs . body . split ( ',' ) ; color = hexColor [ 0 ] . trim ( ) ; if ( undefined === hexColor [ 1 ] ) { percentage = '' ; } else { percentage = hexColor [ 1 ] . trim ( ) ; } } // Cleans the variable if ( percentage ) { percentage = percentage . replace ( ',' , '' ) . trim ( ) ; percentage = percentage . replace ( '%' , '' ) / 100 ; } else { // Check if the percentage is undefine or empty and set it to 0 percentage = '0' ; } return colorConvert ( percentage , colorArgs . pre , color ) ; }
Gets the type of conversion is needed for the current string
Gets the type of conversion is needed for the current string