src/peliasDocGenerators.js
function setupDocument(record, hierarchy) {
  var wofDoc = new Document( 'whosonfirst', record.place_type, record.id );

  if (record.name) {
    wofDoc.setName('default', record.name);

    // index a version of postcode which doesn't contain whitespace
    if (record.place_type === 'postalcode' && typeof record.name === 'string') {
      var sans_whitespace = record.name.replace(/\s/g, '');
      if (sans_whitespace !== record.name) {
        wofDoc.setNameAlias('default', sans_whitespace);
      }
    }

    // index name aliases for all other records (where available)
    else if (record.name_aliases.length) {
      record.name_aliases.forEach(alias => {
        wofDoc.setNameAlias('default', alias);
      });
    }
  }
  wofDoc.setCentroid({ lat: record.lat, lon: record.lon });

  // only set population if available
  if (record.population) {
    wofDoc.setPopulation(record.population);
  }

  // only set popularity if available
  if (record.popularity) {
    wofDoc.setPopularity(record.popularity);
  }

  // WOF bbox is defined as:
  // lowerLeft.lon, lowerLeft.lat, upperRight.lon, upperRight.lat
  // so convert to what ES understands
  if (!_.isUndefined(record.bounding_box)) {
    var parsedBoundingBox = record.bounding_box.split(',').map(parseFloat);
    var marshaledBoundingBoxBox = {
      upperLeft: {
        lat: parsedBoundingBox[3],
        lon: parsedBoundingBox[0]
      },
      lowerRight: {
        lat: parsedBoundingBox[1],
        lon: parsedBoundingBox[2]
      }

    };
    wofDoc.setBoundingBox(marshaledBoundingBoxBox);
  }

  // a `hierarchy` is composed of potentially multiple WOF records, so iterate
  // and assign fields
  if (!_.isUndefined(hierarchy)) {
    hierarchy.forEach(function(hierarchyElement) {
      assignField(hierarchyElement, wofDoc);
    });
  }

  // add self to parent hierarchy for postalcodes only
  if (record.place_type === 'postalcode') {
    assignField(record, wofDoc);
  }

  return wofDoc;

}
function setupDocument(record, hierarchy) {
  var wofDoc = new Document( 'whosonfirst', record.place_type, record.id );

  if (record.name) {
    wofDoc.setName('default', record.name);

    // index a version of postcode which doesn't contain whitespace
    if (record.place_type === 'postalcode' && typeof record.name === 'string') {
      var sans_whitespace = record.name.replace(/\s/g, '');
      if (sans_whitespace !== record.name) {
        wofDoc.setNameAlias('default', sans_whitespace);
      }
    }

    // index name aliases for all other records (where available)
    else if (record.name_aliases.length) {
      record.name_aliases.forEach(alias => {
        wofDoc.setNameAlias('default', alias);
      });
    }
  }
  wofDoc.setCentroid({ lat: record.lat, lon: record.lon });

  // only set population if available
  if (record.population) {
    wofDoc.setPopulation(record.population);
  }

  // only set popularity if available
  if (record.popularity) {
    wofDoc.setPopularity(record.popularity);
  }

  // WOF bbox is defined as:
  // lowerLeft.lon, lowerLeft.lat, upperRight.lon, upperRight.lat
  // so convert to what ES understands
  if (!_.isUndefined(record.bounding_box)) {
    var parsedBoundingBox = record.bounding_box.split(',').map(parseFloat);
    var marshaledBoundingBoxBox = {
      upperLeft: {
        lat: parsedBoundingBox[3],
        lon: parsedBoundingBox[0]
      },
      lowerRight: {
        lat: parsedBoundingBox[1],
        lon: parsedBoundingBox[2]
      }

    };
    wofDoc.setBoundingBox(marshaledBoundingBoxBox);
  }

  // a `hierarchy` is composed of potentially multiple WOF records, so iterate
  // and assign fields
  if (!_.isUndefined(hierarchy)) {
    hierarchy.forEach(function(hierarchyElement) {
      assignField(hierarchyElement, wofDoc);
    });
  }

  // add self to parent hierarchy for postalcodes only
  if (record.place_type === 'postalcode') {
    assignField(record, wofDoc);
  }

  return wofDoc;

}
function setupDocument ( record , hierarchy ) { var wofDoc = new Document ( 'whosonfirst' , record . place_type , record . id ) ; if ( record . name ) { wofDoc . setName ( 'default' , record . name ) ; // index a version of postcode which doesn't contain whitespace if ( record . place_type === 'postalcode' && typeof record . name === 'string' ) { var sans_whitespace = record . name . replace ( / \s / g , '' ) ; if ( sans_whitespace !== record . name ) { wofDoc . setNameAlias ( 'default' , sans_whitespace ) ; } } // index name aliases for all other records (where available) else if ( record . name_aliases . length ) { record . name_aliases . forEach ( alias => { wofDoc . setNameAlias ( 'default' , alias ) ; } ) ; } } wofDoc . setCentroid ( { lat : record . lat , lon : record . lon } ) ; // only set population if available if ( record . population ) { wofDoc . setPopulation ( record . population ) ; } // only set popularity if available if ( record . popularity ) { wofDoc . setPopularity ( record . popularity ) ; } // WOF bbox is defined as: // lowerLeft.lon, lowerLeft.lat, upperRight.lon, upperRight.lat // so convert to what ES understands if ( ! _ . isUndefined ( record . bounding_box ) ) { var parsedBoundingBox = record . bounding_box . split ( ',' ) . map ( parseFloat ) ; var marshaledBoundingBoxBox = { upperLeft : { lat : parsedBoundingBox [ 3 ] , lon : parsedBoundingBox [ 0 ] } , lowerRight : { lat : parsedBoundingBox [ 1 ] , lon : parsedBoundingBox [ 2 ] } } ; wofDoc . setBoundingBox ( marshaledBoundingBoxBox ) ; } // a `hierarchy` is composed of potentially multiple WOF records, so iterate // and assign fields if ( ! _ . isUndefined ( hierarchy ) ) { hierarchy . forEach ( function ( hierarchyElement ) { assignField ( hierarchyElement , wofDoc ) ; } ) ; } // add self to parent hierarchy for postalcodes only if ( record . place_type === 'postalcode' ) { assignField ( record , wofDoc ) ; } return wofDoc ; }
method that extracts the logic for Document creation.  `hierarchy` is optional
method that extracts the logic for Document creation . hierarchy is optional