<commit_before>const defaults = require('./defaults.js');

const parseBoolean = boolean => boolean === 'true';

const parseIntervals = (intervals) => {
  if (Array.isArray(intervals)) {
    return intervals
      .filter(i => !isNaN(i))
      .map(parseFloat)
      .sort((a, b) => a - b);
  }
  const interval = parseFloat(intervals);
  return interval ? [interval] : defaults.intervals;
};

const parseUnits = (units) => {
  if (units === 'kilometers' || units === 'miles') {
    return units;
  }
  return defaults.units;
};

const parsers = {
  lng: parseFloat,
  lat: parseFloat,
  radius: parseFloat,
  cellSize: parseFloat,
  concavity: parseFloat,
  lengthThreshold: parseFloat,
  deintersect: parseBoolean,
  intervals: parseIntervals,
  units: parseUnits
};

const parseQuery = query =>
  Object.keys(parsers).reduce((acc, paramKey) => {
    if (query[paramKey]) {
      const parser = parsers[paramKey];
      acc[paramKey] = parser(query[paramKey]);
    }
    return acc;
  }, defaults);

module.exports = parseQuery;<commit_msg>Clone `defaults` object to avoid member assignment<commit_after>const defaults = require('./defaults.js');

const parseBoolean = boolean => boolean === 'true';

const parseIntervals = (intervals) => {
  if (Array.isArray(intervals)) {
    return intervals
      .filter(i => !isNaN(i))
      .map(parseFloat)
      .sort((a, b) => a - b);
  }
  const interval = parseFloat(intervals);
  return interval ? [interval] : defaults.intervals;
};

const parseUnits = (units) => {
  if (units === 'kilometers' || units === 'miles') {
    return units;
  }
  return defaults.units;
};

const parsers = {
  lng: parseFloat,
  lat: parseFloat,
  radius: parseFloat,
  cellSize: parseFloat,
  concavity: parseFloat,
  lengthThreshold: parseFloat,
  deintersect: parseBoolean,
  intervals: parseIntervals,
  units: parseUnits
};

const parseQuery = query =>
  Object.keys(parsers).reduce((acc, paramKey) => {
    if (query[paramKey]) {
      const parser = parsers[paramKey];
      acc[paramKey] = parser(query[paramKey]);
    }
    return acc;
  }, Object.assign({}, defaults));

module.exports = parseQuery;
{'fraction_non_alphanumeric': 0.14873713751169318, 'fraction_numerical': 0.0, 'mean_word_length': 3.763919821826281, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7267346', 'n_tokens_mistral': 684, 'n_tokens_neox': 687, 'n_words': 162}