<commit_before>import qs from 'query-string';
import {createRoutes} from 'react-router';
import React from 'react';

import Util from './Util';

function findRedirect(queryString) {
  let redirectTo = false;

  Object.keys(queryString).forEach(function (key) {
    if (/redirect/.test(key)) {
      redirectTo = queryString[key];
    }
  });

  return redirectTo;
}

const RouterUtil = {

  getRedirectTo() {
    let redirectTo = false;

    // This will match url instances like this:
    // /?redirect=SOME_ADDRESS#/login
    if (global.location.search) {
      redirectTo = findRedirect(qs.parse(global.location.search));
    }

    // This will match url instances like this:
    // /#/login?redirect=SOME_ADDRESS
    if (!redirectTo && global.location.hash) {
      redirectTo = findRedirect(qs.parse(global.location.hash));
    }

    return redirectTo;
  },

  /**
   * Creates a tree of React components for an array of route configurations
   *
   * @param  {Array} routes
   * @return {Array} React tree of routes
   */
  createComponentsFromRoutes(routes) {
    return routes.map(function (route) {
      let args = [route.type, Util.omit(route, ['type', 'children'])];

      if (
          route.component &&
          route.component.willTransitionTo &&
          !route.onEnter
        ) {
        route.onEnter = route.component.willTransitionTo;
      }

      if (route.children) {
        let children = RouterUtil.createComponentsFromRoutes(route.children);
        args = args.concat(children);
      }
      return React.createElement(...args);
    });
  },

  /**
   * Builds a route array that react router can use,
   * with the correct configuration.
   *
   * @param  {Array} originalRoutes Original Route configuration
   * @return {Array} Routes ready to use by react router
   */
  buildRoutes(originalRoutes) {
    let elementRoutes = RouterUtil.createComponentsFromRoutes(originalRoutes);
    return createRoutes(elementRoutes);
  },

  /**
   * Checks if a page should hide the header navigation tabs
   * @param  {Array} routes instance of react-router
   * @return {Bool} should hide Page Navigation
   */
  shouldHideNavigation(routes) {
    return !!routes[routes.length - 1].hideHeaderNavigation;
  },

  /**
   * Builds absolute path from routes array
   * @param {Array} routes - an array of current routes react-rouer gives you
   * @returns {String} path - absolute path pattern
   */
  reconstructPathFromRoutes(routes) {<commit_msg>Fix typo<commit_after>import qs from 'query-string';
import {createRoutes} from 'react-router';
import React from 'react';

import Util from './Util';

function findRedirect(queryString) {
  let redirectTo = false;

  Object.keys(queryString).forEach(function (key) {
    if (/redirect/.test(key)) {
      redirectTo = queryString[key];
    }
  });

  return redirectTo;
}

const RouterUtil = {

  getRedirectTo() {
    let redirectTo = false;

    // This will match url instances like this:
    // /?redirect=SOME_ADDRESS#/login
    if (global.location.search) {
      redirectTo = findRedirect(qs.parse(global.location.search));
    }

    // This will match url instances like this:
    // /#/login?redirect=SOME_ADDRESS
    if (!redirectTo && global.location.hash) {
      redirectTo = findRedirect(qs.parse(global.location.hash));
    }

    return redirectTo;
  },

  /**
   * Creates a tree of React components for an array of route configurations
   *
   * @param  {Array} routes
   * @return {Array} React tree of routes
   */
  createComponentsFromRoutes(routes) {
    return routes.map(function (route) {
      let args = [route.type, Util.omit(route, ['type', 'children'])];

      if (
          route.component &&
          route.component.willTransitionTo &&
          !route.onEnter
        ) {
        route.onEnter = route.component.willTransitionTo;
      }

      if (route.children) {
        let children = RouterUtil.createComponentsFromRoutes(route.children);
        args = args.concat(children);
      }
      return React.createElement(...args);
    });
  },

  /**
   * Builds a route array that react router can use,
   * with the correct configuration.
   *
   * @param  {Array} originalRoutes Original Route configuration
   * @return {Array} Routes ready to use by react router
   */
  buildRoutes(originalRoutes) {
    let elementRoutes = RouterUtil.createComponentsFromRoutes(originalRoutes);
    return createRoutes(elementRoutes);
  },

  /**
   * Checks if a page should hide the header navigation tabs
   * @param  {Array} routes instance of react-router
   * @return {Bool} should hide Page Navigation
   */
  shouldHideNavigation(routes) {
    return !!routes[routes.length - 1].hideHeaderNavigation;
  },

  /**
   * Builds absolute path from routes array
   * @param {Array} routes - an array of current routes react-router gives you
   * @returns {String} path - absolute path pattern
   */
  reconstructPathFromRoutes(routes) {
{'fraction_non_alphanumeric': 0.11317704122877931, 'fraction_numerical': 0.0004042037186742118, 'mean_word_length': 2.9719101123595504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '329031', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1423, 'n_words': 385}