destructure.js
function extractNamedFields(fields, input) {
  var output = Object.create(null);
  fields.forEach(function(field) {
    var subObject = input;
    for (var i = 0; i < field.path.length; i += 1) {
      if (subObject == undefined) {
        throw new Error("Unreachable: matched input will always have fields");
      }
      subObject = subObject[field.path[i]];
    }
    switch (field.typeShortcut) {
      // type matcher:
      case 1:
        subObject = global[field.type](subObject);
      break;
      // literal matcher:
      case 3:
        subObject = field.object;
      break;
    }
    output[field.name] = subObject;
  });
  return output;
}
function extractNamedFields(fields, input) {
  var output = Object.create(null);
  fields.forEach(function(field) {
    var subObject = input;
    for (var i = 0; i < field.path.length; i += 1) {
      if (subObject == undefined) {
        throw new Error("Unreachable: matched input will always have fields");
      }
      subObject = subObject[field.path[i]];
    }
    switch (field.typeShortcut) {
      // type matcher:
      case 1:
        subObject = global[field.type](subObject);
      break;
      // literal matcher:
      case 3:
        subObject = field.object;
      break;
    }
    output[field.name] = subObject;
  });
  return output;
}
function extractNamedFields ( fields , input ) { var output = Object . create ( null ) ; fields . forEach ( function ( field ) { var subObject = input ; for ( var i = 0 ; i < field . path . length ; i += 1 ) { if ( subObject == undefined ) { throw new Error ( "Unreachable: matched input will always have fields" ) ; } subObject = subObject [ field . path [ i ] ] ; } switch ( field . typeShortcut ) { // type matcher: case 1 : subObject = global [ field . type ] ( subObject ) ; break ; // literal matcher: case 3 : subObject = field . object ; break ; } output [ field . name ] = subObject ; } ) ; return output ; }
extract out the named fields from an input
extract out the named fields from an input