<commit_before>import React from 'react';
import Router from 'react-router';
import currencies from '../data/currencies.js';
import routes from './routes.jsx';
import i18n from '../locales/i18n.js';
import assign from 'react/lib/Object.assign';
import paths from '../scripts/paths.js';

function redirectTo(pathname, query, Handler) {
  // we need to check if the requested path exists in our paths list
  // if not redirect to root which is better than showing blank page
  if(paths.indexOf(pathname) === -1) {
    Handler.replaceWith('/');
  } else {
    Handler.replaceWith(pathname, {}, query);
  }
}

Router.run(routes, Router.HistoryLocation, function (Handler, state) {
  var lang = i18n.isSupportedLanguage(i18n.currentLanguage) ? i18n.currentLanguage : i18n.defaultLang;
  var queryString = state.query;
  var pathname = queryString.pathname || state.pathname;

  var presets = "";
  var currencyCode = "usd";
  var amount = "";
  var frequency = "single";
  if (queryString) {
    presets = queryString.presets || presets;
    currencyCode = queryString.currency || currencyCode;
    amount = queryString.amount || amount;
    if (queryString.frequency === "monthly") {
      frequency = "monthly";
    }
  }

  var currency = currencies[currencyCode];
  if (!currency) {
    currency = currencies['usd'];
  }
  // We didn't get valid presets from the query string,
  // so default to the currency and frequency preset.
  presets = presets.split(",");
  if (presets.length !== 4) {
    presets = currency.presets[frequency];
  } else if(presets.length === 4) {
    if(!presets.every(isNumber)) {
      presets = currency.presets[frequency];
    }
  }
  function isNumber(item) {
    return !isNaN(item);
  }

  var values = {
    currency: currency,
    presets: presets,
    currencies: currencies,
    amount: amount,
    frequency: frequency
  };

  // checking if language code is part of the URL e.g. /en-US/thank-you
  if(i18n.urlOverrideLang(queryString.pathname).test) {
    // but is the language code supported in our app?
    if(i18n.isSupportedLanguage(i18n.urlOverrideLang().lang)) {
      var messages = i18n.intlDataFor(i18n.urlOverrideLang().lang);
      values = assign(values, messages);<commit_msg>boil down client.jsx logic<commit_after>import React from 'react';
import Router from 'react-router';
import currencies from '../data/currencies.js';
import routes from './routes.jsx';
import i18n from '../locales/i18n.js';
import assign from 'react/lib/Object.assign';
import paths from '../scripts/paths.js';

function redirectTo(pathname, query, Handler) {
  // we need to check if the requested path exists in our paths list
  // if not redirect to root which is better than showing blank page
  if(paths.indexOf(pathname) === -1) {
    Handler.replaceWith('/');
  } else {
    Handler.replaceWith(pathname, {}, query);
  }
}

Router.run(routes, Router.HistoryLocation, function (Handler, state) {
  var lang = i18n.isSupportedLanguage(i18n.currentLanguage) ? i18n.currentLanguage : i18n.defaultLang;
  var queryString = state.query;
  var pathname = queryString.pathname || state.pathname;

  var presets = "";
  var currencyCode = "usd";
  var amount = "";
  var frequency = "single";
  if (queryString) {
    presets = queryString.presets || presets;
    currencyCode = queryString.currency || currencyCode;
    amount = queryString.amount || amount;
    if (queryString.frequency === "monthly") {
      frequency = "monthly";
    }
  }

  var currency = currencies[currencyCode];
  if (!currency) {
    currency = currencies['usd'];
  }
  function isNumber(item) {
    return !isNaN(item);
  }
  // We didn't get valid presets from the query string,
  // so default to the currency and frequency preset.
  presets = presets.split(",");
  if (presets.length !== 4 || !presets.every(isNumber)) {
    presets = currency.presets[frequency];
  }

  var values = {
    currency: currency,
    presets: presets,
    currencies: currencies,
    amount: amount,
    frequency: frequency
  };

  // checking if language code is part of the URL e.g. /en-US/thank-you
  if(i18n.urlOverrideLang(queryString.pathname).test) {
    // but is the language code supported in our app?
    if(i18n.isSupportedLanguage(i18n.urlOverrideLang().lang)) {
      var messages = i18n.intlDataFor(i18n.urlOverrideLang().lang);
      values = assign(values, messages);
{'fraction_non_alphanumeric': 0.12897324491195974, 'fraction_numerical': 0.011205122341641893, 'mean_word_length': 3.5993690851735014, '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': '6161326', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1340, 'n_words': 371}