<commit_before>const shapefile = require('shapefile');
const { GeoStore } = require('terraformer-geostore');
const { RTree } = require('terraformer-rtree');
const GeostoreMemory = require('terraformer-geostore-memory').Memory;

/**
 * Creates a new store for handling quering GeoJson collections.
 */
const store = new GeoStore({
  store: new GeostoreMemory(),
  index: new RTree(),
});

/**
 * Adds an id property to each feature in the featureCollection.
 *
 * Terraformer GeoStore expects an id property for each feature in the feature collection.
 * @param {object} collection
 * @return {object} The modified collection
 */
function addIdToFeatureCollection(collection) {
  let id = 0;

  collection.features.map((feature) => {
    feature.id = (id += 1).toString(); // Terraformer library throws errors if id is a number.
    return feature;
  });

  return collection;
}

/**
 * Adds a GeoJson feature collection to the Terraformer memory store.
 *
 * @param {object} collection A GeoJson feature collection.
 * @returns {undefined}
 */
function addCollectionToStore(collection) {
  store.add(collection); // if we fail to read the shapfile, shutdown the server TODO
}

/**
 * Inserts a GeoJson object into the Terraformer memory store if it exists.
 *
 * @param {object} collection A GeoJson collection read from the shapefile.
 * @return {undefined}
 */
function addShapefileCollectionToStore(collection) {
  const collectionWithId = addIdToFeatureCollection(collection);
  addCollectionToStore(collectionWithId);
}

shapefile
  .read('./world/tz_world_mp.shp')
  .then(response => addShapefileCollectionToStore(response))
  .catch(err => console.error(err));

module.exports = store;
<commit_msg>making use of es6 destructuring<commit_after>const shapefile = require('shapefile');
const { GeoStore } = require('terraformer-geostore');
const { RTree } = require('terraformer-rtree');
const { Memory } = require('terraformer-geostore-memory');

/**
 * Creates a new store for handling quering GeoJson collections.
 */
const store = new GeoStore({
  store: new Memory(),
  index: new RTree(),
});

/**
 * Adds an id property to each feature in the featureCollection.
 *
 * Terraformer GeoStore expects an id property for each feature in the feature collection.
 * @param {object} collection
 * @return {object} The modified collection
 */
function addIdToFeatureCollection(collection) {
  let id = 0;

  collection.features.map((feature) => {
    feature.id = (id += 1).toString(); // Terraformer library throws errors if id is a number.
    return feature;
  });

  return collection;
}

/**
 * Adds a GeoJson feature collection to the Terraformer memory store.
 *
 * @param {object} collection A GeoJson feature collection.
 * @returns {undefined}
 */
function addCollectionToStore(collection) {
  store.add(collection); // if we fail to read the shapfile, shutdown the server TODO
}

/**
 * Inserts a GeoJson object into the Terraformer memory store if it exists.
 *
 * @param {object} collection A GeoJson collection read from the shapefile.
 * @return {undefined}
 */
function addShapefileCollectionToStore(collection) {
  const collectionWithId = addIdToFeatureCollection(collection);
  addCollectionToStore(collectionWithId);
}

shapefile
  .read('./world/tz_world_mp.shp')
  .then(response => addShapefileCollectionToStore(response))
  .catch(err => console.error(err));

module.exports = store;

{'fraction_non_alphanumeric': 0.11228378774552918, 'fraction_numerical': 0.001465845793022574, 'mean_word_length': 4.593442622950819, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4117294', 'n_tokens_mistral': 999, 'n_tokens_neox': 954, 'n_words': 314}