src/_get-expression-value.js
function getExpressionValue (varName, scssExpression) {
    if (is.undef(scssExpression) || is.args.empty(arguments)) {
        message('Error: Missing arguments');
        return undefined;
    }

    if (!is.string(varName) || !is.string(scssExpression)) {
        message('Error: Check arguments type');
        return undefined;
    }

    if (!~scssExpression.indexOf('$')) {
        message('Warning: Check scssExpression to contain valid code')
    }

    // print the interpolated value in comment string
    // /*#{$varName}*/ --> /*varValue*/
    const scssContent = `${scssExpression}/*#{$${varName}}*/`;

    const sassResult = sass.renderSync({
        data: scssContent
    });

    const cssResult = sassResult.css.toString();

    return extractExpressionValue(cssResult);
}
function getExpressionValue (varName, scssExpression) {
    if (is.undef(scssExpression) || is.args.empty(arguments)) {
        message('Error: Missing arguments');
        return undefined;
    }

    if (!is.string(varName) || !is.string(scssExpression)) {
        message('Error: Check arguments type');
        return undefined;
    }

    if (!~scssExpression.indexOf('$')) {
        message('Warning: Check scssExpression to contain valid code')
    }

    // print the interpolated value in comment string
    // /*#{$varName}*/ --> /*varValue*/
    const scssContent = `${scssExpression}/*#{$${varName}}*/`;

    const sassResult = sass.renderSync({
        data: scssContent
    });

    const cssResult = sassResult.css.toString();

    return extractExpressionValue(cssResult);
}
function getExpressionValue ( varName , scssExpression ) { if ( is . undef ( scssExpression ) || is . args . empty ( arguments ) ) { message ( 'Error: Missing arguments' ) ; return undefined ; } if ( ! is . string ( varName ) || ! is . string ( scssExpression ) ) { message ( 'Error: Check arguments type' ) ; return undefined ; } if ( ! ~ scssExpression . indexOf ( '$' ) ) { message ( 'Warning: Check scssExpression to contain valid code' ) } // print the interpolated value in comment string // /*#{$varName}*/ --> /*varValue*/ const scssContent = ` ${ scssExpression } ${ varName } ` ; const sassResult = sass . renderSync ( { data : scssContent } ) ; const cssResult = sassResult . css . toString ( ) ; return extractExpressionValue ( cssResult ) ; }
Resolve variable value
By variable name and previous code
@param varName
@param scssExpression
Resolve variable value By variable name and previous code