jasmine-where.js
function parseFnBody(fnBody) {
  
    var fs = fnBody.toString();
    var table = fs.match(/\/(\*){3,3}[^\*]+(\*){3,3}\//);
    var data = table[0].replace(/[\/\*]*[\r]*[\*\/]*/g, '').split('\n');
    var rows = [];
    
    var row, size;
        
    for (var i = 0; i < data.length; i++) {
    
      row = data[i].replace(/\b[\s*]/,'').replace(/(\s)*\b/, '');

      if (row.match(/\S+/)) {

        row = row.replace(/\s+/g, '');

        // empty column
        if (row.match(/[\|][\|]/g)) {
          throw new Error('where() data table has unbalanced columns: ' + row);
        }
        
        row = balanceRowData(row);
        
        // visiting label row
        if (typeof size != 'number') {
          shouldNotHaveDuplicateLabels(row);
          size = row.length;
        }

        // data row length
        if (size !== row.length) {
          throw new Error('where-data table has unbalanced row; expected ' + size + 
                          ' columns but has ' + row.length + ': [' + row.join(', ') + 
                          ']');
        }

        convertNumerics(row);

        rows.push(row);         
      }
    }
    
    // num rows
    if (rows.length < 2) {
      throw new Error('where() data table should contain at least 2 rows but has ' + 
                      rows.length);
    }
    
    return rows;
  }
function parseFnBody(fnBody) {
  
    var fs = fnBody.toString();
    var table = fs.match(/\/(\*){3,3}[^\*]+(\*){3,3}\//);
    var data = table[0].replace(/[\/\*]*[\r]*[\*\/]*/g, '').split('\n');
    var rows = [];
    
    var row, size;
        
    for (var i = 0; i < data.length; i++) {
    
      row = data[i].replace(/\b[\s*]/,'').replace(/(\s)*\b/, '');

      if (row.match(/\S+/)) {

        row = row.replace(/\s+/g, '');

        // empty column
        if (row.match(/[\|][\|]/g)) {
          throw new Error('where() data table has unbalanced columns: ' + row);
        }
        
        row = balanceRowData(row);
        
        // visiting label row
        if (typeof size != 'number') {
          shouldNotHaveDuplicateLabels(row);
          size = row.length;
        }

        // data row length
        if (size !== row.length) {
          throw new Error('where-data table has unbalanced row; expected ' + size + 
                          ' columns but has ' + row.length + ': [' + row.join(', ') + 
                          ']');
        }

        convertNumerics(row);

        rows.push(row);         
      }
    }
    
    // num rows
    if (rows.length < 2) {
      throw new Error('where() data table should contain at least 2 rows but has ' + 
                      rows.length);
    }
    
    return rows;
  }
function parseFnBody ( fnBody ) { var fs = fnBody . toString ( ) ; var table = fs . match ( / \/(\*){3,3}[^\*]+(\*){3,3}\/ / ) ; var data = table [ 0 ] . replace ( / [\/\*]*[\r]*[\*\/]* / g , '' ) . split ( '\n' ) ; var rows = [ ] ; var row , size ; for ( var i = 0 ; i < data . length ; i ++ ) { row = data [ i ] . replace ( / \b[\s*] / , '' ) . replace ( / (\s)*\b / , '' ) ; if ( row . match ( / \S+ / ) ) { row = row . replace ( / \s+ / g , '' ) ; // empty column if ( row . match ( / [\|][\|] / g ) ) { throw new Error ( 'where() data table has unbalanced columns: ' + row ) ; } row = balanceRowData ( row ) ; // visiting label row if ( typeof size != 'number' ) { shouldNotHaveDuplicateLabels ( row ) ; size = row . length ; } // data row length if ( size !== row . length ) { throw new Error ( 'where-data table has unbalanced row; expected ' + size + ' columns but has ' + row . length + ': [' + row . join ( ', ' ) + ']' ) ; } convertNumerics ( row ) ; rows . push ( row ) ; } } // num rows if ( rows . length < 2 ) { throw new Error ( 'where() data table should contain at least 2 rows but has ' + rows . length ) ; } return rows ; }
private method
parseFn() takes a function or string and extracts the data table labels and values.
returns a result object with {body} the function as a string and {table} data array.
private method parseFn () takes a function or string and extracts the data table labels and values . returns a result object with { body } the function as a string and { table } data array .