<commit_before>import is from 'is_js';

import { formatPattern } from 'react-router';

export const createBuildRoute = (ownProps) => (...args) => {
  const route = getRoute(args);
  const params = getParams(args);
  if (is.not.object(params) || is.empty(params)) {
    return normalizeUrl(`/${ownProps.location.pathname}/${route}`);
  }

  let newRoute = '';
  ownProps.routes.forEach((routePiece) => {
    if (is.not.string(routePiece.path)) {
      return;
    }

    newRoute = `${newRoute}/${routePiece.path}`;
  });

  newRoute = normalizeUrl(`/${newRoute}/${route}`);

  const finalParams = Object.assign({}, ownProps.params, params);
  return formatPattern(newRoute, finalParams);
};

function getRoute(args) {
  return is.string(args[0]) ? args[0] : '';<commit_msg>Fixed cases starting or ending with /<commit_after>import is from 'is_js';

import { formatPattern } from 'react-router';

export const createBuildRoute = (ownProps) => (...args) => {
  const route = getRoute(args);
  const params = getParams(args);
  if (/^\//.test(route)) {
    return normalizeUrl(route);
  }

  if (is.not.object(params) || is.empty(params)) {
    return normalizeUrl(`/${ownProps.location.pathname}/${route}`);
  }

  let newRoute = '';
  ownProps.routes.forEach((routePiece) => {
    if (is.not.string(routePiece.path)) {
      return;
    }

    newRoute = `${newRoute}/${routePiece.path}`;
  });

  const finalParams = Object.assign({}, ownProps.params, params);
  return normalizeUrl(formatPattern(`/${newRoute}/${route}`, finalParams));
};

function getRoute(args) {
  return is.string(args[0]) ? args[0] : '';
{'fraction_non_alphanumeric': 0.18633540372670807, 'fraction_numerical': 0.002484472049689441, 'mean_word_length': 4.130573248407643, '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': '1349785', 'n_tokens_mistral': 538, 'n_tokens_neox': 536, 'n_words': 102}