tasks/lib/update_json.js
function expandField(input, grunt){
  var get = pointer(input);

  return function(memo, fin, fout){
    if(_.isString(fin)){
      var match = fin.match(re.PATH_POINT);
      // matched  ...with a `$.`       ...but not with a `\`
      if(match && match[3] === '$.' && !match[1]){
        // field name, starts with an unescaped `$`, treat as JSON Path
        memo[fout] = jsonPath(input, match[2]);
      }else if(match && match[3] === '/' && !match[1]){
        // field name, treat as a JSON pointer
        memo[fout] = get(match[2]);
      }else{
        memo[fout] = input[match[2]];
      }
    }else if(_.isFunction(fin)){
      // call a function
      memo[fout] = fin(input);
    }else if(_.isArray(fin)){
      // pick out the values
      memo[fout] = _.map(fin, function(value){
        return expandField(input)({}, value, "dummy")["dummy"];
      });
    }else if(_.isObject(fin)){
      // build up an object of something else
      memo[fout] = _.reduce(fin, expandField(input, grunt), {});
    }else if(_.isNull(fin)){
      // copy the value
      memo[fout] = input[fout];
    }else{
      grunt.fail.warn('Could not map `' + JSON.stringify(fin) + '` to `' + 
        JSON.stringify(fout) + '`');
    }
    return memo;
  };
}
function expandField(input, grunt){
  var get = pointer(input);

  return function(memo, fin, fout){
    if(_.isString(fin)){
      var match = fin.match(re.PATH_POINT);
      // matched  ...with a `$.`       ...but not with a `\`
      if(match && match[3] === '$.' && !match[1]){
        // field name, starts with an unescaped `$`, treat as JSON Path
        memo[fout] = jsonPath(input, match[2]);
      }else if(match && match[3] === '/' && !match[1]){
        // field name, treat as a JSON pointer
        memo[fout] = get(match[2]);
      }else{
        memo[fout] = input[match[2]];
      }
    }else if(_.isFunction(fin)){
      // call a function
      memo[fout] = fin(input);
    }else if(_.isArray(fin)){
      // pick out the values
      memo[fout] = _.map(fin, function(value){
        return expandField(input)({}, value, "dummy")["dummy"];
      });
    }else if(_.isObject(fin)){
      // build up an object of something else
      memo[fout] = _.reduce(fin, expandField(input, grunt), {});
    }else if(_.isNull(fin)){
      // copy the value
      memo[fout] = input[fout];
    }else{
      grunt.fail.warn('Could not map `' + JSON.stringify(fin) + '` to `' + 
        JSON.stringify(fout) + '`');
    }
    return memo;
  };
}
function expandField ( input , grunt ) { var get = pointer ( input ) ; return function ( memo , fin , fout ) { if ( _ . isString ( fin ) ) { var match = fin . match ( re . PATH_POINT ) ; // matched  ...with a `$.`       ...but not with a `\` if ( match && match [ 3 ] === '$.' && ! match [ 1 ] ) { // field name, starts with an unescaped `$`, treat as JSON Path memo [ fout ] = jsonPath ( input , match [ 2 ] ) ; } else if ( match && match [ 3 ] === '/' && ! match [ 1 ] ) { // field name, treat as a JSON pointer memo [ fout ] = get ( match [ 2 ] ) ; } else { memo [ fout ] = input [ match [ 2 ] ] ; } } else if ( _ . isFunction ( fin ) ) { // call a function memo [ fout ] = fin ( input ) ; } else if ( _ . isArray ( fin ) ) { // pick out the values memo [ fout ] = _ . map ( fin , function ( value ) { return expandField ( input ) ( { } , value , "dummy" ) [ "dummy" ] ; } ) ; } else if ( _ . isObject ( fin ) ) { // build up an object of something else memo [ fout ] = _ . reduce ( fin , expandField ( input , grunt ) , { } ) ; } else if ( _ . isNull ( fin ) ) { // copy the value memo [ fout ] = input [ fout ] ; } else { grunt . fail . warn ( 'Could not map `' + JSON . stringify ( fin ) + '` to `' + JSON . stringify ( fout ) + '`' ) ; } return memo ; } ; }
factory for a reduce function, bound to the input, that can get the value out of the input
factory for a reduce function bound to the input that can get the value out of the input