src/js/utils.js
function parseFunctionFromExpression( expr, func ) {
    let index;
    let result;
    let openBrackets;
    let start;
    let argStart;
    let args;
    const findFunc = new RegExp( `${func}\\s*\\(`, 'g' );
    const results = [];

    if ( !expr || !func ) {
        return results;
    }

    while ( ( result = findFunc.exec( expr ) ) !== null ) {
        openBrackets = 1;
        args = [];
        start = result.index;
        argStart = findFunc.lastIndex;
        index = argStart - 1;
        while ( openBrackets !== 0 && index < expr.length ) {
            index++;
            if ( expr[ index ] === '(' ) {
                openBrackets++;
            } else if ( expr[ index ] === ')' ) {
                openBrackets--;
            } else if ( expr[ index ] === ',' && openBrackets === 1 ) {
                args.push( expr.substring( argStart, index ).trim() );
                argStart = index + 1;
            }
        }
        // add last argument
        if ( argStart < index ) {
            args.push( expr.substring( argStart, index ).trim() );
        }

        // add [ 'function( a ,b)', ['a','b'] ] to result array
        results.push( [ expr.substring( start, index + 1 ), args ] );
    }

    return results;
}
function parseFunctionFromExpression( expr, func ) {
    let index;
    let result;
    let openBrackets;
    let start;
    let argStart;
    let args;
    const findFunc = new RegExp( `${func}\\s*\\(`, 'g' );
    const results = [];

    if ( !expr || !func ) {
        return results;
    }

    while ( ( result = findFunc.exec( expr ) ) !== null ) {
        openBrackets = 1;
        args = [];
        start = result.index;
        argStart = findFunc.lastIndex;
        index = argStart - 1;
        while ( openBrackets !== 0 && index < expr.length ) {
            index++;
            if ( expr[ index ] === '(' ) {
                openBrackets++;
            } else if ( expr[ index ] === ')' ) {
                openBrackets--;
            } else if ( expr[ index ] === ',' && openBrackets === 1 ) {
                args.push( expr.substring( argStart, index ).trim() );
                argStart = index + 1;
            }
        }
        // add last argument
        if ( argStart < index ) {
            args.push( expr.substring( argStart, index ).trim() );
        }

        // add [ 'function( a ,b)', ['a','b'] ] to result array
        results.push( [ expr.substring( start, index + 1 ), args ] );
    }

    return results;
}
function parseFunctionFromExpression ( expr , func ) { let index ; let result ; let openBrackets ; let start ; let argStart ; let args ; const findFunc = new RegExp ( ` ${ func } \\ \\ ` , 'g' ) ; const results = [ ] ; if ( ! expr || ! func ) { return results ; } while ( ( result = findFunc . exec ( expr ) ) !== null ) { openBrackets = 1 ; args = [ ] ; start = result . index ; argStart = findFunc . lastIndex ; index = argStart - 1 ; while ( openBrackets !== 0 && index < expr . length ) { index ++ ; if ( expr [ index ] === '(' ) { openBrackets ++ ; } else if ( expr [ index ] === ')' ) { openBrackets -- ; } else if ( expr [ index ] === ',' && openBrackets === 1 ) { args . push ( expr . substring ( argStart , index ) . trim ( ) ) ; argStart = index + 1 ; } } // add last argument if ( argStart < index ) { args . push ( expr . substring ( argStart , index ) . trim ( ) ) ; } // add [ 'function( a ,b)', ['a','b'] ] to result array results . push ( [ expr . substring ( start , index + 1 ) , args ] ) ; } return results ; }
Parses an Expression to extract all function calls and theirs argument arrays.

@param  {String} expr The expression to search
@param  {String} func The function name to search for
@return {<String, <String*>>} The result array, where each result is an array containing the function call and array of arguments.
Parses an Expression to extract all function calls and theirs argument arrays .